Home CodeCircuitpython Raspberry Pi Pico and ADXL345 3-axis accelerometer circuitpython example

Raspberry Pi Pico and ADXL345 3-axis accelerometer circuitpython example

by rp2040guy71

In this article we connect a ADXL345 3-axis accelerometer to a Raspberry Pi Pico running Circuitpython

Sensor Information

The ADXL345 is a small, thin, ultralow power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16 g. Digital output data is formatted as 16-bit twos complement and is accessible through either a SPI (3- or 4-wire) or I2C digital interface.

The ADXL345 is well suited for mobile device applications. It measures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock. Its high resolution (3.9 mg/LSB) enables measurement of inclination changes less than 1.0°.

Several special sensing functions are provided. Activity and inactivity sensing detect the presence or lack of motion by comparing the acceleration on any axis with user-set thresholds.

Tap sensing detects single and double taps in any direction. Freefall sensing detects if the device is falling. These functions can be mapped individually to either of two interrupt output pins.

An integrated memory management system with a 32-level first in, first out (FIFO) buffer can be used to store data to minimize host processor activity and lower overall system power consumption.

Low power modes enable intelligent motion-based power management with threshold sensing and active acceleration measurement at extremely low power dissipation.


  • Ultralow power: as low as 23 µA in measurement mode and
  • 0.1 µA in standby mode at VS = 2.5 V (typical)
  • Power consumption scales automatically with bandwidth
  • User-selectable resolution
  • Fixed 10-bit resolution
  • Full resolution, where resolution increases with g range, up to 13-bit resolution at ±16 g (maintaining 4 mg/LSB scale factor in all g ranges)
  • Embedded memory management system with FIFO technology minimizes host processor load
  • Single tap/double tap detection
  • Activity/inactivity monitoring
  • Free-fall detection
  • Supply voltage range: 2.0 V to 3.6 V
  • SPI (3- and 4-wire) and I2C digital interfaces
  • Flexible interrupt modes mappable to either interrupt pin
  • Measurement ranges selectable via serial command
  • Bandwidth selectable via serial command
  • Wide temperature range (−40°C to +85°C)
  • 10,000 g shock survival

Parts Required


Name Link
Pico Raspberry Pi Pico Development Board
ADXL345 ADXL345 digital three-axis acceleration of gravity tilt module
Connecting cables Aliexpress link

Amazon.com link

Ebay link



Black for GND
Red for V+
Blue for SDA
Yellow for SCL

So color coded for ease of use, this layout shows a connection to the module

rp2040 and adxl345

rp2040 and adxl345

Code Example

I used Thonny for development

The following is based on a library , I copied the adafruit_adxl34x.mpy library for this device to the lib folder on my Raspberry Pi Pico – https://circuitpython.org/libraries

[codesyntax lang=”python”]

import time
import board
import busio
import adafruit_adxl34x

# Create sensor object, using the board's default I2C bus.
i2c = busio.I2C(board.GP1, board.GP0)  # SCL, SDA
accelerometer = adafruit_adxl34x.ADXL345(i2c)

while True:
    print("%f %f %f" % accelerometer.acceleration)



Here is what I saw in Thonny REPL window

-0.039227 -4.354151 -7.923771
7.962996 -1.412157 -6.982332
5.648628 2.981221 -8.590622
-3.491166 -7.649185 -6.746973
2.863541 -8.590622 -7.021559
6.668518 0.627625 -5.217136



You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More