RPistepper is a library control stepper motors using a Raspberry Pi and a transistor array
Project description
RPistepper is a library containing: * A class to control a stepper motor with a RPi. * A function to execute a zig-zag motion with two motors. * A function to execute a square_spiral motion with two motors.
Wiring
In our setup, the power to the motors (Vm) is supplied with the 5V pins of the RPi, the grounding of the coils is controlled with a ULN2803A transistor array.
Conections RPi - ULN2803A:
RPi Pin (BCM) |
ULN2803A |
---|---|
17 |
1B |
27 |
2B |
10 |
3B |
9 |
4B |
14 |
5B |
15 |
6B |
23 |
7B |
24 |
8B |
Conections ULN2803A - Motors:
ULN2803A |
Motors |
---|---|
1C |
Motor_1 Coil_A1 |
2C |
Motor_1 Coil_A2 |
3C |
Motor_1 Coil_B1 |
4C |
Motor_1 Coil_B2 |
5C |
Motor_2 Coil_A1 |
6C |
Motor_2 Coil_A2 |
7C |
Motor_2 Coil_B1 |
8C |
Motor_2 Coil_B2 |
In this case, two motors were attached to the ULN2803A.
Usage
class Motor
This class allows the user to control a 6 pin stepper motor using 4 GPIO pins of a RPi.
Software uses BCM mode for pin indexing.
This class is best used with the ‘with’ statement to properly handle the cleanup of the GPIOs.
self.steps is a property of this class that will get the number of steps taken from the initial position or set to a specific step, similar to self.move.
In order to save power, it’s advised to call self.release() when the motor is idle.
Arguments are a list with the 4 pins (Coil_A1, Coil_A2, Coil_B1, Coil_B2), the delay between steps (default = 20ms) and verbose to display reports on the motor movements, the last two are optional. e.g:
import RPistepper as stp
M1_pins = [17, 27, 10, 9]
with stp.Motor(M1_pins) as M1:
for i in range(10): # moves 20 steps,release and wait
print M1
M1.move(20)
M1.release()
raw_input('enter to execute next step')
If the class is instantiated normally, use the method cleanup prior to closing the application to close the GPIO resources. Also, if it’s important to go back to the initial position when finishing the routine, use the method reset.
import RPistepper as stp
M1_pins = [17, 27, 10, 9]
M1 = stp.Motor(M1_pins)
for i in range(10): # moves 20 steps,release and wait
print M1
M1.move(20)
M1.release()
raw_input('enter to execute next step')
M1.reset()
M1.cleanup()
Methods
Currently there are five implemented methods:
def move(self, steps):
'''
Moves the motor 'steps' steps. Negative steps moves the motor backwards
'''
def release(self):
'''
Sets all pins low. Power saving mode
'''
def reset(self):
'''
Returns the motor to it's initial position
'''
def zero(self):
'''
Sets the motor to the next position which Coil_A1 and Coil_A2
are on. Sets this position as the reference (steps = 0).
'''
def cleanup(self):
'''
Cleans the GPIO resources
'''
The main method is move, which moves the motor the desired number of steps
steps property
It’s possible to check the motor position or manually set the desired step using the steps property:
import RPistepper as stp
M1_pins = [17, 27, 10, 9]
with stp.Motor(M1_pins) as M1:
for i in range(10): # moves 20 steps,release and wait
print M1.steps
M1.steps = 20*i
M1.release()
raw_input('enter to execute next step')
M1.reset()
Attributes
This class haves the following attributes:
Attribute |
Data |
---|---|
DELAY |
Time between steps |
VERBOSE |
Display motor data on screen |
PINS |
GPIOs used by the instance |
actual_state |
A list with the status of the coils (on/off) |
functions
These two functions executes pre determined movements and requires two stepper motor objects:
def zig_zag(motor1, motor2, amp1, amp2, delay=None):
'''
Executes a zig-zag movement with two RPistepper objects.
Arguments are: motor1 and motor2 objects and amp1, amp2, the amplitude
of movement, a tuple (step, rep) representing the number of steps per
iteration and the number of iterations of the following algorithm:
Repeat rep1 times:
1. Moves motor 2 step2*rep2 steps forward
2. Moves motor 1 step1 steps forward
3. Moves motor 2 step2*rep2 steps backwards
4. Moves motor 1 step1 steps forward
Reset to initial state
Release the motors
It's possible to change the delay between steps with the 'delay' argument
'''
def square_spiral(motor1, motor2, amplitude, delay=None):
'''
Executes a square spiral movement with two RPistepper objects.
Arguments are: motor1 and motor2 objects and the amplitude of movement,
a tuple (step, rep) representing the number of steps per iteration and
the number of iterations of the following algorithm:
for i in range(rep):
1. Moves motor 2 to position i
2. Moves motor 1 to position i
3. Moves motor 1 to position -i
4. Moves motor 2 to position -i
Reset to initial state
Release the motors
It's possible to change the delay between steps with the 'delay' argument
'''
/bin/rpistepper
rpistepper is a shell for controlling the motors. It provides all the methods in the Motor class. All the commands are documented in the shell. It’s possible to pipe a list of commands to the shell:
rpistepper < sample.stp
or
cat sample.stp | rpistepper
Invoking rpistepper with -g flag will open a GUI application with similar functionality
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file RPistepper-0.3a1.tar.gz
.
File metadata
- Download URL: RPistepper-0.3a1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5acb4f1b2f48156508766d1ee95b37deaaf99af8a1bda9a0e050f83439dde2c |
|
MD5 | ed028ec984fd99c8744b4c1e1e9cb915 |
|
BLAKE2b-256 | 71377d6c53cdc01c1079af1c7def49d113f0aa30414a472ef31d08b48f1ed4a6 |
File details
Details for the file RPistepper-0.3a1-py3-none-any.whl
.
File metadata
- Download URL: RPistepper-0.3a1-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22088cf45642cc4f6528acaec5a3a89001d7dd767d5928ba36f0d25566c84937 |
|
MD5 | 80c877c2d99ec3fd8c286b1758174604 |
|
BLAKE2b-256 | 0f3d66c98d74a66b0b157403ebc231e1bf1c603483f917a5210e05c6971e0d26 |