Donnerstag, 13. Dezember 2012

Controlling a stepper with raspberrypi gpio pins

Raspberry RASPBRRY-MODB-512M Mainboard Sockel (ARM 1176JZF-S, 2x USB 2.0, 1x HDMI)





First of all, you need the wiringPi library from https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/
Once installed, there is a new command gpio which can be used as a non-root user to control the GPIO pins.

I took a schmalzhaus easydriver stepper shield, controlled with a little shell script.

circuit layout:



My stepper has 1,8° = 200 Steps for 360°
GPIO pin 23 controlls the steps, one high peak per step,
GPIO pin 24 controlls the direction

30 times clockwise and counterclockwise Rounds:

shell script:

#!/bin/sh
pause=0.001
gpio -g mode 23 out
gpio -g mode 24 out


for i in $(seq 30); do

echo round $i starts:
sleep 1

gpio -g write 24 1
for i in $(seq 200); do
  echo $i
  gpio -g write 23 1
  sleep $pause
  gpio -g write 23 0
  sleep $pause
done
sleep 1
gpio -g write 24 0
for i in $(seq 200); do
  echo $i
  gpio -g write 23 1
  sleep $pause
  gpio -g write 23 0
  sleep $pause
done
done

1 Kommentar:

  1. Danke! great tutorial. But is there a way to do the same with python?
    I've been looking for a while now. You're the first that I find on the web
    that shares a layout on how to connect it! Would it be the same if I drive
    it though Python?

    AntwortenLöschen