The following shows i2c module APIs available for each platform.
Linux (Ubuntu) |
Raspbian (Raspberry Pi) |
Nuttx (STM32F4-Discovery) |
|
---|---|---|---|
i2c.scan | O | O | X |
i2c.write | O | O | X |
i2c.writeByte | O | O | X |
i2c.writeBytes | O | O | X |
i2c.read | O | O | X |
i2c.readByte | O | O | X |
i2c.readBytes | O | O | X |
i2c.stream | O | O | X |
address: Number (Default value is 0x23)
options: Object
options
is an object specifying following information:
device: String (Default value is /dev/i2c-1)
Create I2C object. Following methods can be called with I2C object.
For example,
var i2c = require('i2c');
var wire = new i2c(0x23, {device: '/dev/i2c-1'});
wire.scan(function(err, data) {
// Do something.
});
callback: Function(data)
data
is an object specifying following information:
address: Number
data: Array (an array of bytes)
cmd: Number
length: Number
timestamp: Number
Emitted when stream
method is called.
For example,
...
wire.on('data', function(data) {
console.log('data.timestamp: ' + data.timestamp);
console.log('data.address: ' + data.address);
console.log('data.cmd: ' + data.cmd);
console.log('data.length: ' + data.length);
console.log('data.data: ' + data.data);
});
wire.stream(0x20, 2, 1000);
length: Number
callback: Function(err, res)
Read bytes from I2C device.
length
is the number of bytes. res
contains an array of bytes.
callback: Function(err, res)
Read one byte from I2C device. res
contains result as a number.
command: Number
length: Number
callback: Function(err, res)
Read bytes from I2C device with command.
length
is the number of bytes. res
contains an array of bytes.
callback: Function(err, data)
Scan I2C device. data
contains an array of addresses.
command: Number
length: Number
delay: Number
Read bytes from I2C device with command, continuously. It emits data
event.
length
is the number of bytes. It will pause for the amount of time(delay
in ms).
bytes: Array
callback: Function(err)
Write bytes to I2C device. bytes
is an array of numbers.
byte: Number
callback: Function(err)
Write one byte to I2C device.
command: Number
bytes: Array
callback: Function(err)
Write bytes to I2C device with command. bytes
is an array of numbers.