sudo raspi-config # Enable I2C
ls -l /dev/i2c* || sudo reboot
sudo apt-get install i2c-tools
/usr/sbin/i2cdetect -y 1
#| 0 1 2 3 4 5 6 7 8 9 a b c d e f
#| 00: -- -- -- -- -- -- -- -- -- -- -- -- --
#| 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#| 20: -- -- -- 23 -- -- -- -- -- 29 -- -- -- -- -- --
#| 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#| 40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#| 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#| 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#| 70: -- -- -- -- -- -- -- 77
let BH1750 = require('@abandonware/bh1750');
const options = {
device: '/dev/i2cยญ1', // RPi I2C bus
address: 0x23, // I2C address
command: 0x10, // 1 lx resolution
length: 2
};
let sensor = new BH1750(options);
sensor.readLight((value) => {
console.log(value); // 42
});
var bmp085 = require('@abandonware/bmp085-sensor');
var sensor = bmp085({address: 0x77, mode: 3});
sensor.calibrate(function (err, data) {
// ...
sensor.read(function (err, data) {
console.log(data);
// { pressure: 29.9, temp: 42.0 }
});
});
#include "mbed.h"
#include "FXOS8700Q.h"
I2C i2c(PTE25, PTE24); // K64F's pins for SDA SDC
FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1);
motion_data_units_t v;
acc.enable();
acc.getAxis(v);
printf("X=%f Y=%f Z=%f\n", v.x, v.y, v.z);
// file: example.js
var GenericSensors = require('generic-sensors-lite');
var sensor = new GenericSensors.Geolocation({frequency: 0.42});
sensor.onreading = function() {
console.log("[" + this.latitude + "," + this.longitude + "]");
this.stop();
};
sensor.start()
# Run JS application with Node.js
node example.js
[ 4.20180308, 2.20200923]
var sensor = new ColorSensor({controller: "tcs34725"}) // I2C
sensor.onreading = function () {
console.log('{"color": "' + this.color + '"}') // #badc0d
}
sensor.start()
$ make -C generic-sensors-lite/example/webthing/ start
make runtime=iotjs start
make -C example/webthing runtime=iotjs start
curl -s http://localhost:8888/properties
#| { (...) "illuminance":123., "celsius":42., "color":"#c0a175" (...) }
Created by Philippe Coval