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

Steve French
  • 209
  • 1
  • 3
  • 14

5 Answers5

6

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!!

hildred
  • 916
  • 1
  • 6
  • 21
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

John La Rooy
  • 12,005
  • 9
  • 48
  • 77
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)?

SF.
  • 920
  • 1
  • 8
  • 21
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]
PiBorg
  • 1,537
  • 10
  • 11
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.

rob
  • 2,813
  • 4
  • 22
  • 31