Firmata

The Firmata protocol is based on the MIDI protocol used for communicating with musical equipment.

It is also one of the most widely used protocols for communication with Arduino devices.

This driver is built to be compatible with the StandardFirmata Arduino Sketch which can be found here (Version last changed on August 17th, 2017)

Connection String Options

Name

Type

Default Value

Required

Description

Name

Firmata

Code

firmata

Maven Dependency

<dependency>
  <groupId>org.apache.plc4x</groupId>
  <artifactId>plc4j-driver-firmata</artifactId>
  <version>pre-release</version>
</dependency>

Default Transport

serial

Supported Transports

  • serial

  • tcp

Config options:

request-timeout

INT

10000

Maximum time (in milliseconds) to wait for the initial firmware-report reply during connection setup.

Transport config options:

serial

serial.baud-rate

INT

9600

Baud rate (bits per second)

serial.data-bits

INT

8

Number of data bits (5, 6, 7, or 8)

serial.stop-bits

INT

1

Number of stop bits (1 or 2)

serial.parity

STRING

NONE

Parity: NONE, ODD, EVEN, MARK, SPACE

serial.flow-control

STRING

NONE

Flow control: NONE, RTS_CTS, XON_XOFF, RTS_CTS_XON_XOFF

serial.read-timeout

INT

1000

Read timeout in milliseconds. 0 means blocking read.

serial.write-timeout

INT

1000

Write timeout in milliseconds.

serial.dtr

BOOLEAN

false

Enable DTR (Data Terminal Ready) signal

serial.rts

BOOLEAN

false

Enable RTS (Request To Send) signal

serial.reuse-port

BOOLEAN

false

Reuse the underlying serial port across multiple transport instances. When true, instances with the same port will share a connection. This is useful for protocols where multiple logical connections share one serial port.

serial.receive-buffer-size

INT

4096

Receive buffer size in bytes. 0 uses system default.

serial.send-buffer-size

INT

4096

Send buffer size in bytes. 0 uses system default.

serial.break-enabled

BOOLEAN

false

Enable break signal

serial.interframe-delay

INT

0

Interframe delay in milliseconds for protocols that need spacing between messages. Only applies when reusePort is true.

tcp

tcp.connect-timeout

INT

5000

tcp.read-timeout

INT

0

tcp.write-timeout

INT

0

tcp.tcp-no-delay

BOOLEAN

true

tcp.keep-alive

BOOLEAN

false

tcp.send-buffer-size

INT

81920

tcp.receive-buffer-size

INT

81920

tcp.local-address

STRING

tcp.local-port

INT

0

Name

Value

Description

Supported Operations

write

Writing is only supported to digital addresses.

subscribe

Reading is supported for both digital and analog addresses. See note after this table however.

When subscribing to pins, these are configured to become read pins. When writing to digital pins, these are configured to become output pins. However, writing to pins for which a subscription exists, an exception will be thrown. In order to write to previously subscribed pins, all subscriptions for this have to be cancelled first.

Individual Resource Address Format

Similar to the Modbus protocol, the Firmata protocol support Boolean and Short values.

Booleans are used for the digital IO pins and short values for the analog inputs.

Binary Addresses

The full format for a digital address has the following format:

digital:{start-address}[{array-size}]:{special-config}

The start-address and array-size are simple integer values. special-config can be used to configure the digital input pin to something else than INPUT.

Currently the only supported option is PULLUP which configured the Arduino’s digital input pin to use it’s built in pullup-resistor.

Both the array-size as well as the special-config parts are optional. So the following example addresses are valid:

digital:4
digital:4[5]
digital:4:PULLUP

A normal Arduino Uno is equipped with 14 digital inputs: 0-13

However in case of using the serial port (which will always be the case when using this driver), the pins 0 and 1 are the RX and TX pins of the serial port and can’t be used.

Analog Addresses

The full format for an analog address is as follows:

analog:{start-address}[{array-size}]

The start-address and array-size are simple integer values.

Both the array-size is optional. So the following example addresses are valid:

analog:1
analog:2[3]

A normal Arduino Uno is equipped with 6 analog inputs: 0-5