raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 11:42 am

Hello,

Raspberry Pi 2 (raspbian stretch)
Adafruit TB6612
Stepper Motor 17hs4223
Raspberry Pi TB6612
Pin 2 Vcc
Pin 6 GND
Pin 4 PwmA
Pin 11 AIN1
Pin 15 AIN2
Pin 13 STBY
Pin 16 BIN1
Pin 18 BIN2
Pin 4 PwmB

Vmotor to 12V DC
VM floating

MotorA , red and green wires
MotorB, yellow and blue wires
I've probed with several codes but not works.

For example with pigpio:

Code: Select all

import pigpio
from PigpioStepperMotor import StepperMotor

pi = pigpio.pi()
motor = StepperMotor(pi, 11, 15, 16, 18)
for i in range(2048):
  motor.doСlockwiseStep()

But nothing happens.

Best regards

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 12:45 pm

I'm not 100% sure but. I think you connect the TB6612 to the 5V rail power supply of you pi. This means that when you set you pi outputs to high. The voltage at that pin is around the 3.3V. But, the TB6612 will see this a high input voltage, Vcc*0.7 ==> so 5*0.7 = 3.5V. And thats lower than the pi can deliver.
So, the solution is to set the vcc (digital side of the TB6612) pin to 3.3V .

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 1:10 pm

Thank you,

Also I have pwmA y pwmB connected to 5V, should I connect it to pin 17?

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 1:13 pm

Yes, that is correct.

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 1:23 pm

I have changed all to 3V3, pin 1 to PwmA and PwmB and Pin 17 to Vcc (digital side of the TB6612) but not works. Also I have probed with this code but not works --> RPistepper


Only this code move 1 step (i think), It makes a noise like a blow, when the script ends too:

Code: Select all

#!/usr/bin/env python

# Import required modules
import time
import RPi.GPIO as GPIO

# Declare the GPIO settings
GPIO.setmode(GPIO.BOARD)

# set up GPIO pins
GPIO.setup(12, GPIO.OUT) # Connected to PWMA
GPIO.setup(15, GPIO.OUT) # Connected to AIN2
GPIO.setup(11, GPIO.OUT) # Connected to AIN1
GPIO.setup(13, GPIO.OUT) # Connected to STBY
GPIO.setup(18, GPIO.OUT) # Connected to BIN1
GPIO.setup(16, GPIO.OUT) # Connected to BIN2
GPIO.setup(32, GPIO.OUT) # Connected to PWMB

# Drive the motor clockwise
# Motor A:
GPIO.output(11, GPIO.HIGH) # Set AIN1
GPIO.output(15, GPIO.LOW) # Set AIN2
# Motor B:
GPIO.output(16, GPIO.HIGH) # Set BIN1
GPIO.output(18, GPIO.LOW) # Set BIN2

# Set the motor speed
# Motor A:
GPIO.output(12, GPIO.HIGH) # Set PWMA
# Motor B:
GPIO.output(32, GPIO.HIGH) # Set PWMB

# Disable STBY (standby)
GPIO.output(13, GPIO.HIGH)

# Wait 5 seconds
time.sleep(5)

# Drive the motor counterclockwise
# Motor A:
GPIO.output(11, GPIO.LOW) # Set AIN1
GPIO.output(15, GPIO.HIGH) # Set AIN2
# Motor B:
GPIO.output(16, GPIO.LOW) # Set BIN1
GPIO.output(18, GPIO.HIGH) # Set BIN2

# Set the motor speed
# Motor A:
GPIO.output(12, GPIO.HIGH) # Set PWMA
# Motor B:
GPIO.output(32, GPIO.HIGH) # Set PWMB

# Disable STBY (standby)
GPIO.output(13, GPIO.HIGH)

# Wait 5 seconds
time.sleep(5)

# Reset all the GPIO pins by setting them to LOW
GPIO.output(11, GPIO.LOW) # Set AIN1
GPIO.output(15, GPIO.LOW) # Set AIN2
GPIO.output(12, GPIO.LOW) # Set PWMA
GPIO.output(13, GPIO.LOW) # Set STBY
GPIO.output(16, GPIO.LOW) # Set BIN1
GPIO.output(18, GPIO.LOW) # Set BIN2
GPIO.output(32, GPIO.LOW) # Set PWMB
Last edited by raspdroid on Sun Aug 12, 2018 1:43 pm, edited 1 time in total.

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 1:28 pm

Ehm, okay.
It's it maybe possible to post a picture of your setup?
And did you look at the manual?

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 2:01 pm

Yes, I have read the manual.

I have built a solder paste dispenser with a step motor and I wanted to try it with my raspberry pi. It's for a pick & place machine that I'm building.
20180812_145456_0012.jpg
20180812_145456_0012.jpg (249.6 KiB) Viewed 1804 times

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 5:00 pm

When you don't turn the motor by the software. Can you turn the motor by hand easily. Because when the driver is active and the power is on, you shouldn't be able to turn the motor by hand.
Is the yellow motor wire currently connected, because it looks a little bit strange on the picture.
BTW: did you connect both ground to each other. From your motor power supply and pi

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 5:42 pm

Yes, yellow wire is solder.

The ground of power supply is connected to pin 39 of pi.

I can turn the motor by hand when power is on and driver is active.

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 5:49 pm

