javascript - Tessel 2 - i2c.read not logging buffer -


i'm attempting use tessel 2 read data co2 sensor not having success.

from sensor's data sheet:

to read current co2 concentration sensor need read memory locations 0x08 (hi byte) , 0x09 (low byte).

to need send sequence of 2 i2c frames: first send i2c write frame containing sensor address, command number , how many bytes read, ram address read from, , checksum. send i2c read frame read status, data , checksum.

in our case want read 2 bytes starting address 0x08. give data address 0x08 , 0x09, contains current co2 reading. sensor address 0x68 (default factory setting, configurable in eeprom).

so, first frame should like:

start | 0xd0 | 0x22 | 0x00 | 0x08 | 0x2a | stop

--a. 0xd0 sensor address , read/write bit. 0x68 shifted 1 bit left , r/w bit 0 (write).

--b. 0x22 command number 2(readram), , 2 bytes read

--c. checksum 0x2a calculated sum of byte 2, 3 , 4.

the next frame read actual data:

start | 0xd1 | <4 bytes read sensor> | stop

--d. 1:st byte sensor contain operation status, bit 0 tells if read command executed.

--e. 2:nd , 3:rd byte contain co2 value hi byte , co2 value low byte.

--f. 4:th byte contains checksum

so, code looks this:

'use strict';  // require var async   = require('async'); var tessel  = require('tessel'); var port    = tessel.port.b;  // vars var i2c;  // process async.waterfall([   function(callback) {     i2c = new port.i2c(0xd0);     callback(null,new buffer([0xd0, 0x22, 0x00, 0x08, 0x2a]));   },   function(data, callback) {     i2c.send(data, function (error) {         console.log("done sending data");         callback(null,null);     })   },   function(data, callback) {     i2c = new port.i2c(0xd1);     callback(null,null);   } ], function (err, result) {     i2c.read(4, function (error, buffer) {         console.log(`i2c slave (0x${address.tostring(16)} response: `, buffer);     });     }); 

the code executes way until i2c.read code block , never receives buffer sensor.

i decided not use transfer method because address changes.

what doing wrong?

i cheated little bit looking @ arduino sketch gave me ideas panned out.

  1. i2c should instantiated using proper address (0x68), not shifted in docs provided in datasheet
  2. the buffer i2c.send should not include address i2c has address added in frame on instantiation. buffer should this:

    callback(null,new buffer([0x22, 0x00, 0x08, 0x2a]));

  3. add timeout between sending reading of 1000ms


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -