lsm6ds
v1.0.1
Published
An I2C driver for the LSM6DS accelerometer and gyroscope sensor family.
Downloads
183
Maintainers
Readme
A nodeJS I2C driver for the ST LSM6DS family of IMUs
This library uses the i2c-bus nodeJS package to communicate with the chip over I2C.
Supported modules
I only have the need for the ISM330DHCX, hence it's the only one both supported and tested. If you have any of the untested sensors then feel free to test them and submit a PR if they work correctly.
| Variant | Supported | Tested | |---------|-------------|-------------:| | ISM330DHCX | :white_check_mark: | :white_check_mark: | | LSM6DS3TR-C | :white_check_mark: | :x: | | LSM6DS33 | :white_check_mark: | :x: | | LSM6DS3 | :white_check_mark: | :x: | | LSM6DSO32 | :white_check_mark: | :x: | | LSM6DSOX | :white_check_mark: | :x: |
Supported functionality
- Reading accelerometer and gyroscope data
- Accelerometer and gyroscope range and rate configuration
- Accelerometer high-pass filter configuration
- FIFO batching support for accel and gyro data
Installation
npm install lsm6dsExamples
Reading a single value at a time. Reading gyroscope data works identically.
const { ISM330DHCX } = require('lsm6ds');
(async () => {
const sensor = new ISM330DHCX();
try {
await sensor.init({ accelRate: sensor.Rate.RATE_26_HZ });
while (true) {
const data = await sensor.readAccelerometer();
console.log(`Accel: X=${data.x.toFixed(3)}g Y=${data.y.toFixed(3)}g Z=${data.z.toFixed(3)}g`);
await new Promise((r) => setTimeout(r, 100));
}
} catch (err) {
console.error('sensor init error', err);
process.exit(1);
}
})();You can use the FIFO buffer to avoid the I2C overhead that comes from reading a single value at a time. For example, at 6.66kHz you can read ~200 samples every ~10ms instead of reading 1 sample every ~0.15ms. This means that even on non-realtime systems such as the Raspberry Pi you can utilize the full datarate, instead of skipping some readings due to timing issues. Fast-Mode Plus I2C mode is of course also required.
const { ISM330DHCX } = require('lsm6ds');
(async () => {
const sensor = new ISM330DHCX();
try {
await sensor.init({ accelRate: sensor.Rate.RATE_6_66K_HZ });
await sensor.setFIFOMode(sensor.FIFOModes.CONTINUOUS);
await sensor.setAccelFIFOBatchRate(sensor.Rate.RATE_6_66K_HZ);
while (true) {
const data = await sensor.readFIFOData(await sensor.getFIFOSampleCount());
console.log(`Got ${data.accel.length} samples`);
await new Promise((r) => setTimeout(r, 10));
}
} catch (err) {
console.error('sensor init error', err);
process.exit(1);
}
})();