Wednesday, October 12, 2016

106: EasyDriver + Linear Stepper Motor
-- Finally --

I've long lost track of how many failed attempts I've made to get this to work. Here's my successful EasyDriver wiring:
The messy setup

Here's some Python code that works for me.
Note: I had to install PWM -- see
http://raspi.tv/2013/rpi-gpio-0-5-2a-now-has-software-pwm-how-to-use-it

import RPi.GPIO as GPIO
import time, sys
GPIO.setmode(GPIO.BCM)
STEP = 22
DIR = 17
GPIO.setup(STEP, GPIO.OUT)
GPIO.setup(DIR, GPIO.OUT)

sp = GPIO.PWM(STEP, 800)# 800 seems faster than 500 ???

# usage: sudo python this_file.py direction steps
dir = sys.argv[1]        # f or b -- forward or back
steps = int(sys.argv[2]) # max on my linear screw about 700

def spin(dir, steps):
  GPIO.output(DIR, dir)
  while steps > 0:
    sp.start(1)
    time.sleep(0.005) # smaller delay looses steps ???
    steps -= 1
  sp.stop()
  return True

if dir == "f":  # i.e., "forward" away from the motor 
  dir = False
else:
  dir = True
spin(dir, steps)
print "Done"
GPIO.cleanup()

More about the linear motor, see:
http://dicks-photon-arduino.blogspot.com/, post 46.

Not represented in the above code: I added a relay switch for the 5v power to the motor. Otherwise steppers draw current constantly (and the motor housing can get hot). Too bad that the EasyDriver doesn't work like the ULN2003 -- which allows you to turn the 4 motor leads off without an added switch. Re relays: I got 5 single-relay devices on the cheap from Amazon; they lack opto-isolation and have no mounting holes -- but cheap.

1 comment:

  1. Stepper motors generally are not available in frame sizes larger than NEMA 34, with most applications falling in the nema 17 stepper motor or nema 23 stepper motor motor sizes. As a result, it is unusual to find stepper motors capable of producing more than 1000 to 2000 ounce inches of torque.

    ReplyDelete