MrYsLab / PyMata

A Python client class library for Interaction with Standard Firmata
GNU Affero General Public License v3.0
95 stars 40 forks source link

THIS REPOSITORY HAS BEEN ARCHIVED

PLEASE USE pymata4.

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

Callbacks

Check out the example code on the wiki.

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

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!

This project was developed with Pycharm logo