On the Pi I have three motors (compared to just one on the Arduino), as a result many of the commands take an extra motor number parameter in the range 0..2.
The original code was written on Arduino, to make it work on Pi, I used the:
On Arduino the code gets commands from the serial port and responds the same way. For the Pi version I wrote an emulation of the necessary bits of the Serial class which uses standard input and output. As a result on Pi the code runs as a process and accepts typed commands, replying to the terminal.
The stepper folder is intended to be contained inside the top level wiringPi folder. Use the command
to run the code.
There was a snag with version 2.00, sudo processes are not killed when a terminal closes, as a result old invocations of stepper will continue to run. That is not too bad but there was a bug in the code which caused it to keep executing the last command line if there was no terminal present.
Version 2.02 adds two command line flags; 'pipe' to create named pipes for reading and writing commands and 'debug' to copy to stdout all output. The named pipes are /tmp/stepperin and /tmp/stepperout.
sudo ./stepper pipe
Opening two more terminals and entering
echo ve > /tmp/stepperin
will allow pipe mode to be tested.
For serious use, stepper is run once on boot and left running. The application for controlling the motors talks to the stepper process via the two named pipes using the Stepper Pi Library, or the node.js web app Stepper Pi Node.
- C++ source code for Stepper Pi - (2.03 6th June 2016)
- C++ source code for Stepper Pi - (2.10 14th July 2016)
pw <motor> [0|1|2]
Set power mode 0 = off, 1= on, 2= automatic
mv <motor> <distance>
Move, returns a message when move is complete including new position of the form:
mv <motor> <position>
sp <motor> <speed>
Set speed in steps per second. *
ac <motor> <acceleration>
Set acceleration in steps per second per second *
ss <motor> [1|2|4|8|16]
Set number of microsteps, in ti mode 32 is also allowed. *
Return current position. Gives response of the form:
ps <motor> <position>
Return distance to go
Read state of a pin, returns value
wr <pin> <value>
Write a value to a pin
sc <motor> <position>
Set the current position value. Allows zero point of values returned to be changed.
rs <motor> <speed>
Make the motor run continuously at the given speed. Use a value of zero to stop.
Return software version
Enter Texas Instruments mode. Enables 32 microstep mode.
This sets the base scale, default is 16. It sets the units that step values are measured in (as a multiple of one step). Just like one can choose to measure distances in 16 ths of an inch or 8 ths of an inch (or 1000 ths of a metre).
Motor movement resolution can't be less than the bs value. So if it is set to 16, the motor can move in 1/32 nds (ss =32) but will always end up on a 1/16 th position.
Test if optical sensor is present on given pin. Note the pull up resistors on the Tilt motor input mean this command is unlikely to give accurate results for that pin.
0 sensor connected 1 sensor not-connected
Whilst executing commands pause for time ms.
Start executing program n. Programs are held in the array
program and the first one is a NULL pointer so rc 0 stops execution.
ai <motor> <1|0> <mode>
Arm interrupt. Mode can be 0 or 1, signifying that the corresponding level on the input pin associated with the motor means the motor should be stopped. For the current implementation there is only one input per motor and the middle parameter (the interrupt number) should be left as 0. For example ai 1 0 0 means that motor 1 will be stopped when its input pin goes low. Interrupts clear after being triggered so this command should be issued before each move that you want an input change to stop.
ri <motor> <1|0>
Remove interrupt. Disarms the given interrupt.
Return debug info on interrupt state
sd <time in ms>
Shutdown Pi in given number of milliseconds. Gives response of the form:
Save settings with given name. If the name is omitted 'default' will be used. Gives response of the form:
Load settings from given name. If the name is omitted 'default' will be used. Gives a series of responses for all the saved values. Values are saved in a folder called 'profiles' in the same folder as the stepper task is run from. The profiles consist of a text file with the given name and the extension .txt. Each line in the text file contains a command from this page. For example:
ss 1 16
The same string would be one of the responses given by the ld command.
List saved profiles. Gives a response of the form:
ls <n> <name>
<n> is an index, starting from zero.
Start time lapse sequence
wp <motor> <start> <wp1> <wp2> <wp3> <end>
Set up way points. Any way point of value zero is ignored.
qv <no of images> <image interval> <sequence duration> <camera settle time> <exposure delay> <no of steps> <delay after last move>
qw <fire raise delay>
qm <motor> <use> <move in> <step length> <delay before first move> <ramp up>
Sequence query, find time lapse sequence information, gives a response of the form:
qq <state> <time> <step>
Responses like this are given whenever the time lapse state changes - without the command being issued.