Crate firmata_rs

Source
Expand description

§Firmata client library in Rust

Control your Firmata devices from Rust!

The library comes with a Board struct, which you can initialize with any object that implements std:io::{Read, Write} and Debug for formatting purposes. This avoids being locked in to a specific interface library. I highly recommend [serialport] for your USB connections (used in examples), but feel free to use [serial] or any other.

The different methods of the Firmata trait that return results also have backoff-able counterparts in the RetryFirmata trait that utilizes a backoff::ExponentialBackoff strategy powered by the backoff crate. This may be useful as your Rust program may run “too fast” for your Firmata device to keep up.

The crate has been set up to utilize tracing, which helps in finding where your messages went! If you set the environment variable CARGO_LOG=DEBUG you can capture the most noise.

§Examples

There are quite a couple of examples to try with your Firmata device! You can run each of them like this:

cargo run --example blink

Where blink is the example’s filename.

If you want the “full” output you can use:

RUST_LOG=DEBUG cargo run --example blink

§Installing Firmata on a device

Chances are you have an Arduino or other Firmata device lying around since you’re here :). You can go to your favorite Arduino IDE of choice and load the regular “StandardFirmata” onto your device and start tinkering!

§Finding the right port

You might need to set the USB port to the one that is in use on your machine. Find the right port_name in the list after running:

cargo run --example available

§Acknowledgements

This library is largely based on the earlier work by Adrian Zankich over at https://github.com/zankich/rust-firmata to whom should go out many thanks!

Structs§

Board
A Firmata board representation.
I2CReply
An I2C reply.
Mode
An available pin mode.
Pin
The current state and configuration of a pin.

Enums§

Error
Firmata error type.
Message
Received Firmata message

Constants§

ANALOG
ANALOG_MAPPING_QUERY
ANALOG_MAPPING_RESPONSE
ANALOG_MESSAGE
ANALOG_MESSAGE_BOUND
CAPABILITY_QUERY
CAPABILITY_RESPONSE
DIGITAL_MESSAGE
DIGITAL_MESSAGE_BOUND
ENCODER
ENCODER_DATA
END_SYSEX
EXTENDED_ANALOG
I2C
I2C_CONFIG
I2C_MODE_READ
I2C_MODE_WRITE
I2C_REPLY
I2C_REQUEST
INPUT
ONEWIRE
ONEWIRE_DATA
OUTPUT
PIN_MODE
PIN_STATE_QUERY
PIN_STATE_RESPONSE
PROTOCOL_VERSION
PWM
REPORT_ANALOG
REPORT_DIGITAL
REPORT_FIRMWARE
SAMPLING_INTERVAL
SCHEDULER_DATA
SERVO
SERVO_CONFIG
SHIFT_DATA
START_SYSEX
STEPPER
STEPPER_DATA
STRING_DATA
SYSEX_NON_REALTIME
SYSEX_REALTIME

Traits§

Firmata
Firmata board functionality.
RetryFirmata
Firmata board functionality that retries and fallible methods.

Type Aliases§

Result
Result type with Firmata Error.