Chapter 1: Beginnings
Chapter 2: Further Beginnings
Chapter 3: Hello World
Chapter 4: More On GPIO
Chapter 5: Interrupts
Chapter 6: More On Interrupts
Chapter 7: Timers
Chapter 8: Adding Some Real-World Hardware
Chapter 9: More Timers and Displays
Chapter 10: Buttons and Bouncing
Chapter 11: Button Matrix & Auto Repeating
Chapter 12: Driving WS2812 RGB LEDs
Would you like to be notified by email when Lonnie Honeycutt publishes a new blog?
Beginner robotics is a series of article chronicling my first autonomous robot build, Clusterbot. This build is meant to be affordable, relatively easy and instructive. The total cost of the build is around $50.
Meet Clusterbot, my first robot build. I like to let my projects name themselves, and by the time this robot was complete, he was such a cluster&*%# of jumperwires, zip-ties, velcro and erector-set parts that it was clear what his name should be. For all of Clusterbots deficiencies, it ended up being a terrific learning experience in mechanical design and motor control principles. This series of articles is also dedicated as a memorial to Clusterbot, who has since been dismantled and returned to various parts bins.
Today's post is going to focus on connecting and writing code for the Toshiba TB6612FNG motor driver.
Why do we need a motor driver? Can't we just connect the motors directly to the Arduino, just like an LED or any other component? Unfortunately, no. The output ports of a microcontroller are simply unable to handle the amount of current most motors will draw. The microcontroller used for this project was an Arduino Nano clone. The max current per pin on the Nano is 40 mA. The small toy motor used in Clusterbot can easily exceed this, pulling 500mA or more of current.
The motors we are using for Clusterbot are the Mabuchi FA-130RA-18100 (see datasheet here). These are small and cheap toy motors. These little motors can pull anywhere between .1A and 2A (at stall). The current draw for my application is likely to be no more than .5A, but this is a rough guess.
Clusterbot won't cause the motors to reach their stall current, but it should be noted that the stall current rating of the motors is higher than max current rating for our motor controller. If stall current is a concern in your project, you will need to address it by installing some type of over-current protection, whether you use a fuse of some sort or a current sense feedback loop to the microcontroller. This topic is a little bit outside of the scope of this article, but I think it is worth mentioning.
I chose the Toshiba TB6612FNG as the motor controller. Why? Mostly because it was cheap and easy to implement on a breadboard. Several companies sell The TB6612FNG on breakout boards, I went with the Pololu TB6612FNG Motor Driver Carrier. Only $4.95 and easy to use with a breadboard once you solder the included header pins to the carrier board.
How do we control this thing?
First of all, nothing at all will happen if the STBY pin is not HIGH. Do this however you like, either in software by using another digital pin, or set it high permanently by tieing it directly to VCC.
If you want motor A to turn clockwise, set AIN1 to HIGH, AIN2 to LOW, PWMA to >0
If you want motor A to turn counter-clockwise, set AIN1 to LOW, AIN2 to HIGH, PWMA to >0
If you don't want to use PWM speed control of the motors, you can simply tie the PWMA and PWMB pins to VCC. In the case of an Arduino, this would be the equivalent of AnalogWrite(5,255);. Also concerning the PWM values - you will need to determine the minimum PWM duty cycle for the lowest speed you can run your motors at. Set a PWM value too low, and you can place the motor in a stall condition that will draw too much current. Low PWM values can also result in jerky operation.
In my particular case, a PWM value of 35 was necessary for the lowest speed smooth operation of my motors. This will be a function of your motor power source, motor size and the weight of your robot.
Now that you can control the direction and rate of spin of each motor, you can easily control your robot. In the case of Clusterbot, spinning motor A and B in the same direction at the same rate of speed will result in relatively straight travel in that direction. Spin the motors in opposite directions and you get a very quick zero-radius turn. You can experiment with different values for different types of sloping turns.
Due to a combination of poor chassis design and cheap toy motors, the output speed on each motor is a little different. You can compensate by altering the PWM duty cycle for one of the motors. For instance, you may find that you need to set motor A to 255 and motor B to 249 for straight line travel. A little experimentation may be necessary to calibrate.
There are no comments yet!
Add a Comment