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);