Académique Documents
Professionnel Documents
Culture Documents
TRENDING
StepperMotorControlInPython
Welcome
HOME
CATEGORIES
Home
General
BERRYCLIP
BUY
TOOLS
CONTACT US
Search...
SITE MAP
45
GENERAL
RECENT
POPULAR
NEWS
FEBRUARY 8, 2016
Having played with LEDs, switches and buzzers I felt the natural next step was playing with a stepper motor
or two. This might form part of an idea I had to create an automated stop motion animation turn table for
rotating and photographing objects.
DECEMBER 8, 2015
There is a huge selection of motors to buy but I decided to experiment with a 28BJY-48 with ULN2003 control board.
Test
DECEMBER 6, 2015
It is cheap
DECEMBER 3, 2015
Zero Case
Easy to interface
I ordered two from 4tronix_uk on eBay and they arrived the next day. There are additional details in the Stepper
Motor 28BJY-48 Datasheet
Interfacing With The Pi
Search
Search
CATEGORIES
The motor connects to the controller board with a presupplied connector. The controller board has 4+2 pins that
need to be connected to the Pi header (P1).
5V (P1-02)
GND (P1-06)
3D Printing
Add-ons
BerryClip
Books
Camera Module
and
Cases
Inp1 (P1-11)
Inp2 (P1-15)
Events
General
Inp3 (P1-16)
Inp4 (P1-18)
Hardware
I2C
http://www.raspberrypispy.co.uk/2012/07/steppermotorcontrolinpython/#comments
1/10
19.02.2016.
StepperMotorControlInPython
Infographics
Minecraft
Model A+
Model B+
News
Pi 2 Model B
Pi Zero
sequence.
Power
Python Script
Programming
Python
Here is a copy of the stepper motor script I used to rotate the stepper motor. It uses the RPi.GPIO library and
defines a 4-step and 8-step sequence.
Raspbian
Robotics
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
#Importrequiredlibraries
importsys
importtime
importRPi.GPIOasGPIO
#UseBCMGPIOreferences
#insteadofphysicalpinnumbers
GPIO.setmode(GPIO.BCM)
#DefineGPIOsignalstouse
#Physicalpins11,15,16,18
#GPIO17,GPIO22,GPIO23,GPIO24
StepPins=[17,22,23,24]
#Setallpinsasoutput
forpininStepPins:
print"Setuppins"
GPIO.setup(pin,GPIO.OUT)
GPIO.output(pin,False)
#Defineadvancedsequence
#asshowninmanufacturersdatasheet
Seq=[[1,0,0,1],
[1,0,0,0],
[1,1,0,0],
[0,1,0,0],
[0,1,1,0],
[0,0,1,0],
[0,0,1,1],
[0,0,0,1]]
StepCount=len(Seq)
StepDir=1#Setto1or2forclockwise
#Setto1or2foranticlockwise
#Readwaittimefromcommandline
iflen(sys.argv)>1:
WaitTime=int(sys.argv[1])/float(1000)
else:
WaitTime=10/float(1000)
#Initialisevariables
StepCounter=0
#Startmainloop
whileTrue:
printStepCounter,
printSeq[StepCounter]
forpininrange(0,4):
xpin=StepPins[pin]#GetGPIO
ifSeq[StepCounter][pin]!=0:
print"EnableGPIO%i"%(xpin)
GPIO.output(xpin,True)
else:
GPIO.output(xpin,False)
StepCounter+=StepDir
#Ifwereachtheendofthesequence
#startagain
if(StepCounter>=StepCount):
StepCounter=0
if(StepCounter<0):
StepCounter=StepCount+StepDir
#Waitbeforemovingon
time.sleep(WaitTime)
Sensors
Software
Tutorials & Help
TAGS
3D Printing
44780
battery
berryclip
cambridge
camera
DigiMakers
mp4
portable
Model A
sensor
ultrasonic
sd card
soldering
cpu
i2c
Linux
Model B
photos
Pi-Lite
python
power
revision
Book
CamJam
Li-on
photography
Raspberry Pi Bootcamp
ravpower
bluetooth
LED
Minecraft
pcb
avconv
GPIO
games
lcd
Kickstarter
mcp23017
audio
SPI
raspbian
security
temperature
video
RASPBERRY PI RELATED
You can download it directly to your Pi using :
Averageman Vs Pi
wgethttps://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/stepper.py
MattsBits Pi Resources
Official RaspBerry Pi Site
As with all Python scripts that use the GPIO library it needs to be run using sudo :
1
sudopythonstepper.py
http://www.raspberrypispy.co.uk/2012/07/steppermotorcontrolinpython/#comments
Raspberry Pi Pod
RasPi.tv
Raspihub.com
2/10
19.02.2016.
StepperMotorControlInPython
Raspihub.com
RaspTut
Rastrack.co.uk
RPi School
TECH RESOURCES
In this example the default wait time is set to 0.01 seconds (10 milliseconds). To change the speed of rotation you
can change thisvalue. I found I could reduce it to 4ms before the motor stopped working. If the script runs too fast
the motor controller cant keep up. This performance may vary depending on your motor and its controller.
How2Code
Technology Spy
The 4 step sequence is faster but the torque is lower. Its easy to stop the rotation by holding the motor spindle. The
8 step sequence is slower but the torque is much higher. For my turntable application I prefer the torque over
ARCHIVES
Archives
SelectMonth
You can now control a stepper motor using a Raspberry Pi and some Python script. Add another motor and youve
got the beginnings of a small robot!
SHARE.
PREVIOUS ARTICLE
NEXT ARTICLE
RELATED POSTS
DECEMBER 8, 2014
APRIL 3, 2014
57
11
Glossary
45 COMMENTS
As I understand it, the torque is higher when you select two inputs because you have twice the number
of coils activated. If this is the case, then surely your 8 step sequence actually does High Torque turn
(2 inputs), Low Torque turn (1 input), High Torque turn (2 inputs), Low Torque turn (1 input)
I could be very wrong, but think you may not be using the entire torque available.
http://www.raspberrypispy.co.uk/2012/07/steppermotorcontrolinpython/#comments
REPLY
3/10