Skip to main content

pymata-express

A high performance, Python asyncio client for the Arduino Firmata Protocol.

Pymata-Express is a Firmata client that, like its conventional Python sibling, pymata4, allows you to control an Arduino using the high-performance FirmataExpress sketch.

It supports both an enhanced version of StandardaFirmata 2.5.8, called FirmataExpress, as well as StandardFirmata and StandardFimataWiFi.

  • FirmataExpress adds support for:
    • HC-SR04 Ultrasonic Distance Sensors using a single pin.
    • DHT Humidity/Temperature Sensors.
    • Stepper Motors.
    • Piezo Tone Generation.
    • Baud rate of 115200

Major features

  • Fully documented intuitive API

  • Python 3.7+ compatible.

  • Set the pin mode and go!

  • Data change events may be associated with a callback function or each pin can be polled for its last event change.

    • Each data change event is time stamped and logged.
  • User's Guide, Including Examples.

  • Implements 100% of the StandardFirmata Protocol (StandardFirmata 2.5.8).

  • Advanced auto-detection of Arduino devices (when using FirmataExpress).

Here is an example that monitors for data changes on a digital input pin.

import asyncio
import time
import sys
from pymata_express import pymata_express

"""
Setup a pin for digital input and monitor its changes
using a callback.
"""

# Setup a pin for analog input and monitor its changes
DIGITAL_PIN = 12  # arduino pin number
IDLE_TIME = .001  # number of seconds for idle loop to sleep

# Callback data indices
# Callback data indices
CB_PIN_MODE = 0
CB_PIN = 1
CB_VALUE = 2
CB_TIME = 3


async def the_callback(data):
    """
    A callback function to report data changes.
    This will print the pin number, its reported value and
    the date and time when the change occurred

    :param data: [pin, current reported value, pin_mode, timestamp]
    """
    date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[CB_TIME]))
    print(f'Pin: {data[CB_PIN]} Value: {data[CB_VALUE]} Time Stamp: {date}')


async def digital_in(my_board, pin):
    """
     This function establishes the pin as a
     digital input. Any changes on this pin will
     be reported through the call back function.

     :param my_board: a pymata_express instance
     :param pin: Arduino pin number
     """

    # set the pin mode
    await my_board.set_pin_mode_digital_input(pin, callback=the_callback)

    while True:
        try:
            await asyncio.sleep(IDLE_TIME)
        except KeyboardInterrupt:
            await board.shutdown()
            sys.exit(0)

# get the event loop
loop = asyncio.get_event_loop()

# instantiate pymata_express
board = pymata_express.PymataExpress()

try:
    # start the main function
    loop.run_until_complete(digital_in(board, 12))
except (KeyboardInterrupt, RuntimeError) as e:
    loop.run_until_complete(board.shutdown())
    sys.exit(0)

Sample console output as input change events occur:

Pin: 12 Value: 0 Time Stamp: 2020-03-10 13:26:22
Pin: 12 Value: 1 Time Stamp: 2020-03-10 13:26:27

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymata-express-1.21.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymata_express-1.21-py2.py3-none-any.whl (49.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pymata-express-1.21.tar.gz.

File metadata

  • Download URL: pymata-express-1.21.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5

File hashes

Hashes for pymata-express-1.21.tar.gz
Algorithm Hash digest
SHA256 1417197ef601c3515829801c2afac158b1c24a78d7590adfdd38231d21c394d1
MD5 e415124662af64a3f9c85aa0cf7b9ddd
BLAKE2b-256 587520319f69e6ed750d817e4a09bf50ae92f94ddc905a19428bf49b9a99f9e0

See more details on using hashes here.

File details

Details for the file pymata_express-1.21-py2.py3-none-any.whl.

File metadata

  • Download URL: pymata_express-1.21-py2.py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.5

File hashes

Hashes for pymata_express-1.21-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9a77974b2b79605df179bd3dfb65cf2c125e55207ca03dd810848cd2c73af665
MD5 67343f81440d905bd9df93e8a1c5e4e3
BLAKE2b-256 fac85e80feae1776fd3c8fafd30011c8b540f6f93c922ff97e110abfb9671fe7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.21 This release

2 files

1.20

2 files

1.19

2 files

1.18

2 files

1.17

2 files

1.16

2 files

1.15

2 files

1.14

2 files

1.13

2 files

1.12

2 files

1.11

2 files

1.10

2 files

1.9

2 files

1.8

2 files

1.7

2 files

1.6

2 files

1.5

2 files

1.4

2 files

1.3

2 files

1.2

2 files

1.1

2 files

1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page