LIS2DH12 Accelerometer
The LIS2DH12 is an ultra-low-power high-performance three-axis linear accelerometer with a digital I2C/SPI serial interface.
You can use the LIS2DH12 (About Modules) module with the LIS2DH12 as follows:
SPI
SPI1.setup({miso:..., mosi:..., sck:...);
var accel = require("LIS2DH12").connectSPI(SPI1, CS_PIN, {callback:function(xyz) {
// callback whenever data is received
console.log(xyz);
// prints { "x": 3.90625, "y": -7.8125, "z": 984.375 }
}});
accel.setPowerMode(on?"low":"powerdown");
I2C
I2C1.setup({sda:..., scl:...);
var accel = require("LIS2DH12").connectI2C(I2C1, {callback:function(xyz) {
// callback whenever data is received
console.log(xyz);
// prints { "x": 3.90625, "y": -7.8125, "z": 984.375 }
}});
accel.setPowerMode(on?"low":"powerdown");
Note: you can supply addr
to connectI2C
's second argument to set an I2C
address if it is non-standard.
Reference
/* Set the power state of the accelerometer.
Either :
"normal" - 100Hz
"low" - 1Hz
"fast" - 1000Hz
"highres" - 1000Hz
"powerdown" - Off
*/
LIS2DH12.prototype.setPowerMode = function (mode) { ... }
/* Get the last read accelerometer readings as
an object with {x,y,z,new} elements. new is false if the data hasn't changed since the last read
*/
LIS2DH12.prototype.getXYZ = function () { ... }
/* Call the callback with an accelerometer reading {x,y,z}. If the accelerometer is powered off,
power it on, take a reading, and power it off again
*/
LIS2DH12.prototype.readXYZ = function (callback) { ... }
/* Initialise the LIS2DH12 module with the given SPI interface and CS pins.
See 'LIS2DH12' above for options
*/
exports.connectSPI = function (spi, cs, options) { ... }
/* Initialise the LIS2DH12 module with the given I2C interface (and optional address with connectI2C(i2c,{addr:...}) )
See 'LIS2DH12' above for more options
*/
exports.connectI2C = function (i2c, options) { ... }
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.