Adafruit Motor Shield V2 for Arduino Created by lady ada Last updated on 2018-01-21 01:32:38 PM UTC
Guide Contents Guide Contents Overview FAQ 2 4 6 How many motors can I use with this shield? Can I connect more motors? What if I also need some more servos? What Arduinos is this shield compatible with? I get the following error trying to run the example code: "error: Adafruit_MotorShield.h: No such file or directory...." How do I install the library? HELP! My motor doesnt work! - HELP! My motor doesnt work!...
Include the required libraries Create the Adafruit_MotorShield object Create the DC motor object Connect to the Controller Set default speed Run the motor Using Stepper Motors 30 30 31 31 31 31 32 Include the required libraries Create the Adafruit_MotorShield object Create the stepper motor object Set default speed Run the motor Library Reference class Adafruit_MotorShield; Adafruit_MotorShield(uint8_t addr = 0x60); void begin(uint16_t freq = 1600); Adafruit_DCMotor *getMotor(uint8_t n); Adafruit_Stepp
Overview The original Adafruit Motorshield kit is one of our most beloved kits, which is why we decided to make something even better. We have upgraded the shield kit to make the bestest, easiest way to drive DC and Stepper motors. This shield will make quick work of your next robotics project! We kept the ability to drive up to 4 DC motors or 2 stepper motors, but added many improvements: Instead of a L293D darlington driver, we now have the TB6612 MOSFET drivers with 1.
4 H-Bridges: TB6612 chipset provides 1.2A per bridge (3A for brief 20ms peaks) with thermal shutdown protection, internal kickback protection diodes. Can run motors on 4.5VDC to 13.5VDC. Up to 4 bi-directional DC motors with individual 8-bit speed selection (so, about 0.5% resolution) Up to 2 stepper motors (unipolar or bipolar) with single coil, double coil, interleaved or micro-stepping.
FAQ How many motors can I use with this shield? You can use 2 DC hobby servos that run on 5V and up to 4 DC motors or 2 stepper motors (or 1 stepper and up to 2 DC motors) that run on 5-12VDC Can I connect more motors? Yes, by stacking shields! Every shield you stack on will add 4 DC motors or 2 stepper motors (or 1 more stepper and 2 more DC motors). You will not gain more servo connections as the servo contacts go to pin #9 and #10 on the Arduino.
What pins are/are not used on the motor shield? GND and either 5v (default) or 3.3v are required to power the logic on-board. (5v or 3v operation is selectable via jumper) The shield uses the SDA and SCL i2c pins to control DC and stepper motors. On the Arduino UNO these are also known as A4 and A5. On the Mega these are also known as Digital 20 and 21. On the Leonardo these are also known as digital 2 and 3.
But my motor already has a capacitor on it and it still doesn't work. These motors generate a lot of brush noise and usually need the full 3-capacitor treatment for adequate suppression. Why don't you just design capacitors into the shield? They would not be effective there.
My shield doesn't work with my LED backpack. Some backpacks have a default address of 0x70. This is the "all call" address of the controller chip on the motor shield. If you re-address your backpack, it will work with the shield. © Adafruit Industries https://learn.adafruit.
Install Headers & Terminals Installing Standard Headers The shield comes with 0.1" standard header. Standard header does not permit stacking but it is mechanically stronger and they're much less expensive too! If you want to stack a shield on top, do not perform this step as it is not possible to uninstall the headers once soldered in! Skip down to the bottom for the stacking tutorial Break apart the 0.
Place the assembled shield on top of the header-ed Arduino so that all of the short parts of the header are sticking through the outer set of pads Solder each one of the pins into the shield to make a secure connection Next, you will attach the terminal blocks, power jumper and servo connections © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
That's it! Now you can install the terminal blocks and jumper... Installing Terminal Blocks and more After you have installed either normal or stacking headers, you must install the terminal blocks. Next we will install the terminal blocks. These are how we will connect power and motors to the shield. They're much easier to use than soldering direct, just use a small screwdriver to release/attach wires! First, though, we must solder them in.
Solder in the two pins of the external power terminalblock © Adafruit Industries https://learn.adafruit.
Solder in both motor blocks, 5 pads each © Adafruit Industries https://learn.adafruit.
That's it for the terminal blocks. Next up, servo connections. OK next up take the 2x3 pin header and place it with the short legs down into the top corner where it says SERVO 1 and SERVO 2 You might have to sort of angle the part a little to get it to fit into both sets of 3-pin holes. we did this so it wont fall out easily when you turn it over! © Adafruit Industries https://learn.adafruit.
Then flip the board over and solder the 6 pins © Adafruit Industries https://learn.adafruit.
Finally, break off a 2-pin piece of header and place it next to the POWER terminal block, short legs down, tape it in place if necessary and solder it in. Installing with Stacking Headers You will need to purchase Arduino stacking headers for this step, the shield does not come with them. (http://adafru.it/85) © Adafruit Industries https://learn.adafruit.
Start by sliding the 10 pin, 2 x 8 pin and 6-pin stacking headers into the outer rows of the shield from the top. Then flip the board over so its resting on the four headers. Pull on the legs if necessary to straighten them out. Tack one pin of each header, to get them set in place before more soldering. If the headers go crooked you can re-heat the one pin while re-positioning to straighten them up © Adafruit Industries https://learn.adafruit.
Once you've tacked and straightened all the headers, go back and solder the remaining pins for each header. © Adafruit Industries https://learn.adafruit.
© Adafruit Industries https://learn.adafruit.
Install Software Install Adafruit Motor Shield V2 library To use the shield on an Arduino, you'll need to install the Adafruit Motorshield v2 library. This library is not compatible with the older AF_Motor library used for v1 shields. However, if you have code for the older shield, adapting the code to use the new shield isn't difficult.
DC Motor The library comes with a few examples to get you started up fast. We suggest getting started with the DC motor example. You can use any DC motor that can be powered by 6V-12VDC First, restart the IDE to make sure the new library is loaded. Plug the shield into the Arduino and connect a DC motor to motor port 1 - it does not matter which wire goes into which terminal block as motors are bi-directional.
Once you have verified the motor is connected properly and you have the power LED lit up brightly, we can upload our code. In the IDE, load File->Examples->Adafruit_MotorShield->DCMotorTest You should see and hear the DC motor turn on and move back and forth, attaching a slip of paper or tape as a 'flag' can help you visualize the movement if you have trouble seeing the movement Stepper Motor Test You can also test a stepper motor connection with the shield.
You must also supply 5-12VDC to power the motor. There are two ways to do this 1. You can power the Arduino via the DC Barrel Jack and insert the VIN Jumper shown as the tall black handle right next to the green Power LED below 2. You can power the Arduino via the DC Barrel jack or USB port.
Once you have verified the motor is connected properly and you have the power LED lit up brightly, we can upload our code. In the IDE, load File->Examples->Adafruit_MotorShield->StepperTest You should see and hear the stepper motor turn on and move back and forth, attaching a slip of paper or tape as a 'flag' can help you visualize the movement if you have trouble seeing the movement. There are four ways to move a stepper, with varying speed, torque and smoothness tradeoffs.
Powering Motors Motors need a lot of energy, especially cheap motors since they're less efficient. Voltage requirements: The first important thing to figure out what voltage the motor is going to use. If you're lucky your motor came with some sort of specifications. Some small hobby motors are only intended to run at 1.5V, but its just as common to have 6-12V motors. The motor controllers on this shield are designed to run from 5V to 12V. MOST 1.
If you would like to have a single DC power supply for the Arduino and motors Say a wall adapter or a single battery pack with 6-12VDC output, simply plug it into the DC jack on the Arduino or the 2-pin power terminal block on the shield. Place the power jumper on the motor shield. Note that you may have problems with Arduino resets if the battery supply is not able to provide constant power, so it is not a suggested way of powering your motor project.
Using RC Servos Hobby servos are the easiest way to get going with motor control. They have a 3-pin 0.1" female header connection with +5V, ground and signal inputs. The motor shield simply brings out the PWM output lines from Arduino pins 9 and 10 to two 3-pin headers so that its easy to plug in and go. They can take a lot of power so a 9V battery wont last more than a few minutes! The nice thing about using the onboard PWM is that its very precise and goes about its business in the background.
Using DC Motors DC motors are used for all sort of robotic projects. The motor shield can drive up to 4 DC motors bi-directionally. That means they can be driven forwards and backwards. The speed can also be varied at 0.5% increments using the high-quality built in PWM. This means the speed is very smooth and won't vary! Note that the H-bridge chip is not meant for driving continuous loads of 1.2A, so this is for small motors.
Create the DC motor object Request the DC motor from the Adafruit_MotorShield: Adafruit_DCMotor *myMotor = AFMS.getMotor(1); with getMotor(port#). Port# is which port it is connected to. If you're using M1 its 1, M2 use 2, M3 use 3 and M4 use 4 Connect to the Controller In your setup() function, call begin() on the Adafruit_MotorShield object: AFMS.begin(); Set default speed Set the speed of the motor using setSpeed(speed) where the speed ranges from 0 (stopped) to 255 (full speed).
Using Stepper Motors Stepper motors are great for (semi-)precise control, perfect for many robot and CNC projects. This motor shield supports up to 2 stepper motors. The library works identically for bi-polar and uni-polar motors For unipolar motors: to connect up the stepper, first figure out which pins connected to which coil, and which pins are the center taps. If its a 5-wire motor then there will be 1 that is the center tap for both coils.
Create the stepper motor object Request the Stepper motor from the Adafruit_MotorShield: Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2); ...with getStepper(steps, stepper#) . Steps indicates how many steps per revolution the motor has. A 7.5 degree/step motor has 360/7.5 = 48 steps. Stepper# is which port it is connected to. If you're using M1 and M2, its port 1.
Library Reference class Adafruit_MotorShield; The Adafruit_MotorShield class represents a motor shield and must be instantiated before any DCMotors or StepperMotors can be used. You will need to declare one Adafruit_MotorShield for each shield in your system. © Adafruit Industries https://learn.adafruit.
Adafruit_MotorShield(uint8_t addr = 0x60); The constructor takes one optional parameter to specify the i2c address of the shield. The default address of the constructor (0x60) matches the default address of the boards as shipped. If you have more than one shield in your system, each shield must have a unique address. void begin(uint16_t freq = 1600); begin() must be called in setup() to initialize the shield.
class Adafruit_DCMotor The Adafruit_DCMotor class represents a DC motor attached to the shield. You must declare an Adafruit_DCMotor for each motor in your system. Adafruit_DCMotor(void); The constructor takes no arguments. The motor object is typically initialized by assigning a motor object retrieved from the shield class as below: // Create the motor shield object with the default I2C address Adafruit_MotorShield AFMS = Adafruit_MotorShield(); // Select which 'port' M1, M2, M3 or M4.
class Adafruit_StepperMotor The Adafruit_StepperMotor class represents a stepper motor attached to the shield. You must declare an Adafruit_StepperMotor for each stepper motor in your system. Adafruit_StepperMotor(void); The constructor takes no arguments.
uint8_t onestep(uint8_t dir, uint8_t style); The oneStep() function is a low-level internal function called by step(). But it can be useful to call on its own to implement more advanced functions such as acceleration or coordinating simultaneous movement of multiple stepper motors. The direction and style parameters are the same as for step(), but onestep() steps exactly once. Note: Calling step() with a step count of 1 is not the same as calling onestep().
Arduino Library Docs Arduino Library Docs (https://adafru.it/AvQ) © Adafruit Industries https://learn.adafruit.
Stacking Shields One of the cool things about this shield design is that it is possible to stack shields. Every shield you stack can control another 2 steppers or 4 DC motors (or a mix of the two) You can stack up to 32 shields for a total of 64 steppers or 128 DC motors! Most people will probably just stack two or maybe three but hey, you never know.
Board 0: Address = 0x60 Offset = binary 0000 (no jumpers required) Board 1: Address = 0x61 Offset = binary 0001 (bridge A0 as in the photo above) Board 2: Address = 0x62 Offset = binary 0010 (bridge A1, to the left of A0) Board 3: Address = 0x63 Offset = binary 0011 (bridge A0 & A1, two rightmost jumpers) Board 4: Address = 0x64 Offset = binary 0100 (bridge A2, middle jumper) etc. Note that address 0x70 is the "all call" address for the controller chip on the shield.
// On the top shield, connect two steppers, each with 200 steps Adafruit_StepperMotor *myStepper2 = AFMStop.getStepper(200, 1); Adafruit_StepperMotor *myStepper3 = AFMStop.getStepper(200, 2); // On the bottom shield connect a stepper to port M3/M4 with 200 steps Adafruit_StepperMotor *myStepper1 = AFMSbot.getStepper(200, 2); // And a DC Motor to port M1 Adafruit_DCMotor *myMotor1 = AFMSbot.
Resources Motor ideas and tutorials Wikipedia has tons of information on steppers Jones on stepper motor types Jason on reverse engineering the stepper wire pinouts Schematic, click to embiggen © Adafruit Industries Last Updated: 2018-01-21 01:32:37 PM UTC Page 43 of 43