@tibbo-tps/i2c

0.0.3 • Public • Published

Common API for Tibbo's I2C Modules

Methods:

init(socket, address)

  • line - TPP socket number, e.g. S13
  • address - i2c address of the Tibbit module, e.g. 0x53 for Tibbit #36 (Accelerometer)

Returns an object with the following methods:

.read(register, bytes)

  • register - I2C register, e.g. 0x32
  • bytes - bytes to read

Returns buffer.

.write(register, value)

  • register - I2C register, e.g. 0x08
  • value - value to write, e.g. 0x80

Example: configure and get data from Tibbit #36 (Accelerometer):

const ADXL312 = {
    I2C_ADDRESS : 0x53,
    POWER_CTL : 0x2D,

    BW_RATE : 0x2C,

    DATA_FORMAT : 0x31,

    FULL_RES_1_5G : 0x08,
    FULL_RES_3G : 0x09,
    FULL_RES_6G : 0x0A,
    FULL_RES_12G : 0x0B,

    FIFO_CTL : 0x38,
    BYPASS_MODE : 0x80,

    DATA_X0 : 0x32,
    DATA_Y0 : 0x34,
    DATA_Z0 : 0x36,
    INT_ENABLE : 0x2E,
}

var i2c = require("./i2c.js");
var acc = i2c.init("s15", ADXL312.I2C_ADDRESS)

acc.write(ADXL312.DATA_FORMAT, ADXL312.FULL_RES_1_5G);
acc.write(ADXL312.BW_RATE, 0x0A);
acc.write(ADXL312.POWER_CTL, 0x08);
acc.write(ADXL312.INT_ENABLE, 0x80);
acc.write(ADXL312.FIFO_CTL, ADXL312.BYPASS_MODE);

setInterval(function(){
    var x = acc.read(ADXL312.DATA_X0, 2).readInt16LE()*2.9;
    var y = acc.read(ADXL312.DATA_Y0, 2).readInt16LE()*2.9;
    var z = acc.read(ADXL312.DATA_Z0, 2).readInt16LE()*2.9;
    console.log(x,y,z)
},1000)

Readme

Keywords

none

Package Sidebar

Install

npm i @tibbo-tps/i2c

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

54.5 kB

Total Files

5

Last publish

Collaborators

  • tibbo-tps