Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
LSM6DS3TR-C
LSM6DS33
LSM6DS3
LSM6DSO32
LSM6DSOX

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 lsm6ds

Examples

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);
  }
})();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages