Quantcast
Channel: Intel Communities: Message List
Viewing all articles
Browse latest Browse all 18548

I need help with NodeJS i2c.read()

$
0
0

So far I believe I have my ph sensor hooked up properly to i2c pins A4 and A5.  My code is as follows:

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

i2c.address(0x63);
i2c.write("R,56.26");

console.log("Reading I2C..");

function readPH() {
    var data = i2c.read();    console.log( ">> I2C value: " + data);
}
setTimeout(function (e) { readPH(); }, 1000);

The code is pretty much straight forward.  I send the command R,56.26 to the ph sensor, wait 1 second and then execute i2c.read().

 

The datasheet of the ph sensor explains:

i2c.png

I used a setTimeout at 1sec to allow enough time for the ph sensor to calculate the value.  After 1second is up readPH() function executes.  i2c.read() does read data; however, when I output the data value I only receive a 1 as the output. How do I read the complete 7 byte string?


Viewing all articles
Browse latest Browse all 18548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>