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 | 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
.
Provides the AIO API object. The method runs the following steps:
- If the AIO functionality is not supported on the board, throw
"NotSupportedError"
. - Initialize AIO functionality on the board. If it fails, throw
"SystemError"
. - Let
aio
be the AIO API object. Returnaio
.
Provides the GPIO API object. The method runs the following steps:
- If the GPIO functionality is not supported on the board, throw
"NotSupportedError"
. - Initialize GPIO functionality on the board. If it fails, throw
"SystemError"
. - Let
gpio
be the GPIO API object. Returngpio
.
Provides the PWM API object. The method runs the following steps:
- If the PWM functionality is not supported on the board, throw
"NotSupportedError"
. - Initialize PWM functionality on the board. If it fails, throw
"SystemError"
. - Let
pwm
be the [PWM API object](./pwm.md/#apiobject). Return
pwm`.
Provides the I2C API object. The method runs the following steps:
- If the I2C functionality is not supported on the board, throw
"NotSupportedError"
. - Initialize I2C functionality on the board. If it fails, throw
"SystemError"
. - Let
i2c
be the I2C API Object. Returnpwm
.
Provides the SPI API object. The method runs the following steps:
- If the SPI functionality is not supported on the board, throw
"NotSupportedError"
. - Initialize SPI functionality on the board. If it fails, throw
"SystemError"
. - Let
spi
be the SPI API object. Returnspi
.
Provides the UART API object. The method runs the following steps:
- If the UART functionality is not supported on the board, throw
"NotSupportedError"
. - Initialize UART functionality on the board. If it fails, throw
"SystemError"
. - Let
uart
be the UART API object object. Returnuart
.