Arduino
Setup
First, install the Python module.
pip install python-arduino
Next, plug in an Arduino board. Locate the device file that corresponds to it:
user@comp:~$ cd /dev
user@comp:/dev$ ll | grep ttyACM
crw-rw---- 1 root dialout 166, 0 Nov 6 00:00 ttyACM0 # This is the device file
user@comp:/dev$ sudo chmod 666 ttyACM0 # Allow all users to control it
Before you can control the board, compile and upload the Firmata program to it. Open the
Arduino IDE and open File >> Examples >> Firmata >> StandardFirmata
, and compile and upload.
Core
Motor
- class arduino.motor.Stepper(board: pyfirmata.pyfirmata.Board, spr: int)
Base stepper motor class. Extend from this to create a specific motor.
- clock: arduino.core.Clock
Motor’s clock. Set at init so no overhead for creating the object.
- property pos: float
The current position in degrees.
- rotate(deg: float, rpm: float)
Rotate the motor.
- Parameters
deg – The angle to rotate in degrees.
rpm – Speed in revolutions per minute.
- rotate_for(deg: float, t: float)
Rotate
deg
fort
seconds.
- rotate_to(deg: float, rpm: float)
Rotate to
deg
atrpm
rotations per minute.
- rotate_to_for(deg: float, t: float)
Rotate to
deg
fort
seconds.
- spr: int
Steps per revolution.
- step(cw: bool, t: float)
Step the motor. Calls
self._step(cw, t)
. Define in a subclass.- Parameters
cw – True if clockwise, False if counter-clockwise.
t – Total step time.
This is a Python module which provides an API to controlling Arduino boards. It uses PyFirmata to communicate, and provides functions which implement individual pin controls.