LIS3DH Hookup Guide

Contributors: MTaylor
Favorited Favorite 1

Extra Examples and Arduino Library Reference

The following examples are included in the Arduino library:

  • ADCUsage - Demonstrates analog in reads and has notes about temperature collection
  • FifoExample - Demonstrates using the built-in buffer to burst-collect data - Good demonstration of settings
  • FullSettingExample - Shows all settings, with non-used options commented out
  • IntUsage - shows configuration of interrupt bits
  • LowLevelExample - Demonstrates using only the core driver without math and settings overhead
  • MinimalistExample - The easiest configuration
  • MultiI2C - Using two LIS3DHs over I2C
  • MultiSPI - Using two LIS3DHs over SPI

Library Usage

Take the following steps to use the library

  • construct an object in the global space with one of these constructions
    • No parameters -- I2C mode at address 0x19
    • I2C_MODE, address
    • SPI_MODE, pin number
  • With in begin, set the .settings. values
  • run .begin()


LIS3DH myIMU; //This creates an instance the library object.

void setup()
    myIMU.settings.adcEnabled = 1;
    myIMU.settings.tempEnabled = 0;
    myIMU.settings.accelSampleRate = 50;  //Hz.  Can be: 0,1,10,25,50,100,200,400,1600,5000 Hz
    myIMU.settings.accelRange = 2;      //Max G force readable.  Can be: 2, 4, 8, 16


The main LIS3DH class has a public member, which is named settings. To configure settings, use the format myIMU.settings.accelSampleRate = (...);. Then, call .begin() to apply.

Settings contains the following members:

  • uint8_t adcEnabled -- Set to 1 to enable ADCs
  • uint8_t tempEnabled -- Set to 1 to override ADC3 with delta temperature information
  • uint16_t accelSampleRate -- Can be: 0,1,10,25,50,100,200,400,1600,5000 Hz
  • uint8_t accelRange -- Max G force readable. Can be: 2, 4, 8, 16
  • uint8_t xAccelEnabled -- Set to 1 to enable x axis
  • uint8_t yAccelEnabled -- Set to 1 to enable y axis
  • uint8_t zAccelEnabled -- Set to 1 to enable z axis
  • uint8_t fifoEnabled -- Set to 1 to enable FIFO
  • uint8_t fifoMode -- Can be 0x0,0x1,0x2,0x3
  • uint8_t fifoThreshold -- Number of bytes read before watermark is detected (0 to 31)


Advanced programmers: The LIS3DH class inherits the LIS3DHCore, which can be used to communicate without all these functions, so you can write your own. This class is not covered in this hookup guide.

uint8_t begin( void );

Call after providing settings to start the wire or SPI library as indicated by construction and runs applySettings(). Returns 0 for success.

void applySettings( void );

This configures the IMU's registers based on the contents of .settings.

int16_t readRawAccelX( void );

int16_t readRawAccelY( void );

int16_t readRawAccelZ( void );

These functions return axis acceleration information as a 16 bit, signed integer.

float readFloatAccelX( void );

float readFloatAccelY( void );

float readFloatAccelZ( void );

These functions call the Raw functions, then apply math to convert to a float expressing acceleration in number of Gs.

uint16_t read10bitADC1( void );

uint16_t read10bitADC2( void );

uint16_t read10bitADC3( void );

These functions return the ADC values read from the pins. Values will be 10 bit and the detectable range is about 0.9V to 1.8V.

Note: When tempEnabled == 1, ADC3 reads as an unreferenced temperature in degrees C. Read twice and calculate the change in temperature.

void fifoBegin( void );

This enables the FIFO by writing the proper values into the FIFO control reg, and control reg 5. This does not start the data collection to the FIFO, run fifoStartRec() when ready.

Sample rate depends on data rate selected in .settings.

void fifoClear( void );

This reads all data until the status says none is available, discarding the data. Use to start with new data if the FIFO fills with old data.

void fifoStartRec( void )

This enables FIFO data collection. Run this before starting to check if data is available.

After fifoStartRec is used, data from the X, Y, Z registers is not real time, but is the next available sample.

uint8_t fifoGetStatus( void )

This returns the FIFO status byte. The contents of the byte are as follows:

  • bit 7: Watermark exceeded
  • bit 6: FIFO has overflowed
  • bit 5: FIFO is empty
  • bit 4 through 0: Number of samples available (0 to 31)

void fifoEnd( void );

This stops the FIFO and returns the device to regular operation.