(This document is a work in progress)
An IO Plugin is any class whose instances implement a Firmata compatible interface. For an in-depth case study of creating an IO plugin, read about the design and creation of the Galileo-IO Plugin here.
IO Plugins are used extensively by Johnny-Five to communicate with non-Arduino based hardware but may also be used independently if desired.
The following platform IO Plugins are currently available:
The plugin must...
isReady
whose initial value is false
. isReady
must be set to true
in the same or previous execution turn as the the "ready" event is emitted.
MODES
whose value is a frozen object containing the following property/values: { INPUT: 0, OUTPUT: 1, ANALOG: 2, PWM: 3, SERVO: 4 }
SERIAL_PORT_IDs
whose value is a frozen object containing key/value pairs that represent a platform independent serial port identification. pins
whose value is an array of pin configuration objects. The indices of the pins
array must correspond to the pin address integer value, eg. on an Arduino UNO digital pin 0 is at index 0 and analog pin 0 is index 14. See mock-pins.js for a complete example.
supportedModes
: an array of modes supported by this pin, eg.
[0, 1, 2]
represents INPUT
, OUTPUT
, ANALOG
. (Common analog read capable pins)[0, 1, 4]
represents INPUT
, OUTPUT
, SERVO
. (Common digital I/O capable pins) [0, 1, 3, 4]
represents INPUT
, OUTPUT
, PWM
, SERVO
. (Common digital I/O and PWM capable pins)mode
: the current mode this pin is set to.value
: the current value of this pin
report
: 1 if reporting, 0 if not reportinganalogChannel
: corresponding analogPin index (127 if none), eg. analogChannel: 0
is A0
whose index is 14
in the pins
array.analogPins
whose value is an array of pin indices that correspond to the analog pin indices in the pins
array.HIGH
whose value corresponds to the logic high value used by the IO plugin, e.g. 1
LOW
whose value corresponds to the logic low value used by the IO plugin, e.g. 0
analogRead
, the program must throw as an irrefutable means of indicating non-support.INPUT: 0
OUTPUT: 1
ANALOG: 2
PWM: 3
SERVO: 4
Data writing operations must be executed in order of instruction.
analogWrite
)value
(0-255) that is written to the specified pin
.value
(0 or 1) that is written to the specified pin
.inBytes
to the specified address
.inBytes
to the specified address
and register
.value
to the specified address
and register
.inBytes
to the specified portId
.value
that is written to the specified pin
. If the value is between 0 and 180, it is assumed to be a servo arm position in degrees. If the value is between 180 and 544, it is also assumed to be in degrees and is truncated to 180. If the value is greater than or equal to 544, it is assumed to be a duty cycle in microseconds.All new data read processes must be asynchronous. The following methods must not block the execution process, by any means necessary. The following methods must not return the value of the new data read process.
pin
handler
for all new data reads, with a single argument which is the present value
read from the pin
.analog-read-${pin}
event is created and emitted for all new data reads, with a single argument which is the present value
read from the pin
(This can be used to invoke handler
).pin
handler
for all new data reads in which the data has changed from the previous data, with a single argument which is the present value
read from the pin
.digital-read-${pin}
event is created and emitted for all new data reads in which the data has changed from the previous data, with a single argument which is the present value
read from the pin
(This can be used to invoke handler
).address
and register
, requesting the specified number of bytesToRead
. handler
for all new data reads, with a single argument which is an array containing the bytes read.i2c-reply-${address}-${register}
event is created and emitted for all new data reads, with a single argument which is an array containing the bytes read. (This can be used to invoke handler
).address
, requesting the specified number of bytesToRead
. handler
for all new data reads, with a single argument which is an array containing the bytes read.i2c-reply-${address}
event is created and emitted for all new data reads, with a single argument which is an array containing the bytes read. (This can be used to invoke handler
).address
and register
, for the specified number of bytesToRead
. handler
with a single argument which is an array containing the bytes read.i2c-reply-${address}-${register}
"once" event is created and emitted, with a single argument which is an array containing the bytes read. (This can be used to invoke handler
).address
, requesting the specified number of bytesToRead
. handler
for all new data reads, with a single argument which is an array containing the bytes read.i2c-reply-${address}
event is created and emitted, with a single argument which is an array containing the bytes read. (This can be used to invoke handler
).This method is defined solely to handle the needs of HCSR04
(and similar) components.
No pin mode specified
Create a single data
event, invoking handler
.
settings
is an object that includes the following properties and corresponding values:
Property | Description | Default | Required |
---|---|---|---|
pin | The pin number/name attached to the servo | Yes | |
value | HIGH or LOW |
HIGH |
No |
pulseOut | Time µs for pulseIn timeout ✭ |
5 | No |
handler
is called with a duration value, in microseconds
, which is the result of take a pulsed measurement as required by HCSR04
(and similar) devices.
portId
, optionally capping the read to the specified maxBytesToRead
. handler
for all new data reads, with a single argument which is an array containing the bytes read.serial-data-${portId}
event is created and emitted for all new data reads, with a single argument which is an array containing the bytes read. (This can be used to invoke handler
).options
is an object that MUST include, at very least, the following properties and corresponding values:
Property | Description |
---|---|
address | The address of the I2C component |
options
may include any of the common configuration properties:
Property | Description |
---|---|
bus | The I2C bus |
port | The I2C bus port |
delay | Time µs between setting a register and reading the bus |
i2cConfig will always be called once by every I2C component controller class in Johnny-Five. This means that any setup necessary for a given platform's I2C peripheral capabilities should be done here.
stopTX
flag.bus
to use.All options specified by a user program in the instantiation of a component will be forwarded to i2cConfig.
Must be called to configure a serial/uart port
options
is an object that MUST include, at very least, the following properties and corresponding values:
Property | Description |
---|---|
portId | Some value that identifies the serial/uart port to configure |
options
may include any of the common configuration properties:
Property | Description |
---|---|
baud | The baud rate |
rxPin | The RX pin |
txPin | The TX pin |
All options specified by a user program in the instantiation of a component will be forwarded to serialConfig.
May be called as an alternative to calling pinMode(pin, SERVO)
.
options
is an object that MUST include, at very least, the following properties and corresponding values:
Property | Description | Default | Required |
---|---|---|---|
pin | The pin number/name attached to the servo | Yes | |
min | The minimum PWM pulse time in microseconds | ✭, ✭✭ | Yes |
max | The maximum PWM pulse time in microseconds | ✭, ✭✭✭ | Yes |
✭ This is platform dependent and should be tested thoroughly with as many different servos as possible.
✭✭ Approximiately between 400 and 600
✭✭✭ Approximately between 2200 and 2400
These additions are still pending.
portId
. portId
.portId
. For hardware serial, this waits for the transmission of outgoing serial data to complete. For software serial, this removes any buffered incoming serial data.
// Examples:
var io = new IOPlugin();
// The board might want to map "A*" pins to their integer value, // eg. Arduino allows user code to write "A0" for pin 14: io.normalize("A0"); // 14
### Special Property Definitions
#### defaultLed
- This is the pin address for the board's default, built-in led.
#### name
- A printable version of the name of the IO plugin being used, e.g. "Raspi IO"
### TODO
- Define pluggable transports, for example: replacing node-serialport with socket.io-serialport and similar.