Example Code for Raspberry Pi-Read Acceleration

Last revision 2025/12/17

This guide offers step-by-step instructions on how to set up and read acceleration data using a Raspberry Pi and a H3LIS200DL triple axis accelerometer, including hardware and software preparation, wiring, and executing example code.

Hardware Preparation

Software Preparation

Wiring Diagram

  • Connect the module to the Raspberry Pi according to the connection diagram. The default I2C address is 0x19.

Other Preparation Work

  1. Enable the I2C interface of the Raspberry Pi:
    sudo raspi-config
    
    Select "5 Interfacing Options" → "P5 I2C" → "YES", then restart.
  2. Install dependencies:
    sudo apt-get update
    sudo apt-get install build-essential python-dev python-smbus git
    
  3. Download the library:
    cd Desktop
    git clone https://github.com/DFRobot/DFRobot_LIS
    
  4. Navigate to the sample code directory:
    cd DFRobot_LIS/python/raspberrypi/examples/H3LIS200DL/get_acceleration
    

Sample Code

Run the sample code:

python get_acceleration.py

Result

Shake the sensor, and the acceleration values in x, y, z directions will be printed on the terminal.

If you see an error about I2C address, check if the I2C address is set correctly (0x18 or 0x19) via the toggle switch.

Was this article helpful?

TOP