• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
  • Created over 9 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Documentation and discussion point for IO Plugins

IO Plugins

Gitter

(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.

Available IO Plugins

The following platform IO Plugins are currently available:

Minimum Plugin Class Requirements

The plugin must...

  • Be a constructor function that defines a prototype object
  • Be a subclass of EventEmitter
  • Initialize instances that must...
    • asynchronously emit a "connect" event when the connection to a physical device has been made.
    • asynchronously emit a "ready" event when the handshake to the physical device is complete.
    • include a property named 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.
      • The process of establishing a connection and becoming "ready" is irrelevant to this document's purposes.
    • include a readonly property named MODES whose value is a frozen object containing the following property/values: { INPUT: 0, OUTPUT: 1, ANALOG: 2, PWM: 3, SERVO: 4 }
    • include a readonly property named SERIAL_PORT_IDs whose value is a frozen object containing key/value pairs that represent a platform independent serial port identification.
    • include a readonly property named 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.
      • each pin configuration object must contain the following properties and values:
        • 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
          • INPUT mode: property updated via the read loop
          • OUTPUT mode: property updated via *Write methods
        • report: 1 if reporting, 0 if not reporting
        • analogChannel: corresponding analogPin index (127 if none), eg. analogChannel: 0 is A0 whose index is 14 in the pins array.
    • include a readonly property named analogPins whose value is an array of pin indices that correspond to the analog pin indices in the pins array.
    • include a readonly property named HIGH whose value corresponds to the logic high value used by the IO plugin, e.g. 1
    • include a readonly property named LOW whose value corresponds to the logic low value used by the IO plugin, e.g. 0
  • If an essential IO feature is not implemented or cannot be implemented, the method must throw. For example, the Raspberry Pi does not support analog inputs, if user code calls through to an analogRead, the program must throw as an irrefutable means of indicating non-support.
  • If a non-essential IO feature is not implemented or cannot be implemented, the method must accept the expected arguments and indicate successful completion. For example, if it receives a callback, that callback must be called asynchronously.

Minimum API Requirements

pinMode(pin, mode)

  • Set the mode of a specified pin to one of:
INPUT: 0
OUTPUT: 1
ANALOG: 2
PWM: 3
SERVO: 4

Writing

Data writing operations must be executed in order of instruction.

analogWrite(pin, value)

pwmWrite(pin, value) (to supercede analogWrite)

  • Accept an 8 bit value (0-255) that is written to the specified pin.

digitalWrite(pin, value)

  • Accept a value (0 or 1) that is written to the specified pin.

i2cWrite(address, inBytes)

  • Write the array of inBytes to the specified address.

i2cWrite(address, register, inBytes)

  • Write the array of inBytes to the specified address and register.

i2cWriteReg(address, register, value)

  • Write the single value to the specified address and register.

serialWrite(portId, inBytes)

  • Write the array of inBytes to the specified portId.

servoWrite(pin, value)

  • Accept a 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.

Reading

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.

analogRead(pin, handler)

  • Initiate a new data reading process for pin
  • The recommended new data reading frequency is greater than or equal to 200Hz. Read cycles may reduce to 50Hz per platform capability, but no less.
  • Invoke handler for all new data reads, with a single argument which is the present value read from the pin.
  • A corresponding 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).

digitalRead(pin, handler)

  • Initiate a new data reading process for pin
  • The recommended new data reading frequency is greater than or equal to 200Hz. Read cycles may reduce to 50Hz per platform capability, but no less.
  • Invoke 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.
  • A corresponding 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).

i2cRead(address, register, bytesToRead, handler)

  • Initiate a new data reading process for address and register, requesting the specified number of bytesToRead.
  • The recommended new data reading frequency is greater than or equal to 100Hz. Read cycles may reduce to 50Hz per platform capability, but no less.
  • Invoke handler for all new data reads, with a single argument which is an array containing the bytes read.
  • A corresponding 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).

i2cRead(address, bytesToRead, handler)

  • Initiate a new data reading process for address, requesting the specified number of bytesToRead.
  • The recommended new data reading frequency is greater than or equal to 100Hz. Read cycles may reduce to 50Hz per platform capability, but no less.
  • Invoke handler for all new data reads, with a single argument which is an array containing the bytes read.
  • A corresponding 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).

i2cReadOnce(address, register, bytesToRead, handler)

  • Initiate a new data reading process for address and register, for the specified number of bytesToRead.
  • This new data read occurs only once.
  • Invoke handler with a single argument which is an array containing the bytes read.
  • A corresponding 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).

