I was able to finally get my first sample running with groovepi, lcd display and dht sensor
It runs fine, but I have no idea how to interpret the results, all I need is temp in celsius degrees and the humidity
var i2c = require(‘i2c-bus’)
var sleep = require(‘sleep’)
var GrovePi = require(‘node-grovepi’).GrovePi
var DHTDigitalSensor = GrovePi.sensors.DHTDigital
var Board = GrovePi.board
var DISPLAY_RGB_ADDR = 0x62;
var DISPLAY_TEXT_ADDR = 0x3e;
function setRGB(i2c1, r, g, b) {
i2c1.writeByteSync(DISPLAY_RGB_ADDR,0,0)
i2c1.writeByteSync(DISPLAY_RGB_ADDR,1,0)
i2c1.writeByteSync(DISPLAY_RGB_ADDR,0x08,0xaa)
i2c1.writeByteSync(DISPLAY_RGB_ADDR,4,r)
i2c1.writeByteSync(DISPLAY_RGB_ADDR,3,g)
i2c1.writeByteSync(DISPLAY_RGB_ADDR,2,b)
}
function textCommand(i2c1, cmd) {
i2c1.writeByteSync(DISPLAY_TEXT_ADDR, 0x80, cmd);
}
function setText(i2c1, text) {
textCommand(i2c1, 0x01) // clear display
sleep.usleep(50000);
textCommand(i2c1, 0x08 | 0x04) // display on, no cursor
textCommand(i2c1, 0x28) // 2 lines
sleep.usleep(50000);
var count = 0;
var row = 0;
for(var i = 0, len = text.length; i < len; i++) {
if(text[i] === ‘\n’ || count === 16) {
count = 0;
row ++;
if(row === 2)
break;
textCommand(i2c1, 0xc0)
if(text[i] === ‘\n’)
continue;
}
count++;
i2c1.writeByteSync(DISPLAY_TEXT_ADDR, 0x40, text[i].charCodeAt(0));
}
}
var board = new Board({
debug: true,
onError: function(err) {
console.log(‘Something wrong just happened’)
console.log(err)
},
onInit: function(res) {
if (res) {
console.log('GrovePi Version :: ’ + board.version())
var dhtSensor = new DHTDigitalSensor(3, DHTDigitalSensor.VERSION.DHT21, DHTDigitalSensor.CELSIUS)
// DHT Sensor
console.log('DHT Digital Sensor (start watch)')
dhtSensor.on('change', function(res) {
console.log(res);
var i2c1 = i2c.openSync(1);
setText(i2c1, 'fymgthdpmpmystfotrsh!!');
setRGB(i2c1, 52, 55, 5);
i2c1.closeSync();
})
dhtSensor.watch(500) // milliseconds
}
}
})
board.init();
end result
info GrovePi.board GrovePi is initing
GrovePi Version :: 1.2.2
DHT Digital Sensor (start watch)
[ 5.104235503814077e+38, -2, -4.36284253365733e+75 ]
[ 5.104235503814077e+38, -2, -4.36284253365733e+75 ]