A Python Protocol Abstraction Library For Arduino Firmata
Project description
PyMata
PyMata is a high performance, multi-threaded, non-blocking Python client for the Firmata Protocol that supports the complete StandardFirmata protocol.
A new version for Python 3.5, pymata_aio, can be found here.
The API can be viewed on the wiki
##Major features
- Implements the entire Firmata 2.4.1 protocol.
- Python 2.7+ and Python 3.4+ compatibility through a shared code set. (If you are running Python 3.4 on Linux, please see note below).
- Easy to use and intuitive API. You can view the PyMata API Documentation here or view in the Documentation/html directory.
- Custom support for stepper motors, Sonar Ping Devices (HC-SRO4), Piezo devices and Rotary Encoders.
- Requires the use of FirmataPlus for PyMata - installation instructions may be found here.
- Wiring diagrams are provided for all examples in the examples directory.
- Digial and Analog Transient Signal Monitoring Via Data Latches:
- They provide "one-shot" notification when either a digital or analog pin meets a user defined threshold.
- Analog latches compare each data change to a user specified value.
- Comparison operators are <, >, <= and >=
- Digital latches compare a data change to either a high or low, specified by the user.
- Latches can easily be re-armed to detect the next transient data change.
- Latches can be either manually read or a callback can be associated with a latch for immediate notification.
- Optional callbacks provide asynchronous notification of data updates.
Callbacks
Check out the example code on the wiki.
- Digital input pins.
- Analog input pins.
- Encoder changes.
- I2C read data changes.
- SONAR (HC-SR04) distance changes.
- Analog latch condition achieved.
- Digital latch condition achieved.
- Callbacks return data reports in a single list format.
- Polling methods and callbacks are available simultaneously and can be used in a mixed polled/callback environment.
- Callbacks return data in a single list.
The callback data return values
Callback Type | List Element 0 | List Element 1 | List Element 2 | List Element 3 |
---|---|---|---|---|
Analog | ANALOG MODE | Pin Number | Data Value | Not Applicable |
Digital | DIGITAL MODE | Pin Number | Data Value | Not Applicable |
I2C | I2C MODE | I2C Device Address | Data Value | Not Applicable |
Sonar | Trigger Pin | Distance in Centimeters | Not Applicable | Not Applicatble |
Encoder | Encoder MODE | Pin Number | Data Value | Not Applicable |
Latched Analog | LATCHED ANALOG MODE | Pin Number | Data Value | Time Stamp |
Latched Digital | LATCHED DIGITAL MODE | Pin Number | Data Value | Time Stamp |
Control-C Signal Handler
Below is a sample Control-C signal handler that can be added to a PyMata Application. It suppresses exceptions being reported as a result of the user entering a Control-C to abort the application.
import sys
import signal
# followed by another imports your application requires
# create a PyMata instance
# set the COM port string specifically for your platform
board = PyMata("/dev/ttyACM0")
# signal handler function called when Control-C occurs
def signal_handler(signal, frame):
print('You pressed Ctrl+C!!!!')
if board != None:
board.reset()
sys.exit(0)
# listen for SIGINT
signal.signal(signal.SIGINT, signal_handler)
# Your Application Continues Below This Point
Misc
- Want to extend PyMata? See Our Instructables Article explaining how stepper motor support was added. Use it as a guide to customize PyMata for your own needs.
- Check Out Mr. Y's Blog Here for all the latest news!
Special Note For Linux Users Wishing to Use Python 3.5
pymata_aio is now available and for Python 3.5.
Check out the pymata_aio wiki!
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
PyMata-2.18.tar.gz
(21.2 kB
view hashes)
Built Distributions
PyMata-2.18-py2.py3-none-any.whl
(22.6 kB
view hashes)
PyMata-2.18-py2.7.egg
(41.1 kB
view hashes)
Close
Hashes for PyMata-2.18-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3219dc67634652ef46b58f788a6e3eda7f129db8ee218bf3ce3df12bfcdcb346 |
|
MD5 | 9cee65a6bf29e61f6fc3e0c71e3903f0 |
|
BLAKE2b-256 | 040f44da4e49e168df76b23c3a98b03f168afd2b6d66fa1b5edbd8de483119ee |