Example Code for Raspberry Pi – Read the x, y, z data of accelerometer
This tutorial shows how to read the accelerometer’s x, y, and z-axis data from the ICG-20660L on a Raspberry Pi in real time.
Hardware Preparation
- Raspberry Pi 4B (or similar) × 1
- 6-Axis IMU Sensor × 1
- Jumper wires
Software Preparation
-
Install the Raspberry Pi OS
Download from the official website:
Raspberry Pi Official OS -
Download the ICG-20660L Python library
GitHub repository:
DFRobot_ICG20660L -
Ensure Python and required dependencies are installed (included in steps below).
-
Open the demo_get_accel_data.py example file from the downloaded library.
Wiring Diagram
Connect the module to the Raspberry Pi according to the wiring diagram.
The default I²C address of the sensor is 0x69.

Driver Installation
- Enable the I2C interface of the Raspberry Pi. If it is already enabled, you can skip this step. Open Terminal, type the following command, and press Enter:
sudo raspi-config
Then use the up and down keys to select "5 Interfacing Options", press Enter, select "P5 I2C", and press Enter to confirm "YES". Restart the Raspberry Pi main control board.
- To install Python dependent libraries and git, the Raspberry Pi needs to be connected to the Internet. If it is already installed, you can skip this step. In the terminal, type the following commands in sequence, and press Enter:
sudo apt-get update
sudo apt-get install build-essential python-dev python-smbus git
- Download the LIS series driver library. In the terminal, type the following commands in sequence and press Enter:
cd Desktop
git clone https://github.com/DFRobot/DFRobot_ICG20660L
Sample Code
- In the terminal, type the following command and press Enter, run the sample code:
cd DFRobot_ICG20660L/Python/raspberrypi/examples
python demo_get_accel_data.py
Result:
Shake the sensor and see the result.

Was this article helpful?
