The Board API provides low level interfaces for I/O operations:
- AIO - Analog I/O
- GPIO - General Purpose I/O
- PWM - Pulse Width Modulation
- I2C - Inter-Integrated Circuit
- SPI - Serial Peripheral Interface
- UART - Universal Asynchronous Receiver/Transmitter.
This API uses board pin names as defined in the corresponding board documentation.
The names, values and semantics related to hardware pins are owned and encapsulated by the implementation. This API uses opaque values (strings and numbers) for Pin
names.
The supported board documentations are listed in this directory:
The full Web IDL definition for Board and IO APIs can be found here.
The API entry point is a Board
object that is exposed in a platform-specific manner. As an example, on Node.js it can be obtained by requiring the package that implements this API.
In the following example, the application requires an implementation that exposed Arduino 101 values and semantics for pins.
var board = require("board");
console.log("Connected to board: " + board.name);
On other platforms, e.g. in browsers, the API entry point can be exposed on another object, or constructed.
var board = new Board(); // provides an instance of the default board
If the functionality is not supported by the platform, require
should throw NotSupportedError
. If there is no permission for using the functionality, require
should throw SecurityError
.
Represents a hardware pin on the board.
Property | Type | Optional | Default value | Represents |
---|---|---|---|---|
pin |
String or Number | no | undefined |
board name for the pin |
The read-only pin
property is the board-specific name or numeric value of a pin, as defined in the board documentation.
In future versions of the API the Pin
object may be extended.
Represents a hardware board.
Property | Type | Optional | Default value | Represents |
---|---|---|---|---|
name |
String | no | undefined |
board name |
version |
String | no | versions.board in package.json |
API version |
Method signature | Description |
---|---|
aio() |
request an AIO object |
gpio() |
request a GPIO object |
pwm() |
request a PWM object |
i2c() |
request an I2C object |
spi() |
request an SPI object |
uart() |
request an UART object |
Event name | Event callback argument |
---|---|
error |
Error object |
The name
property is read-only, and provides the board name.
The version
property is read-only, and provides the provides the Board API version, as specified in the versions.board
property of package.json
.
Board errors are represented as augmented Error
objects. The following Error
names are used for signaling issues:
BoardDisconnectError
BoardTimeoutError
BoardIOError
.
Configures an AIO pin. The method runs the following steps:
- Return a
Promise
objectpromise
and continue in parallel. - If the AIO functionality is not supported, reject
promise
with"NotSupportedError"
. - Run the internal
AIO initialization
algorithm withoptions
as argument and letaio
be the returned result. - If it throws an error, reject promise with that error.
- Resolve
promise
with theaio
object.
Configures a GPIO pin or GPIO port. The method runs the following steps:
- Return a
Promise
objectpromise
and continue in parallel. - If the GPIO functionality is not supported, reject
promise
with"NotSupportedError"
. - Run the internal
GPIO initialization
algorithm withoptions
as argument and letgpio
be the returned result. - If it throws an error, reject promise with that error.
- Resolve
promise
with thegpio
object.
Configures a PWM pin. The method runs the following steps:
- Return a
Promise
objectpromise
and continue in parallel. - If the PWM functionality is not supported, reject
promise
with"NotSupportedError"
. - Run the internal
PWM initialization
algorithm withoptions
as argument and letpwm
be the returned result. - If it throws an error, reject promise with that error.
- Resolve
promise
with thepwm
object.
Configures I2C communication. The method runs the following steps:
- Return a
Promise
objectpromise
and continue in parallel. - If the I2C functionality is not supported, reject
promise
with"NotSupportedError"
. - Run the internal
I2C initialization
algorithm withoptions
as argument and leti2c
be the returned result. - If it throws an error, reject promise with that error.
- Resolve
promise
with thei2c
object.
Configures SPI communication. The method runs the following steps:
- Return a
Promise
objectpromise
and continue in parallel. - If the SPI functionality is not supported, reject
promise
with"NotSupportedError"
. - Run the
SPI init
steps withoptions
as argument and letspi
be the returned result. - If it throws an error, reject promise with that error.
- Resolve
promise
with thespi
object.
Configures UART communication. It takes a dictionary object as argument. The method runs the following steps:
- Return a
Promise
objectpromise
and continue in parallel. - If the UART functionality is not supported, reject
promise
with"NotSupportedError"
. - Run the
UART init
steps withoptions
as argument and letuart
be the returned result. - If it throws an error, reject promise with that error.
- Resolve
promise
with theuart
object.