Skip to content

TeamSunride/Arduino-LSM6DSO32

Repository files navigation

Arduino-LSM6DSO32

An Arduino / PlatformIO library for the LSM6DSO32 inertial module.

Image credit: Adafruit

Developed by Sam Scott

Namespace

The class and it's registers are scoped within the LSM6DSO32 namespace.

E.g LSM6DSO32::REGISTER::FIFO_CTRL1, LSM6DSO32::BATCHING_DATA_RATES::BDR_6667Hz

Usage

Use the appropriate constructor for your configuration: (see protocol)

  • SPI constructor: (recommended)
#define CS_pin 10 // e.g.
LSM6DSO32::LSM6DSO32 LSM(CS_pin, SPI, 4000000);
  • I2C constructor:
LSM6DSO32::LSM6DSO32 LSM(&Wire, 1000000);

Wiring guide:

graph TD;
    mcu[MCU] -- SCK  ---LSM6DSO32[LSM6DSO32];
    mcu-- MOSI  ---LSM6DSO32[LSM6DSO32]
    mcu-- MISO  ---LSM6DSO32[LSM6DSO32]
    mcu-- CS  ---LSM6DSO32[LSM6DSO32] 
    
    mcu2[MCU] -- SCL  ---LSM6DSO32_2[LSM6DSO32];
    mcu2 -- SDA  ---LSM6DSO32_2[LSM6DSO32]
Loading

With the correct configuration (see default_configuration()) calling fifo_pop will pop from the LSM FIFO into the acceleration and gyroscope FIFOs. Note that ACC FIFO and GYRO FIFO are FIFOs of type Vector<double, 4>, so they are FIFOs of Vectors.

graph TD;
    rawData[Raw Sensor Data]-- Continuously Streaming ---lsmFifo[LSM FIFO];
    lsmFifo--> accFifo[ACC Fifo] & gyroFifo[GYRO Fifo]
   
Loading

Compression

This library correctly implements the built-in compression algorithm in the LSM6DSO32 FIFO.

The compression algorithm onboard the LSM6DSO32 analyses the data and when possible, batches the data in the FIFO in a more compact data format, allowing for the 3 kbyte FIFO to have an effective capacity of over 9 kbyte. See the datasheet and application note for more details

The output when using compression is identical to the uncompressed data stream, which means the library correctly decompresses the data:

Filters

The LSM6DSO32 has a number of built-in digital and analogue filters that can be very useful when attempting to eliminate noise.

The default_configuration() has a fairly good filter setup, but for specific applications/ other configurations, refer to these diagrams and the datasheet or application note:

Accelerometer Filters

Gyroscope Filters

Examples

The examples folder contains some examples of how the LSM6DSO32 can be used.

To run an example in platformio, run (in library root):

pio ci ".\examples\direct_read.cpp" -l "." -l "lib/Protocol" -l "lib/Vector" -l "lib/Fifo" -c "platformio.ini"

Unit testing

In the tests folder, there are some tests that run with unity and platformio

Run the unit tests using pio test: