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
- Raspberry Pi 4B(or similar) x 1
- H3LIS200DL Triple Axis Accelerometer x1
- Jumper wires x1
Software Preparation
- Raspberry Pi Official OS
- Download and install the LIS Series Python Library.
Wiring Diagram
- Connect the module to the Raspberry Pi according to the connection diagram. The default I2C address is 0x19.

Other Preparation Work
- Enable the I2C interface of the Raspberry Pi:
Select "5 Interfacing Options" → "P5 I2C" → "YES", then restart.sudo raspi-config - Install dependencies:
sudo apt-get update sudo apt-get install build-essential python-dev python-smbus git - Download the library:
cd Desktop git clone https://github.com/DFRobot/DFRobot_LIS - 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?
