1/18/2012

How to use the TB6612FNG motor driver with the Arduino for noobs

Pinout of the TB6612FNG motor driver IC
mounted on a breakout board.
It took a few hours of research and trial and error for me to figure out how to use the Toshiba TB6612FNG with my Arduino, but I finally figured it out.  Hopefully I can save someone some trouble by posting all of the information here.

This information is referring to the Toshiba TB6612FNG , sold on breakout boards as the Sparkfun Motor Driver 1A Dual TB6612FNG and the Pololu Dual DC Motor Driver 1A.  Refer to the picture at the left for the rest of this post for pinout information.  


At first I was under the impression that you just hooked up AO1 and AO2 to one motor, BO1 and BO2 to the other motor, and PWMA to one PWMA to one PWM output and PWMB to another PWM output.  It turns out, you have to make every connection on the TB6612FNG chip to get it to work properly.   I'll cover them one by one.

From the top left of the diagram, working counter-clockwise:
GND - Connect to the ground terminal on the Arduino board
VCC  - Connect to the 5V VCC on the Arduino board.
AO1 - Connect to the negative lead of motor A.
AO2 - Connect to the positive lead of motor A.
BO2 - Connect to the positive lead of motor B.
BO1 - Connect to the negative lead of motor B.
VMOT - Connect to the positive side of the power source you are using to power the motors.
GND - Connect to the negative side of the power source you are using to power the motors.
PWMA - Connect to PWM pin on the Arduino.  On the Arduino Uno, this would be either pin 3,5,6,9,10,or 11.
AIN2 - Connect to a digital pin on the Arduino.
AIN1 - Connect to a digital pin on the Arduino.
STBY - Connect to a digital pin on the Arduino.
BIN1 - Connect to a digital pin on the Arduino.
BIN2 - Connect to a digital pin on the Arduino.
PWMB - Connect to a PWM pin on the Arduino.  On the Arduino Uno, this would be either pin 3,5,6,9,10,or 11.
GND - Connect to the ground of the Arduino.

Now that you have the connections made, it is easy to use the controller to make your motors go.  Basically, you make motor A move clockwise by setting AIN1 to HIGH, AIN2 to LOW, and sending a value between 1 and 255 to PWMA.  STBY will need to be set HIGH also for any motor control to happen.

Also, your mileage may vary, but I found that my motors would not function reliably unless I used a minimum PWM value of 35.  This is probably a function of motor size, power source, robot weight, etc.

So, to go forward you would need to program:
STBY - HIGH
AIN1 - HIGH
AIN2 - LOW
PWMA - 255
STBY - HIGH
BIN1 - HIGH
BIN2 - LOW
PWMB - 255

Backwards would be the same as the above, except AIN1 and BIN1 would be LOW while AIN2 and BIN2 would be high.

So, the IN1 and IN2 pins determine direction, while the PWM pins control speed.  You should be able to use this information to figure out how to do all sorts of turns and maneuvers.

Don't forget the STBY pin must be high for the chip to work!