# ADXL345 Digital Accelerometer

## Overview

Filling out Adafruit's accelerometer offerings, we now have the really lovely digital ADXL345 from Analog Devices, a triple-axis accelerometer with digital I2C and SPI interface breakout. We added an on-board 3.3V regulator and logic-level shifting circuitry, making it a perfect choice for interfacing with any 3V or 5V microcontroller such as the Arduino.

![](https://cdn-learn.adafruit.com/assets/assets/000/110/581/medium800/adafruit_products_51959389602_87abe42807_c.jpg?1649188939)

The sensor has three axes of measurements, X Y Z, and pins that can be used either as I2C or SPI digital interfacing. You can set the sensitivity level to either +-2g, +-4g, +-8g or +-16g. The lower range gives more resolution for slow movements, the higher range is good for high speed tracking. The ADXL345 is the latest and greatest from Analog Devices, known for their exceptional quality MEMS devices.

![](https://cdn-learn.adafruit.com/assets/assets/000/110/582/medium800/adafruit_products_51960959355_ddd72bfc9f_c.jpg?1649188955)

We added an on-board 3.3V regulator and logic-level shifting circuitry, making it a perfect choice for interfacing with any 3V or 5V microcontroller or computer, such as Arduino or Raspberry Pi.

There are both [Arduino (C/C++)&nbsp;](https://learn.adafruit.com/adxl345-digital-accelerometer)and&nbsp;[CircuitPython (Python 3) libraries](https://learn.adafruit.com/adxl345-digital-accelerometer/python-and-circuitpython) available, so you can use it with any microcontroller like [Arduino, ESP8266, Metro, etc.](https://learn.adafruit.com/adxl343-breakout-learning-guide/arduino)&nbsp;or with&nbsp;[Raspberry Pi or other Linux computers](https://learn.adafruit.com/adxl343-breakout-learning-guide/circuitpython)&nbsp;thanks to Blinka (our CircuitPython library support helper).

![](https://cdn-learn.adafruit.com/assets/assets/000/110/583/medium800/adafruit_products_51960452788_03767d297d_c.jpg?1649188971)

As if that weren't enough, we've also added [SparkFun qwiic](https://www.sparkfun.com/qwiic)&nbsp;compatible&nbsp;**[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt)**&nbsp;connectors for the I2C bus&nbsp; **so you don't even need to solder.** &nbsp;Just wire up to your favorite micro with a plug-and-play cable to get accelerometer data ASAP. For a no-solder experience,&nbsp;[just wire up to your favorite micro](https://www.adafruit.com/category/621)&nbsp;using a&nbsp;[STEMMA QT adapter cable.](https://www.adafruit.com/?q=stemma%20qt%20cable)&nbsp;

The Stemma QT connectors also mean the ADXL can be used with our&nbsp;[various associated accessories.](https://www.adafruit.com/?q=JST%20SH%204) A&nbsp;[QT cable is not included, but we have a variety in the shop](https://www.adafruit.com/?q=stemma+qt+cable&sort=BestMatch)

![](https://cdn-learn.adafruit.com/assets/assets/000/110/584/medium800/adafruit_products_51960959370_a46e417257_c.jpg?1649188990)

Each order comes with a fully tested and assembled breakout and some header for soldering to a PCB or breadboard. Comes with 0.1" standard header in case you want to use it with a breadboard or perfboard. Four 2.5mm (0.1") mounting holes for easy attachment. You'll be up and running in under 5 minutes

The ADXL345 is a low-power, 3-axis MEMS accelerometer modules with both I2C and SPI interfaces. The Adafruit Breakout boards for these modules feature on-board 3.3v voltage regulation and level shifting which makes them simple to interface with 5v microcontrollers such as the Arduino.  
  
The ADXL345 features 4 sensitivity ranges from +/- 2G to +/- 16G. And it supports output data rates ranging from 10Hz to 3200Hz.  
  
[ADXL345 datasheet](http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf)

## How it Works

### MEMS - Micro Electro-Mechanical Systems

The sensor consists of a micro-machined structure on a silicon wafer. The structure is suspended by polysilicon springs which allow it to deflect smoothly in any direction when subject to acceleration in the X, Y and/or Z axis.

Deflection causes a change in capacitance between fixed plates and plates attached to the suspended structure. This change in capacitance on each axis is converted to an output voltage proportional to the acceleration on that axis.

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/006/359/medium800/adafruit_products_2013_03_24_IMG_1453-1024.jpg?1396835278)

# ADXL345 Digital Accelerometer

## Pinouts

The ADXL345 breakout has the following pinout:

![](https://cdn-learn.adafruit.com/assets/assets/000/110/158/medium800/adafruit_products_cropped1231-06.png?1648220125)

![](https://cdn-learn.adafruit.com/assets/assets/000/110/203/medium800/adafruit_products_image.jpg?1648227281)

The default I2C address for this board is&nbsp; **0x53**.

## Power Pins

This breakout board can be run on&nbsp; **3.3V** and&nbsp; **5V** systems. We added an on-board 3.3V regulator and logic-level shifting circuitry, making it a perfect choice for interfacing with any 3V or 5V microcontroller such as the Arduino.

- **VIN** - This is the input to the 3.3V voltage regulator, which makes it possible to use the 3.3V sensor on 5V systems. It also determines the logic level of the SCL and SDA pins. Connect this to&nbsp; **3.3V** on the MCU for 3.3V boards (Adafruit Feathers), or&nbsp; **5.0V** for 5V Arduinos (Arduino Uno, etc.).
- **3Vo** &nbsp;- This is the&nbsp; **OUTPUT** of the 3.3V regulator, and can be used to provide 3.3V power to other parts of your project if required (\< 100mA).
- **GND** - Connect this to the&nbsp; **GND** pin on your development board to make sure they are sharing a common GND connection, or the electrons won't have anywhere to flow!

## I2C Pins

- **SCL** &nbsp;- The clock line on the I2C bus. This pin has an internal pullup resistor on the PCB, which is required as part of the I2C spec, meaning you don't need to add one externally yourself. This also functions as&nbsp; **SCK** &nbsp;in SPI mode.
- **SDA** &nbsp;- The data line on the I2C bus. This pin has an internal pullup resistor on the PCB, which is required as part of the I2C spec, meaning you don't need to add one externally yourself. This also functions as&nbsp; **MOSI** &nbsp;in SPI mode.
- [**STEMMA QT**](https://learn.adafruit.com/introducing-adafruit-stemma-qt) **&nbsp;-&nbsp;** These connectors allow you to connect to development boards with&nbsp; **STEMMA QT** &nbsp;connectors, or to other things, with&nbsp;[various associated accessories](https://www.adafruit.com/category/619).

Info: 

## **Other Pins**

- **SDO/ALT ADDR** &nbsp;- This pin can be used as&nbsp; **MISO** &nbsp;in SPI mode, but is more commonly used as an optional bit in the I2C bus address. By default this pin is pulled down, meaning it has a value of&nbsp; **0** &nbsp;at startup, which will results in an I2C address of&nbsp; **0x53**. If you set this pin high (to 3.3V), and reset, the I2C address will be updated to&nbsp; **0x1D**.
- **CS** : This dual purpose pin can be used as the chip select line in SPI mode, but also determines whether the board will boot up into I2C or SPI mode. The default of logic high sets the board up for I2C, and manually setting this pin low and resetting will cause the device to enter SPI mode. Please note that SPI mode is not actively support and the SPI pins are not all 5V safe and level shifted, so care will be required when using it!
- **INT1** &nbsp;and&nbsp; **INT2** : There are two optional interrupt output pins on this sensor, which can be configured to change their state when one or more 'events' occur. For details on how to use these interrupts, see the Arduino/HW Interrupts page later in this guide.

## LED Jumper

- **LED jumper&nbsp;** - This jumper is located on the back of the board. Cut the trace on this jumper to cut power to the "on" LED.

# ADXL345 Digital Accelerometer

## Assembly and Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/006/362/medium800/adafruit_products_2013_03_23_IMG_1441-1024.jpg?1396835323)

The board comes with all surface-mount components pre-soldered. The included header strip can be soldered on for convenient use on a breadboard or with 0.1" connectors. However, for applications subject to extreme accelerations, shock or vibration, locking connectors or direct soldering is advised.

## Assembly
### Position the Header

Cut the header to size if necessary. Then plug the header - long pins down - into a breadboard to stabilize it for soldering.

![adafruit_products_2013_03_23_IMG_1443-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/006/363/medium640/adafruit_products_2013_03_23_IMG_1443-1024.jpg?1396835332)

### Add the Breakout

Align the breakout board and place it over the header pins on the breadboard.

![adafruit_products_2013_03_23_IMG_1446-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/006/364/medium640/adafruit_products_2013_03_23_IMG_1446-1024.jpg?1396835342)

### And Solder

Be sure to solder all pins to assure good electrical contact.

![adafruit_products_2013_03_23_IMG_1447-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/006/365/medium640/adafruit_products_2013_03_23_IMG_1447-1024.jpg?1396835354)

## I2C Wiring

The ADXL345 Breakout has an I2C address of 0x53. It can share the I2C bus with other I2C devices as long as each device has a unique address. Only 4 connections are required for I2C communication:

- GND -\> GND
- VIN -\> +5v
- SDA -\> SDA (Analog 4 on "Classic Arduinos")
- SCL -\> SCL (Analog 5 on "Classic Arduinos")

The Adafruit breakout has level shifting and regulation circuitry so you can power it from 3-5V and use 3V or 5V logic levels for I2C.

- Connect&nbsp; **SCL** &nbsp;on the Metro to&nbsp; **SCL** &nbsp;**(yellow wire)&nbsp;**on the ADXL343
- Connect&nbsp; **SDA** &nbsp;on the Metro to&nbsp; **SDA** &nbsp;**(blue wire)&nbsp;**in the ADXL343
- Connect&nbsp; **GND** &nbsp;on the Metro to&nbsp;**GND (black wire)**&nbsp;on the ADXL343
- For&nbsp; **3.3V LOGIC** &nbsp;boards: connect&nbsp; **3.3V** &nbsp;on the Arduino/Metro to&nbsp; **VIN** &nbsp;**(red wire)**&nbsp;on the ADXL343
- For&nbsp; **5.0V LOGIC&nbsp;** boards: Connect&nbsp; **5V** &nbsp;on the Arduino/Metro to&nbsp; **VIN** &nbsp;**(red wire)**&nbsp;on the ADXL343

![adafruit_products_metroStemma_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/186/medium640/adafruit_products_metroStemma_bb.png?1648226730)

![adafruit_products_metroBB_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/187/medium640/adafruit_products_metroBB_bb.png?1648226750)

![adafruit_products_originalMetroBB_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/189/medium640/adafruit_products_originalMetroBB_bb.png?1648226867)

# ADXL345 Digital Accelerometer

## Programming and Calibration

# Install the Library:
Download the [ADXL345 library](https://github.com/adafruit/Adafruit_ADXL345 "Link: https://github.com/adafruit/Adafruit\_ADXL345") and install it. You will also need the [Adafruit Sensor Library](https://github.com/adafruit/Adafruit_Sensor) if you do not already have it installed.  
  
[This guide](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use) will help you with the install process. # Test:
Click "File-\>Examples-\>Adafruit\_ADXL345-\>sensortest" to load the example sketch from the library.  
  
Then click on the compile/upload button to compile and upload the sketch to the Arduino. You should see output similar to below. Watch the values change as you move the board around. ![](https://cdn-learn.adafruit.com/assets/assets/000/006/367/medium800/adafruit_products_Capture.jpg?1396835378)

# Calibrate:
The ADXL chips are calibrated at the factory to a level of precision sufficient for most purposes. For critical applications where a higher degree of accuracy is required, you may wish to re-calibrate the sensor yourself.  
  
Calibration does not change the sensor outputs. But it tells you what the sensor output is for a known stable reference force in both directions on each axis. Knowing that, you can calculate the corrected output from a sensor reading. ![](https://cdn-learn.adafruit.com/assets/assets/000/006/368/medium800/adafruit_products_Coordinates.png?1396835396)

## Gravity as a Calibration Reference
Acceleration can be measured in units of gravitational force or "G", where 1G represents the gravitational pull at the surface of the earth. Gravity is a relatively stable force and makes a convenient and reliable calibration reference for surface-dwelling earthlings.  
  

## Calibration Method:
To calibrate the sensor to the gravitational reference, you need to determine the sensor output for each axis when it is precisely aligned with the axis of gravitational pull. Laboratory quality calibration uses precision positioning jigs. The method described here is simple and gives surprisingly good results with just a block of wood.  
  

## Mount the Sensor:
FIrst mount the sensor securely to a block or a box. The size is not important, as long as all the sides are at right angles. The material is not important as long as it is fairly rigid.  
  

## Load the Calibration Sketch:
Load and run the Calibration sketch below. Open the Serial Monitor and wait for the prompt.  
## Position the Block:
Place the block on a firm flat surface such as a sturdy table. Type a character in the Serial Monitor and hit return. The sketch will take a measurement on that axis and print the results.  
![adafruit_products_2013_03_26_IMG_1454-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/006/465/medium640/adafruit_products_2013_03_26_IMG_1454-1024.jpg?1396836697)

## Reposition the Block:
Turn the block so a different side is flat on the table and type another key to measure that axis.  

## 
![adafruit_products_2013_03_26_IMG_1456-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/006/467/medium640/adafruit_products_2013_03_26_IMG_1456-1024.jpg?1396836706)

## Repeat:
Repeat for all six sides of the block to measure the positive and negative aspects of each axis.  
![adafruit_products_2013_03_26_IMG_1458-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/006/468/medium640/adafruit_products_2013_03_26_IMG_1458-1024.jpg?1396836716)

## _(Hint:)_
_For the sides obstructed by the breakout board and/or wires, press the block up against the bottom of the table while taking the reading._  
![adafruit_products_2013_03_26_IMG_1460-1024.jpg](https://cdn-learn.adafruit.com/assets/assets/000/006/469/medium640/adafruit_products_2013_03_26_IMG_1460-1024.jpg?1396836730)

## Calibration Results:
Once all six sides have been sampled, the values printed in the Serial Monitor will represent actual measurements for +/- 1G forces on each axis. These values can be used to re-scale readings for better accuracy. ## Calibration Sketch:
```auto
#include &lt;Wire.h&gt;
#include &lt;Adafruit_Sensor.h&gt;
#include &lt;Adafruit_ADXL345_U.h&gt;

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);


float AccelMinX = 0;
float AccelMaxX = 0;
float AccelMinY = 0;
float AccelMaxY = 0;
float AccelMinZ = 0;
float AccelMaxZ = 0;


void setup(void) 
{
  Serial.begin(9600);
  Serial.println("ADXL345 Accelerometer Calibration"); 
  Serial.println("");
  
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no ADXL345 detected ... Check your wiring!");
    while(1);
  }
}

void loop(void)
{
    Serial.println("Type key when ready..."); 
    while (!Serial.available()){}  // wait for a character
    
    /* Get a new sensor event */ 
    sensors_event_t accelEvent;  
    accel.getEvent(&amp;accelEvent);
    
    if (accelEvent.acceleration.x &lt; AccelMinX) AccelMinX = accelEvent.acceleration.x;
    if (accelEvent.acceleration.x &gt; AccelMaxX) AccelMaxX = accelEvent.acceleration.x;
    
    if (accelEvent.acceleration.y &lt; AccelMinY) AccelMinY = accelEvent.acceleration.y;
    if (accelEvent.acceleration.y &gt; AccelMaxY) AccelMaxY = accelEvent.acceleration.y;
  
    if (accelEvent.acceleration.z &lt; AccelMinZ) AccelMinZ = accelEvent.acceleration.z;
    if (accelEvent.acceleration.z &gt; AccelMaxZ) AccelMaxZ = accelEvent.acceleration.z;
  
    Serial.print("Accel Minimums: "); Serial.print(AccelMinX); Serial.print("  ");Serial.print(AccelMinY); Serial.print("  "); Serial.print(AccelMinZ); Serial.println();
    Serial.print("Accel Maximums: "); Serial.print(AccelMaxX); Serial.print("  ");Serial.print(AccelMaxY); Serial.print("  "); Serial.print(AccelMaxZ); Serial.println();

    while (Serial.available())
    {
      Serial.read();  // clear the input buffer
    }
}
```

## Typical Calibration Output:
```auto
ADXL345 Accelerometer Calibration

Type key when ready...
Accel Minimums: 0.00  0.00  0.00
Accel Maximums: 0.12  0.20  1.14
Type key when ready...
Accel Minimums: 0.00  0.00  0.00
Accel Maximums: 0.12  0.20  1.14
Type key when ready...
Accel Minimums: 0.00  0.00  0.00
Accel Maximums: 0.12  0.20  1.14
Type key when ready...
Accel Minimums: 0.00  0.00  0.00
Accel Maximums: 0.12  0.20  1.14
Type key when ready...
Accel Minimums: 0.00  0.00  -0.24
Accel Maximums: 0.12  1.37  1.14
Type key when ready...
Accel Minimums: 0.00  0.00  -0.24
Accel Maximums: 0.12  1.37  1.14
Type key when ready...
Accel Minimums: 0.00  -1.22  -0.27
Accel Maximums: 0.12  1.37  1.14
Type key when ready...
Accel Minimums: 0.00  -1.22  -0.27
Accel Maximums: 0.12  1.37  1.14
Type key when ready...
Accel Minimums: -1.18  -1.22  -0.27
Accel Maximums: 0.12  1.37  1.14
Type key when ready...

```

The results of the calibration sketch can be used to do a two-point calibraton as described here:&nbsp;[Two Point Calibration](https://learn.adafruit.com/calibrating-sensors/two-point-calibration)

# ADXL345 Digital Accelerometer

## Library Reference

# **Constructor:**
 **Adafruit\_ADXL345(int32\_t sensorID = -1)**  
  
Constructs an instance of the ADXL345 device driver object. 'sensorID' is a device identifier. It will be returned in the sensor\_event in each call to getEvent(). The sensorID has no effect on the operation of the driver or device, but is useful in managing sensor events in systems with multiple sensors.# Initialization()
**bool begin(void****)**  
  
The begin() function initializes communication with the device. The return value is 'true' if it succeeds in connecting to the ADXL345.# **Sensor Details:**
**void getSensor(sensor\_t\*);**  
  
The getSensor() function returns basic information about the sensor. For details about the sensor\_t structure, refer to the [ReadMe file](https://github.com/adafruit/Adafruit_Sensor) for the Adafruit Sensor Library.  
  
# **Getting and Setting the operating range:**
**void setRange(range\_t range)**  
  
The setRange() function sets the operating range for the sensor. Higher values will have a wider measurement range. Lower values will have more sensitivity.  
  
Valid range constants are:  

- **ADXL345\_RANGE\_16\_G**  
- **ADXL345\_RANGE\_8\_G**  
- **ADXL345\_RANGE\_4\_G**  
- **ADXL345\_RANGE\_2\_G** (default value)  

**range\_t getRange(void);**  
  
The getRange() function returns the current operating range as set by setRange()# **Getting and Setting the Data Rate:**
**void setDataRate(dataRate\_t dataRate);**  
  
The setDataRate() function sets the rate at which the sensor output is updated. Rates above 100 Hz will exhibit increased noise. Rates below 6.25 Hz will be more sensitive to temperature variations. See the [data sheet](http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf) for details.  
  
Valid data rate constants are:  
  

- **ADXL345\_DATARATE\_3200\_HZ**  
- **ADXL345\_DATARATE\_1600\_HZ**   
- **ADXL345\_DATARATE\_800\_HZ**  
- **ADXL345\_DATARATE\_400\_HZ**   
- **ADXL345\_DATARATE\_200\_HZ**   
- **ADXL345\_DATARATE\_100\_HZ**   
- **ADXL345\_DATARATE\_50\_HZ**   
- **ADXL345\_DATARATE\_25\_HZ**   
- **ADXL345\_DATARATE\_12\_5\_HZ**   
- **ADXL345\_DATARATE\_6\_25HZ**   
- **ADXL345\_DATARATE\_3\_13\_HZ**   
- **ADXL345\_DATARATE\_1\_56\_HZ**   
- **ADXL345\_DATARATE\_0\_78\_HZ**   
- **ADXL345\_DATARATE\_0\_39\_HZ**   
- **ADXL345\_DATARATE\_0\_20\_HZ**   
- **ADXL345\_DATARATE\_0\_10\_HZ** (default value)  

**dataRate\_t getDataRate(void);**  
  
The getDataRate() function returns the current data rate as set by setDataRate().  
# **Reading Sensor Events:**
**void getEvent(sensors\_event\_t\*);**  
  
The getEvent() function returns the next available reading in the form of a sensor\_event. The sensor\_event contains the sensor\_id as passed to the constructor as well as the X, Y and Z axis readings from the accelerometer. For more information about sensor\_events, see the [ReadMe file](https://github.com/adafruit/Adafruit_Sensor) for the Adafruit Sensor Library.  
# ADXL345 Digital Accelerometer

## Python and CircuitPython

It's easy to use the ADXL343 or the ADXL345 with Python and CircuitPython, and the [Adafruit CircuitPython ADXL34x](https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x) module. This module allows you to easily write Python code that reads the acceleration, taps, motion and more from the breakout.

You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python [thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

Info: 

## CircuitPython Microcontroller Wiring

First, wire up the breakout exactly as shown in the previous pages. Here is an example of wiring the ADXL343 to a Feather M0:

&nbsp;

- Connect&nbsp; **SCL** (yellow wire in STEMMA QT version) on the Feather to&nbsp; **SCL** on the ADXL343
- Connect&nbsp; **SDA** (blue wire in STEMMA QT version) on the Feather to&nbsp; **SDA** in the ADXL343
- Connect&nbsp; **GND** (black wire in STEMMA QT version) on the Feather to&nbsp; **GND** on the ADXL343
- Connect&nbsp; **3.3V** (red wire in STEMMA QT version) on the Feather to&nbsp; **VIN** on the ADXL343

![sensors_featherStemma_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/015/medium640/sensors_featherStemma_bb.png?1647981149)

![sensors_featherBreadboard_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/016/medium640/sensors_featherBreadboard_bb.png?1647981181)

![original_sensors_ADXL343_FeatherExpress_Setup_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/017/medium640/original_sensors_ADXL343_FeatherExpress_Setup_bb.png?1647981197)

Here's an example of wiring the ADXL345 to a Feather M0:

- Connect&nbsp; **SCL** (blue wire) on the Feather to **SCL** on the ADXL345
- Connect&nbsp; **SDA** (yellow wire) on the Feather to **SDA** in the ADXL345
- Connect&nbsp; **GND** (black wire) on the Feather to **GND** on the ADXL345
- Connect&nbsp; **3.3V** (red wire) on the Feather to **VIN** on the ADXL345

![sensors_whitefeatherStemma_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/179/medium640/sensors_whitefeatherStemma_bb.png?1648226015)

![sensors_featherBB_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/180/medium640/sensors_featherBB_bb.png?1648226037)

![sensors_originalADXL345_Feather_M0_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/182/medium640/sensors_originalADXL345_Feather_M0_bb.png?1648226052)

## Python Computer Wiring

Since there's&nbsp;_dozens_&nbsp;of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms,&nbsp;[please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

The following shows a Raspberry Pi connected to the ADXL343:

- Connect&nbsp; **SCL** (yellow wire in STEMMA QT version) on the RPi to&nbsp; **SCL** on the ADXL343
- Connect&nbsp; **SDA** (blue wire in STEMMA QT version) on the Rpi to&nbsp; **SDA** in the ADXL343
- Connect&nbsp; **GND** (black wire in STEMMA QT version) on the Rpi to&nbsp; **GND** on the ADXL343
- Connect&nbsp; **3.3V** (red wire in STEMMA QT version) on the Rpi to&nbsp; **VIN** on the ADXL343

![sensors_piStemma_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/018/medium640/sensors_piStemma_bb.png?1647981273)

![sensors_piBreadboard_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/019/medium640/sensors_piBreadboard_bb.png?1647981285)

![original_sensors_ADXL343_RPi3_Setup_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/020/medium640/original_sensors_ADXL343_RPi3_Setup_bb.png?1647981297)

The following shows a Raspberry Pi connected to the ADXL345:

- Connect&nbsp; **SCL** (blue wire) on the RPi to **SCL** on the ADXL345
- Connect&nbsp; **SDA** (yellow wire) on the RPi to **SDA** in the ADXL345
- Connect&nbsp; **GND** (black wire) on the RPi to **GND** on the ADXL345
- Connect&nbsp; **3.3V** (red wire) on the RPi to **VIN** on the ADXL345

![sensors_piStemma_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/183/medium640/sensors_piStemma_bb.png?1648226143)

![sensors_piBB_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/184/medium640/sensors_piBB_bb.png?1648226179)

![originalsensors_ADXL345_RasPi_I2C_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/110/185/medium640/originalsensors_ADXL345_RasPi_I2C_bb.png?1648226194)

## Library Installation

You'll need to install the [Adafruit CircuitPython ADXL34x](https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x) library on your CircuitPython board.

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://circuitpython.org/libraries).&nbsp; Our CircuitPython starter guide has&nbsp;[a great page on how to install the library bundle](https://learn.adafruit.com/welcome-to-circuitpython/circuitpython-libraries).

For non-express boards like the Trinket M0 or Gemma M0, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_adxl34x.mpy**
- **adafruit\_bus\_device**

Before continuing make sure your board's lib folder or root filesystem has the&nbsp; **adafruit\_adxl34x.mpy,&nbsp;** and **&nbsp;adafruit\_bus\_device**** &nbsp; **files and folders** &nbsp;**copied over.

Next&nbsp;[connect to the board's serial REPL&nbsp;](https://learn.adafruit.com/micropython-basics-how-to-load-micropython-on-a-board/serial-terminal)so you are at the CircuitPython&nbsp; **\>\>\>** prompt.

## Python Installation of the ADXL34x Library

You'll need to install the **Adafruit\_Blinka** library that provides the CircuitPython support in Python. This may also require enabling I2C on your platform and verifying you are running Python 3.&nbsp;[Since each platform is a little different, and Linux changes often, please visit the CircuitPython on Linux guide to get your computer ready](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux)!

Once that's done, from your command line run the following command:

- `sudo pip3 install adafruit-circuitpython-adxl34x`

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

## CircuitPython & Python Usage

To demonstrate the usage of the breakout we'll initialize it and read the acceleration and more from the board's Python REPL.

Run the following code to import the necessary modules and create the I2C object:

```python
import time
import board
import adafruit_adxl34x

i2c = board.I2C()
```

If you're using the **ADXL343** , run the following to initialise the I2C connection with the breakout:

```python
accelerometer = adafruit_adxl34x.ADXL343(i2c)
```

If you're using the **ADXL345** , run the following to initialise the I2C connection with the breakout:

```python
accelerometer = adafruit_adxl34x.ADXL345(i2c)
```

Now you're ready to read values from and enable features of the breakout using any of the following:

- **acceleration** - The acceleration values on the x, y and z axes
- **enable\_motion\_detection** - Enables motion detection. Allows for setting threshold. Threshold defaults to 18.
- **enable\_tap\_detection** - Enables tap detection. Allows for single or double-tap detection.
- **enable\_freefall\_detection** - Enables freefall detection. Allows for setting threshold and time. Threshold defaults to 10, time defaults to 25.
- **events** - Used to read the events when motion detection, tap detection and freefall detection are enables. Requires specifying which event you are trying to read.

To print the acceleration values:

```python
while True:
    print(accelerometer.acceleration)
    time.sleep(0.2)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/082/176/medium800/sensors_ADXL34x_REPL_output.png?1570732642)

That's all there is to reading acceleration values from the ADXL343 and ADXL345 using CircuitPython!

## Full Example Code
https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x/blob/main/examples/adxl34x_simpletest.py

## Motion, Tap and Freefall

There are examples for enabling and using motion, tap and freefall available on GitHub:

- [Motion detection on the ADXL343 and ADXL345](https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x/blob/master/examples/adxl34x_motion_detection_test.py)
- [Tap detection on the ADXL343 and ADXL345](https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x/blob/master/examples/adxl34x_tap_detection_test.py)
- [Freefall detection on the ADXL343 and ADXL345](https://github.com/adafruit/Adafruit_CircuitPython_ADXL34x/blob/master/examples/adxl34x_freefall_detection_test.py)

Save any of the files as **code.py** on your CircuitPython board, or run them from the Python REPL on your Linux computer, to try them out.

# ADXL345 Digital Accelerometer

## Python Docs

# ADXL345 Digital Accelerometer

## Downloads

## Files

- [ADXL345 datasheet](https://cdn-learn.adafruit.com/assets/assets/000/110/160/original/ADXL345.pdf?1648220243)
- [Fritzing object (STEMMA QT version) in the Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20ADXL345%20STEMMA%20QT.fzpz)
- [Fritzing object (original version) in the Adafruit Fritzing Library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20ADXL345.fzpz)
- [EagleCAD PCB files on GitHub](https://github.com/adafruit/Adafruit_ADXL345_PCB)

## Schematic and Fab Print STEMMA QT Version
![](https://cdn-learn.adafruit.com/assets/assets/000/110/162/medium800/adafruit_products_schem.png?1648221956)

![](https://cdn-learn.adafruit.com/assets/assets/000/110/163/medium800/adafruit_products_brd.png?1648221966)

## Schematic and Fab Print Original Version
![](https://cdn-learn.adafruit.com/assets/assets/000/108/759/medium800/adafruit_products_ADXL345_sch.png?1644265806)

![](https://cdn-learn.adafruit.com/assets/assets/000/108/763/medium800/adafruit_products_ADXL345_fab_print.png?1644266919)


## Featured Products

### ADXL345 - Triple-Axis Accelerometer (+-2g/4g/8g/16g) w/ I2C/SPI

[ADXL345 - Triple-Axis Accelerometer (+-2g/4g/8g/16g) w/ I2C/SPI](https://www.adafruit.com/product/1231)
Filling out our accelerometer offerings, we now have the really lovely digital ADXL345 from Analog Devices, a triple-axis accelerometer with digital I2C and SPI interface breakout. We added an on-board 3.3V regulator and logic-level shifting circuitry, making it a perfect choice for...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1231)
[Related Guides to the Product](https://learn.adafruit.com/products/1231/guides)

## Related Guides

- [Raspberry Pi Selfie Bot](https://learn.adafruit.com/raspberry-pi-selfie-bot.md)
- [PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO](https://learn.adafruit.com/esp32-s2-tft-boxing-glove-tracker-w-adafruit-io.md)
- [I2C Addresses and Troublesome Chips](https://learn.adafruit.com/i2c-addresses.md)
- [Adafruit CH9328 UART to HID Keyboard Breakout](https://learn.adafruit.com/adafruit-ch9328-uart-to-hid-keyboard-breakout.md)
- [Adafruit MCP23017 I2C GPIO Expander](https://learn.adafruit.com/adafruit-mcp23017-i2c-gpio-expander.md)
- [Adafruit NeoKey 1x4 QT I2C Breakout](https://learn.adafruit.com/neokey-1x4-qt-i2c.md)
- [ST 9-DoF Combo Breakouts and Wings](https://learn.adafruit.com/st-9-dof-combo.md)
- [Adafruit NeoPixel Breakout](https://learn.adafruit.com/adafruit-neopixel-breakout.md)
- [UTi165 Thermal Fever Scanner Camera](https://learn.adafruit.com/uti165-thermal-fever-scanner-camera.md)
- [Adafruit MCP4728 I2C Quad DAC](https://learn.adafruit.com/adafruit-mcp4728-i2c-quad-dac.md)
- [Adafruit BrainCraft HAT - Easy Machine Learning for Raspberry Pi](https://learn.adafruit.com/adafruit-braincraft-hat-easy-machine-learning-for-raspberry-pi.md)
- [Adafruit I2S Stereo Decoder - UDA1334A](https://learn.adafruit.com/adafruit-i2s-stereo-decoder-uda1334a.md)
- [Booster Cable](https://learn.adafruit.com/booster-cable.md)
- [Adafruit HDC302x Precision Temperature & Humidity Sensor](https://learn.adafruit.com/adafruit-hdc3021-precision-temperature-humidity-sensor.md)
- [Adafruit AirLift FeatherWing - ESP32 WiFi Co-Processor](https://learn.adafruit.com/adafruit-airlift-featherwing-esp32-wifi-co-processor-featherwing.md)
