Skip to main content

Minimal Firmata protocol client for Arduino (StandardFirmata). Only depends on pyserial.

Project description

firmata-client

A minimal Firmata protocol client for Arduino boards running StandardFirmata.

The only dependency is pyserial.

Requirements

  • Python 3.13+
  • Arduino flashed with StandardFirmata (included in the Arduino IDE: File → Examples → Firmata → StandardFirmata)

Installation

pip install firmata-client

Quick start

import logging
import sys
import time

from firmata_client import FirmataClient, PinMode

# Enable all firmata messages including serial traffic:
logging.basicConfig(
    level=logging.DEBUG,
    format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
)

# Suppress serial traffic
logging.getLogger("firmata.serial").setLevel(logging.WARNING)

PORT = sys.argv[1] if len(sys.argv) > 1 else "COM8"

print(f"Connecting to {PORT} ...")
client = FirmataClient(PORT)

print("Querying board info ...")
info = client.query_board_info()
print(f"  Firmware : {info['firmware']}  v{info['version']}")
print(f"  Pin count: {len(info['capabilities'])}")
print(f"  Analog ch: {info['analog_mapping']}")

print("Read analog A0 ...")
A0_CH = 0
client.set_pin_mode(info["analog_mapping"][A0_CH], PinMode.ANALOG)
client.report_analog(A0_CH, True)  # enable reporting
time.sleep(0.2)
print(f"  A0 value : {client.analog_read(A0_CH)}")

print("Blink D13 several times ...")
D13 = 13
client.set_pin_mode(D13, PinMode.OUTPUT)
for _ in range(10):
    client.digital_write(D13, True)
    time.sleep(0.5)
    client.digital_write(D13, False)
    time.sleep(0.5)

client.close()
print("Done.")

API reference

FirmataClient(port, baudrate=57600, timeout=5.0)

Method Description
close() Stop the reader thread and close the port.
query_board_info() -> dict Fetch firmware name, protocol version, pin capabilities, and analog mapping.
set_pin_mode(pin, mode) Set a pin mode (PinMode.INPUT/OUTPUT/ANALOG/PWM/SERVO).
digital_write(pin, value) Write True/False to a digital output pin.
digital_read(pin) -> int | None Read the latest cached digital value (requires report_digital).
analog_write(pin, value) Write a PWM (0–255) or servo (0–180) value.
analog_read(channel) -> int | None Read the latest cached analog value (requires report_analog).
report_analog(channel, enable) Enable/disable streaming analog readings for a channel.
report_digital(port, enable) Enable/disable streaming digital readings for a port.

License

MIT

Project details


Download files

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

Source Distribution

firmata_client-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

firmata_client-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file firmata_client-0.1.0.tar.gz.

File metadata

  • Download URL: firmata_client-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for firmata_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 15b123edcf49bbf6eb132fbecde16bda321b245d088a665f07005cd56e0302b6
MD5 b2bf7bc1f4123d86014a3c1e66338041
BLAKE2b-256 8654170b64d2c5e93ba9a0e69564851f979369fc4d0243681ea1f959aa970e7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for firmata_client-0.1.0.tar.gz:

Publisher: python-publish.yml on NaoNaoMe/firmata-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file firmata_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: firmata_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for firmata_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c1116b5576e9b6f45ec398749a11d8eb7b21d48ce4a4dbb61d0b5acf8998e52
MD5 2ff78b24fb377666ab3b42340ec60195
BLAKE2b-256 cdcfaeca3818a249e39482c3f0bc05014d70275fe24dd26355025ad203e997a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for firmata_client-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on NaoNaoMe/firmata-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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