0

When I execute i2c.read(7) the result gets stored as a string. If I am not mistaken I thought var d = i2c.read(7) should get stored as an object? I am still unclear about what the mraa Javasript i2c API is. Does the i2c.read() supposed to store the result as an object or string? If object, then what am I not doing correctly?

The console.log outputs:
JSON.stringify: "\u00012.974\u0000"
typeof: string
Result: 2.974

Code:

var m = require('mraa');
var i2c = new m.I2c(1);
i2c.address(0x63);

i2c.write("R");
console.log("Reading I2C..");

function readPH() {
  var d = i2c.read(7);
  console.log("JSON.stringify: " + JSON.stringify(d));
  console.log("typeof: " + typeof d);
  console.log("Result: " + d);
}

setTimeout(function (e) { readPH(); }, 1000);
0andriy
  • 4,183
  • 1
  • 24
  • 37
dottedquad
  • 1,371
  • 6
  • 24
  • 55

1 Answers1

0

Recent versions of mraa (0.5.4+) will store the result of i2c.read() as a node_buffer object. It's possible you're on an old version which used to return strings, check with the getVersion() call.