i2cReadOnce(address, bytesToRead, handler)

  • Initiate a new data reading process for address, requesting the specified number of bytesToRead.
  • This new data read occurs only once.
  • Invoke handler for all new data reads, with a single argument which is an array containing the bytes read.
  • A corresponding 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).

pingRead(settings, 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.

serialRead(portId, handler)

serialRead(portId[, maxBytesToRead], handler)

  • Initiate a new data reading process for portId, optionally capping the read to the specified maxBytesToRead.
  • The recommended new data reading frequency is greater than or equal to 100Hz. Read cycles may reduce to 50Hz per platform capability, but no less.
  • Invoke handler for all new data reads, with a single argument which is an array containing the bytes read.
  • A corresponding 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).

Configuring

i2cConfig(options)

  • 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.

    • Examples:
      • Firmata.js will negotiate a default register read in µs and a default value for the stopTX flag.
      • Tessel-IO will negotiate the bus to use.
  • All options specified by a user program in the instantiation of a component will be forwarded to i2cConfig.

serialConfig(options)

  • 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.

servoConfig(options)

  • 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

servoConfig(pin, min, max)

  • See #servoConfig(options)
  • This alternate MUST be supported

IO Control

These additions are still pending.

serialStop(portId)

  • Stop continuous reading of the specified serial portId.
  • This does not close the port, it stops reading it but keeps the port open.

serialClose(portId)

  • Close the specified serial portId.

serialFlush(portId)

  • Flush the specified serial 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.

Special Method Definitions

normalize(pin)

  • Define a special method that Johnny-Five will call when normalizing the pin value.
// 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.

More Repositories

1

idiomatic.js

Principles of Writing Consistent, Idiomatic JavaScript
23,134
star
2

johnny-five

JavaScript Robotics and IoT programming framework, developed at Bocoup.
JavaScript
13,283
star
3

tc39-notes

TC39 Meeting Notes
JavaScript
587
star
4

jquery-hive

jQuery Plugin for creating and managing web workers across implementations. Includes Hive.Pollen.js - the thread-safe utility library for connecting worker threads to the Hive.
JavaScript
203
star
5

jquery.eventsource

Harnessing the EventSource API with jQuery
JavaScript
186
star
6

particle-io

Particle/Spark Core/Photon IO Plugin for Johnny-Five
JavaScript
173
star
7

dmv

JavaScript
118
star
8

galileo-io

Intel Galileo & Intel Edison IO Plugin for Johnny-Five
JavaScript
101
star
9

temporal

Non-blocking, temporal task sequencing. For use with robots built with Johnny-Five
JavaScript
84
star
10

javascript-robotics

JavaScript
71
star
11

grunt-compare-size

JavaScript
62
star
12

proposal-math-extensions

ES Math Extensions
HTML
58
star
13

popcorn.capture

capture any frame from your popcorn video instance and save as png
JavaScript
57
star
14

tessel-io

A Tessel 2 IO Plugin for Johnny-Five JavaScript Robotics programs
JavaScript
50
star
15

proposal-enum-definitions

47
star
16

fritzing-components

Custom Fritzing parts
42
star
17

fact

JavaScript
38
star
18

popcorn.sequence

JavaScript
36
star
19

mediagroup.js

JavaScript
28
star
20

etherport

EtherPort is a transport layer
JavaScript
23
star
21

navigator.getusermedia

JavaScript
22
star
22

popcorn.kernel

JavaScript
20
star
23

playground-io

Adafruit Circuit Playground IO Plugin for Johnny-Five
JavaScript
15
star
24

nodebot-sbc

NodeBots SBC
14
star
25

rwaldron

JavaScript
14
star
26

esp-io

ESP-IO is an IO Plugin that enables writing JavaScript Robotics programs with Johnny-Five, which interact with ESP8266 boards.
13
star
27

imp-io

Electric Imp IO Plugin for Johnny-Five
JavaScript
12
star
28

arduino-adc-io-expander

Turn any Arduino into an ADC IO Expander with an I2C interface.
Arduino
12
star
29

mock-firmata

Mocks used for testing code that depends on Firmata
JavaScript
11
star
30

compulsive

loops and delays without traditional timers
JavaScript
11
star
31

bro

whats up bro
10
star
32

jquery-mobile-badge

JavaScript
10
star
33

subjectisdead

Haskell
9
star
34

popcorn.embedly

JavaScript
9
star
35

edison-io

Intel Edison & Intel Galileo IO Plugin for Johnny-Five
JavaScript
9
star
36

j5-ds-touch

A DS Touch Screen component plugin for Johnny-Five
JavaScript
9
star
37

