10

I recently bought one of these stepper motor and driver boards - and I cannot find any documentation how to connect it to the Raspberry Pi - I'm attempting to use the AdaFruit tutorial and while I've gotten all of the connections made to the proper gpio pins connected (the leds on the driver board light up properly, the motor does nothing).

Does anyone know where I might look for more information on how to connect the raspberry pi to a stepper motor?

Update: Nov 15th 2013 My Program code is this

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

#enable_pin = 18
coil_A_1_pin = 4
coil_A_2_pin = 17
coil_B_1_pin = 23
coil_B_2_pin = 24

#GPIO.setup(enable_pin, GPIO.OUT)
GPIO.setup(coil_A_1_pin, GPIO.OUT)
GPIO.setup(coil_A_2_pin, GPIO.OUT)
GPIO.setup(coil_B_1_pin, GPIO.OUT)
GPIO.setup(coil_B_2_pin, GPIO.OUT)

#GPIO.output(enable_pin, 1)

def forward(delay, steps):  
  for i in range(0, steps):
    setStep(1, 0, 1, 0)
    setStep(0, 1, 1, 0)
    setStep(0, 1, 0, 1)
    setStep(1, 0, 0, 1)

def backwards(delay, steps):  
  for i in range(0, steps):
    setStep(1, 0, 0, 1)
    setStep(0, 1, 0, 1)
    setStep(0, 1, 1, 0)
    setStep(1, 0, 1, 0)


def setStep(w1, w2, w3, w4):
  GPIO.output(coil_A_1_pin, w1)
  GPIO.output(coil_A_2_pin, w2)
  GPIO.output(coil_B_1_pin, w3)
  GPIO.output(coil_B_2_pin, w4)

while True:
  delay = raw_input("Delay between steps (milliseconds)?")
  steps = raw_input("How many steps forward? ")
  forward(int(delay) / 1000.0, int(steps))
  steps = raw_input("How many steps backwards? ")
  backwards(int(delay) / 1000.0, int(steps))

My breadboard looks like this enter image description here

My driver board looks like this enter image description here

I have

IN1 => GPIO 4

IN2 => GPIO 17

IN3 => GPIO 23

IN4 => GPIO 24

  • Are the LEDs are lighting up in the right sequence, with the 0.5 sec delay? – John La Rooy Nov 18 '13 at 1:52
  • Wish I could vote multiple times. – Loko Nov 19 '13 at 15:16
  • They are lighting up in the right sequence with the delay. – Steve French Nov 20 '13 at 20:20
6
+50

You need 3.3 volt to 5 volt bus drivers. The motor kit you bought was for Arduino which uses 5 volt gpio, the rpi uses 3.3 volts, just enough to trip the leds, but not work. you could also get a motor controller that accepts 3.3 volt control lines.

Remember always check your volt ratings!!

  • [Smacks head] I did not think of that - is there any way to get the motor controller to work that you can think of - I realize I'm asking for something miraculous here, or am I just out of luck? – Steve French Nov 21 '13 at 19:13
  • @SteveFrench that is why they make dual voltage bus drivers which buffer between voltages, I bought some on ebay months ago, but Can't remember the part no. they are common and readily available – hildred Nov 21 '13 at 19:17
  • But the red in the photo is connected to the 5V pin, not the 3.3. Shouldn't that be okay?? I haven't used it myself, but I think there are some caveats.. – goldilocks Nov 21 '13 at 19:40
  • 1
    @goldilocks it depends on the controller chip, but probably not. I didn't look up the datasheet for the controller chip, but most dual voltage chips use 3.3v io when vcc is connected to 3.3v. but before trying that you have to make shure it is a dual voltage chip, most are single voltage. there are also wide voltage chips, but the bottom line is check the data sheet for your chip. – hildred Nov 21 '13 at 19:50
0

The adafruit article says

Although the code below mentions pin 18 of the GPIO connector being used as an Enable pin, this is only required when using the L293D.

If the LEDs are lighting, and you've double checked that you have 5V on the red wire, it's time to suspect the motor is faulty.

With the motor disconnected, use a multimeter to check the resistance between each wire and the red wire. They should all be about the same

  • I have commented out the enable_pin and have used a different motor, all to no avail. I am trying the mutimeter approach today - thank you for your help – Steve French Nov 13 '13 at 17:35
  • I checked the resistence - no difference in resistence - very perplexing. – Steve French Nov 15 '13 at 20:44
  • What would be a good way of testing 5v on the red wire? I've tried just putting the multimeter on there directly, but the pulse doesn't seem to last long enough for anything to register. – Steve French Nov 16 '13 at 22:03
0

First, what power supply are you using? In the config I see, the same Vcc is used to drive the RPi, the motor and the board (jumper shorted). I'm surprised that doesn't reset the Raspberry (drawing too much from +5V tends to do that) but I really don't know the characteristics of the motor - so, maybe?

Can you get the stepper to move (minimally, single steps) by connecting +5V from the power supply to Red from the motor, and GND to remaining 4 terminals in sequence?

If the LEDs light up, and the motor doesn't move, it really seems like it's not getting enough current. If this is the case, either get a stronger power supply, or (recommended) add a separate PSU to power the motor - remove the jumper and in its place attach Vcc to outermost pin, and connect GND to the same line on the breadboard as the "-" wire (common ground, don't disconnect the one that's already there.)

(there is a small possibility that there's something wrong with the board too. Could you provide a good photo of the reverse side of the board? (solder side)?

  • I can get the stepper motor to move directly - I'm trying the other method now. – Steve French Nov 20 '13 at 20:19
  • Just tried the vcc method - same result. Maybe these boards just can't be used with the pi for some reason. – Steve French Nov 20 '13 at 20:52
  • If the LEDs light right, then the board works right. Either the motor is faulty or it doesn't get enough current (or, rather unlikely, wiring/connectors on the motor side are damaged.) Have you tried if the motor moves without using the board, just connecting power directly to its contacts? – SF. Nov 21 '13 at 7:43
0

Looking at the AdaFruit code and yours, it would seem the step sequence is wrong, in particular it seems you need to drive two pins at the same time not just one.

I think the following sequence should work based on the AdaFruit code:

# Define simple sequence
StepCount1 = 4
Seq1 = []
Seq1 = range(0, StepCount1)
Seq1[0] = [1,0,1,0]
Seq1[1] = [0,1,1,0]
Seq1[2] = [0,1,0,1]
Seq1[3] = [1,0,0,1]
  • I must have copied that in error the actual sequence of the program is the sequence you have. – Steve French Nov 21 '13 at 19:02
0

I have been following the guide here http://www.raspberrypi-spy.co.uk/2012/07/stepper-motor-control-in-python/, nice grouping of the GPIO pins, but ended up at stackexchange because the motor was doing nothing. Except it was. When picked up I could feel a small "heartbeat" each time the LED changed, I changed the WaitTime parameter from 0.5 to smaller and smaller values until 0.001 allowed a full rotation in 8.5 seconds.

But I did change the sequence type to 2(manufacturers) as type 1 seemed to occasionally stop the motor even with a working "heartbeat".

I altered the code so I could test the number of steps that a full rotation took and built a command line switch to rotate either clockwise or counter clockwise.

With the WaitTime at 0.001 running a test CW and then using the same number of steps CCW produced a small amount of error i.e. it did not line up where it had started.

Setting the WaitTime to 0.01 allowed me to show repeated execution of 4100 steps either CW or CCW always ended up at the same point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.