ShadowNode

Use Node.js in your end devices(QQ: 796448809)

View the Project on GitHub yodaos-project/ShadowNode

Platform Support

The following shows I2C module APIs available for each platform.

  Linux
(Ubuntu)
Raspbian
(Raspberry Pi)
NuttX
(STM32F4-Discovery)
TizenRT
(Artik053)
i2c.open O O O O
i2cbus.read O O O O
i2cbus.write O O O O
i2cbus.close O O O O

I2C

The I2C class supports the I2C protocol. I2C bus has two signals - SDA and SCL.

new I2C()

Returns with an I2C object.

Example

var I2C = require('i2c');

var i2c = new I2C();

i2c.open(configuration[, callback])

Get I2CBus object with configuration.

Example

var I2C = require('i2c');

var i2c = new I2C();
var i2c_bus = i2c.open({device: '/dev/i2c-1', address: 0x23}, function(err) {
  if (err) {
    throw err;
  }
});

Class: I2CBus

i2cbus.read(length[, callback])

Read bytes from I2C device.

Example

var I2C = require('i2c');

var i2c = new I2C();
var i2c_bus = i2c.open({device: '/dev/i2c-1', address: 0x23});

i2c_bus.read(2, function(err, res) {
  if (!err) {
    console.log('read result: ' + res);
  }
});

i2cbus.write(bytes[, callback])

Write bytes to I2C device.

Example

var I2C = require('i2c');

var i2c = new I2C();
var i2c_bus = i2c.open({device: '/dev/i2c-1', address: 0x23});

i2c_bus.write([0x10], function(err) {
  if(!err) {
    console.log('write done');
  }
});

i2cbus.close()

Close I2C device.

Example

var I2C = require('i2c');

var i2c = new I2C();
var i2c_bus = i2c.open({device: '/dev/i2c-1', address: 0x23});

i2c_bus.close();