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.1.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.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: firmata_client-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 fcc0cacb912664dcdbe41458a1ea476d4fd9a02b97d50f09fbfb3fe3798e8ae5
MD5 e02a32b72d5b37ec7d2eb076bce28ab1
BLAKE2b-256 dcdc30924f18341e2b472aa685851f9c3d79d1c1e5105e0c74be49850f331ad9

See more details on using hashes here.

Provenance

The following attestation bundles were made for firmata_client-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: firmata_client-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0fb1d973c621444e69d86e203f3ab3fa6cc6b3a31c8f6a745d1367ffbdc1f779
MD5 79dee772f71cabad3484ff7177122935
BLAKE2b-256 a90355fbe7e493805851beaf38dddea3c0f5321709b80ff83784a309c8adc325

See more details on using hashes here.

Provenance

The following attestation bundles were made for firmata_client-0.1.1-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