Ehm, normally when I worked with a stepper motor, you can't turn it by hand when the driver is active.
So, it's looks like you motor driver is not turning it on. Do you apply a high (3.3V) to the STBY pin?

datasheet, look at page 4 for the correct driving signals

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 6:16 pm

Now it works with rpiStepper but I can stop the engine with my hand when it is spinning. It has very little strength. Will it be stuck?

I have connected stby pin to the pin 13 of rpi. I'll try connecting stby to 3.3V

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 6:52 pm

Okey, thats good to hear that its kind of working.
It could be possible that you program doesn't provide the correct signals to the motor driver. Are the signals similar to the one in the datasheet?
And is you power supply strong enough for the motor.

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 8:09 pm

This is the power supply, 5A 12V

I'm going to try another code.

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 8:15 pm

With pigpiod:

pip3 install pigpio

sudo pigpiod

python3 motor.py


Code: Select all

import pigpio
from PigpioStepperMotor import StepperMotor

pi = pigpio.pi()
motor = StepperMotor(pi, 17, 22, 23, 24)
for i in range(2048):
  motor.doСlockwiseStep()

When I execute this code the motor vibrates and heats up.

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 8:19 pm

At least now I can not move the motor shaft with my hand. :)

It's very hard.

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 8:57 pm

Nice, we are on the right track. I think your hardware is okay know. I think you control signals maybe wrong, at least the way they turn on and off. This is because you motor vibrates. Its normal that the motor will get hot. But not so hot that you can't touch it.

So, did you connect the control lines in this way (i assume that the arduino library has the same connections as the raspberry library), so I show the arduino one:
  • AIN2 to Digital 4
  • AIN1 to Digital 5
  • BIN1 to Digital 6
  • BIN2 to Digital 7
And "control"with this code:

Code: Select all

stepper(STEPS, 4, 5, 6, 7)
So, now my question
Did you connect you Pi in a similar way, take a close look to the connection with the driver ic. When I look at you connection at the first post, this is not the case.

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 10:09 pm

Vcmotor --> 12V 5A power supply

VM --> floating

Vcc --> 3V3 Pin 17

GND --> GND Pin 06

PwmA --> 3V3 Pin 01

AIN2 --> Pin 15 - BCM 22

AIN1 --> Pin 11 - BCM 17

STBY --> Pin 13 - BCM 27

BIN1 --> Pin 16 - BCM 23

BIN2 --> Pin 18 - BCM 24

PwmB --> Pin 32 - BCM

MotorA --> Red (A+) and Green (A-) wires

MotorB --> Yellow (B+) and Blue (B-) wires

GND of Power supply --> Pin 39 (gnd) Raspberry Pi

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 10:28 pm

For me to work with the pigpio code I have to connect PWMA and PWMB to 3V3 or 5V, otherwise it does not vibrate.

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 10:31 pm

I'm on my phone now, so it's side harder now. However;
You had this:
StepperMotor(pi, 17, 22, 23, 24)
Could you try this:
StepperMotor(pi, 22, 17, 23, 24)

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Sun Aug 12, 2018 10:35 pm

That's good. Because when you apply 0v to the PWM function. The controller applied a duty cycle of 0% to the motor. So, it turn the motor in fact off. And when you apply the 3.3v. It turn the motor for the fully 100% on.

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Mon Aug 13, 2018 7:20 am

This code works:

Code: Select all

import pigpio, time
from PigpioStepperMotor import StepperMotor

pi = pigpio.pi()
motor = StepperMotor(pi, 17, 23, 22, 24)
pwma = pigpio.pi()
pwma.write(18,1)
pwmb = pigpio.pi()
pwmb.write(12,1)
stby = pigpio.pi()
stby.write(27,0)
for i in range(4500):
  stby.write(27,1)
  motor.doСlockwiseStep()
  
The engine is just right, I should buy one a little more powerful than this, but it works.

Then upload a video working

Thanks very much and regards

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Mon Aug 13, 2018 9:40 am

Good to hear it is working.

I think you have done this, but you did connect the 12v power supply ground directly to the motor driver circuit? And if you connect the ground from the pi, to the ground pin there. They are connected onto the pcb.

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Mon Aug 13, 2018 3:33 pm

Yes, I have disconnect the wire between the RPi and the TB6612, I think that the driver does it internally (or should) I'll try it later

Brandon92
Posts: 704
Joined: Wed Jul 25, 2018 9:29 pm
Location: Netherlands

Re: Controlling stepper motor with Adafruit TB6612

Mon Aug 13, 2018 4:05 pm

raspdroid wrote:
Mon Aug 13, 2018 3:33 pm
Yes, I have disconnect the wire between the RPi and the TB6612, I think that the driver does it internally (or should) I'll try it later
Okay. But you need this connection "GND --> GND Pin 06". However you have this connection. Otherwise it doesn't work.

And you connect the 12v next to the Vmotor. I believe that one is also the ground.

raspdroid
Posts: 1573
Joined: Thu Nov 06, 2014 9:15 am
Location: Gran Canaria :: España

Re: Controlling stepper motor with Adafruit TB6612

Mon Aug 13, 2018 4:08 pm

Sorry, I was referring to a connection I had between pin 39 and the gnd of the power supply, I was duplicating it, with Pin 06 it's enough.

Return to “Automation, sensing and robotics”