Shrinking the Guts

By Agustin May 20, 2011

Watching ol’ Spazzie run around, it is obvious to me that the key to making him better, and in fact allowing more to be done with him technically (like adding a joystick to control him with, and XBees to allow this control) requires that the current functionality be accomplished with a much smaller form factor, and a lighter weight.

With this in mind, I revisited the first motor driver I purchased. When I first got the little Motor Driver 1A Dual TB6612FNG, I had no idea what to make of the schematics, much less figure out how the hell to make it work. Well, today I figured it out! I am not sure I am wiring it up correctly, but I managed to one of my little tiny vibration motors working on it with dual direction control, standby mode, and of course some good old PWM action. This was pretty exciting because it was the first step I had in getting the Ardumoto Shield working. This is awesome, because the size of the little TB6612FNG (~2cm x ~2cm) compared to the Ardumoto Shield (~5.5cm x ~6cm) is a huge savings in size. Check it out:

 



One concern I have is that I am powering the logic for the chip and the motors both from the Arduino. I separated the two voltages that the Uno provides into the two buses on my breadboard, and I used the 5V for the logic, and the 3.3V for the motors. At least that is what I think I did, hehe… I think I am missing some general understanding of how ground works in a situation like this. I think the only reason it is working without damaging the Arduino is that the motor I attached is super duper tiny – one of those tiny pager motors (which is a lot like the Hexbug motors). Anyway, it worked, so that means it must be good to go, right? On the real – anyone who can enlighten me on whether or not this is correct (and preferably why) shall get a frosty beverage of his or her choosing. I have added a diagram of what I did (and my test code) at the end of the post for anyone intrepid enough to take a crack at it. I would be so happy to know if this is a correct way to set it up. I know a lot of people have asked about the correct way to use the motor driver over on Sparkfun and elsewhere, so once I get it locked down, maybe I will put the diagram(and code) up on the comments over there to help other noobs.

Now I need to get me a little Arduino Mini that I can use to bring the project to the next level! I have been messing around with the current build/code, so I should post something funner soon – my mini me and I have been having fun making the stock IR controlled spider run around after Spazzie…

Motor Driver 1A Dual TB6612FNG Diagram

1x 3v micro motor – data sheet (pdf)

tb6612fng_wiring_1

Motor Driver 1A Dual TB6612FNG Test Code


//Control Pins for Motor 1
int out_A_pwm = 3; //PWM Speed control
int out_A_in_1 = 9; //These are the two pins you set high and low to get various states
int out_A_in_2 = 8;
int out_stby = 12; //This pin sets the motors in standby mode (ie: they are off, and draw no power(?))
void setup(){
//Set up our pins for output
pinMode(out_A_pwm,OUTPUT);
pinMode(out_A_in_1,OUTPUT);
pinMode(out_A_in_2,OUTPUT);
pinMode(out_stby,OUTPUT);
//TODO – these next lines are redundant as the loop starts with this.
//Take the driver out of standby mode
digitalWrite(out_stby,HIGH);
//Set motor direction to fwd
digitalWrite(out_A_in_1,HIGH);
digitalWrite(out_A_in_2,LOW);
//We add speed in the loop
}void loop(){
int i = 0;

//Take the driver out of standby mode
digitalWrite(out_stby,HIGH);
//Set motor direction to FORWARD
digitalWrite(out_A_in_1,HIGH);
digitalWrite(out_A_in_2,LOW);
//Slowly ramp up to full speed (PWM from 0 -> 255)
for (i = 0; i <= 255; i++) { analogWrite(out_A_pwm,i); delay(50); } //Slowly ramp up to full speed (PWM from 255 -> 0)
for (i = 255; i >= 0; i–) {
analogWrite(out_A_pwm,i);
delay(50);
}

//Set motor direction to REVERSE
digitalWrite(out_stby,HIGH);
//Slowly ramp up to full speed (PWM from 0 -> 255)
digitalWrite(out_A_in_1,LOW);
digitalWrite(out_A_in_2,HIGH);
for (i = 0; i <= 255; i++) { analogWrite(out_A_pwm,i); delay(50); } //Slowly ramp up to full speed (PWM from 255 -> 0)
for (i = 255; i >= 0; i–) {
analogWrite(out_A_pwm,i);
delay(50);
}
//Now put the motor driver in standby mode for 3 seconds.
digitalWrite(out_stby,LOW);
delay(3000);

}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *