Notifications
Clear all

[Solved] Controlling a stepper motor using TB6612FNG

2 Posts
1 Users
0 Likes
2,737 Views
(@superdave)
Member
Joined: 3 years ago
Posts: 2
Topic starter  

I was wondering if anyone could shed some light. I have seen various articles controlling normal dc motors with the TB6612fng (the one on the dronebot Youtube channel particularly) and articles on adafruit controlling a stepper with it. What I would like to know is. I have a 1.8A stepper motor. The current limit on the TB6612fng is 1.2A would I be correct in thinking that i could instead of connecting the PWM to the positive rail in the adafruit example to give 100% duty cycle. Connect it to a PWM out from my arduino nano and reduce the duty cycle to around 50% as it is quite a powerful motor and my application does not need a lot of power.

the test code for this project is this

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 200

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 4, 5, 6, 7);


void setup()
{
Serial.begin(9600);
Serial.println("Stepper test!");
// set the speed of the motor to 30 RPMs
stepper.setSpeed(60);
}

void loop()
{
Serial.println("Forward");
stepper.step(STEPS);
Serial.println("Backward");
stepper.step(-STEPS);
}

 

If I am correct I believe it should be possible to use D9 on my Nano as a Pwm out and connect it to the PWMA and PWMB pins on the TB6612FNG. Could anyone tell me if I am correct or if there is a reason people only seem to use the pwm on dc (non stepper) motors. Also would i need to put the driver in standby while the arduino is starting to prevent an overcurrent situation? Any insight would be greatly appreciated!

 

 


   
Quote
(@superdave)
Member
Joined: 3 years ago
Posts: 2
Topic starter  

Ok well It did work if anyone is interested I attached D9 from arduino to PWMA and PWMB on TB6612FNG and it it worked as planned. I did have to reduce the duty cycle a bit but it still seems effective.

Here is the modified code

#include <Stepper.h>
// added to by SuperDave but mostly copied from Adafruit TB6612 1.2A DC/Stepper Motor Driver Breakout Board examples
// uses pwm out pin 9 to set duty cycle to level required and keep driver cool
// change this to the number of steps on your motor
#define STEPS 200

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 4, 5, 6, 7);
int pwm = 9; // the arduino PWM pin9 to attach to pwma and pwmb on the tb6612fng driver

void setup()
{
pinMode(pwm, OUTPUT); // declare pin 9 to be an output:
analogWrite(pwm, 64); // set the duty cycle of pin 9:
Serial.begin(9600);
Serial.println("Stepper test!");
// set the speed of the motor to 30 RPMs (60)
stepper.setSpeed(10);
}

void loop()
{
Serial.println("Forward");
stepper.step(STEPS);
delay(1000);
Serial.println("Backward");
stepper.step(-STEPS);
delay(1000);
}

Hope someone finds this useful!


   
ReplyQuote