idiomatic.json

8
star
38

tyrion

Agent/Device Firmware Pair for Electric Imp. Use with Imp-IO for Johnny-Five
Squirrel
8
star
39

butter

JavaScript
8
star
40

unprefix.js

JavaScript
8
star
41

j5-rc-receiver

RC Receiver component plugin for Johnny-Five
JavaScript
8
star
42

chromakey

html5 video chromakey
JavaScript
8
star
43

nino-io

Linino One & Arduino Yun IO Plugin for Johnny-Five
JavaScript
8
star
44

adventure

JavaScript
7
star
45

burst-core

First pass at re-writing the animation core of The Burst Engine for generic JS Object timeline control.
JavaScript
6
star
46

pee-wee-rover

JSConf 2015 JavaScript Robotics Project Files
JavaScript
5
star
47

node-jsdev

JavaScript
5
star
48

jQuery.Mines

Publisher/Subscriber system with expressive and flexible control - and a cool metaphor.
JavaScript
5
star
49

tiny-query

JavaScript
5
star
50

tinyquery

JavaScript
4
star
51

polyfill

JavaScript polyfill functions
JavaScript
4
star
52

EventSource

THIS IS NOT A RELEASE
JavaScript
4
star
53

avrdude

Arduino-specific version of avrdude
C
3
star
54

jquery-classlist

JavaScript
3
star
55

snippets.js

tab triggered js code snippets... everywhere!
JavaScript
3
star
56

i2c-backpack-workshop

3
star
57

sdactivity

JavaScript
3
star
58

sensors

Notes for Sensor API unification
3
star
59

espresso

Small JavaScript VM for Arduino Mega 2560
C
3
star
60

platoon

JavaScript
3
star
61

footils

For exercisin distributed development
JavaScript
3
star
62

nitwit

nitwit is a command line twitter status update program in python
3
star
63

reflecta-io

IO Plugin for controlling Arduino boards with Johnny-Five via Reflecta
JavaScript
3
star
64

popcorn.zoom

Popcorn plugin to zoom and rotate popcorn video objects
JavaScript
3
star
65

vox-populi-tests

2
star
66

sotu

JavaScript
2
star
67

pcduino-io

pcDuino IO Plugin for Johnny-Five
JavaScript
2
star
68

electron-io

Particle Electron IO Plugin for Johnny-Five
JavaScript
2
star
69

popcorn.create

JavaScript
2
star
70

j5-button-gestures

JavaScript
2
star
71

burst

A javascript vector animation engine for the HTML5 Canvas supporting SVGs, Blender3D objects, timelines, easing, command chanining and callbacks.
JavaScript
2
star
72

lemmy

49% Motherfucker | 51% Son of a Bitch Express + Mocha + HTML5 smart boilerplate for both Javascript and Coffee-Script that kicks your ass!!!
CoffeeScript
2
star
73

NXTI2CDevice

Patched version of NXTI2CDevice for use with Arduino 1.0+
C++
2
star
74

testharness.js

Test framework for writing javascript-based browser tests
JavaScript
1
star
75

cloudnine

hooking up with cloud9 beta
JavaScript
1
star
76

nodysentary.js

1
star
77

b9snvs0

1
star
78

taco

It's a tastier docco built with bootstrap.
CoffeeScript
1
star
79

blitz-node

Node.js API Client for Blitz
JavaScript
1
star
80

tubeyloops

JavaScript
1
star
81

cloudninetest

cloudninetest
JavaScript
1
star
82

popcorn.scene

JavaScript
1
star
83

t2-project

Build a project for deployment to a Tessel 2
JavaScript
1
star
84

animeiosis

JavaScript
1
star
85

junktown

1
star
86

tessel-include-bundling

JavaScript
1
star
87

sumobot

SumoBot class for Johnny-Five
JavaScript
1
star
88

junkbox

1
star
89

geniverse

JavaScript
1
star
90

duokey

JavaScript
1
star
91

webOS

webOS Related Projects.
JavaScript
1
star
92

ObjectLateral

Passing off objects since jqcon 2009
1
star
93

chrome-dev-snippets

JavaScript
1
star
94

scripty2-contrib

1
star
95

euler

JavaScript
1
star
96

tiny-jquery

Interview project
JavaScript
1
star
97

playback.js

JavaScript
1
star
98

Promise

An elegant promise implementation for Javascript
JavaScript
1
star
99

Rust.tmbundle-1

Rust Bundle for TextMate
1
star
100

Sublime-JSLint

Sublime Text Editor 2 JSLint Support
JavaScript
1
star