The ADXL345 is a 3 axis digital accelerometer. It utilizes the I2C and or SPI protocols to commiunicate with micro-controllers.
It's application can range from motion sensing, tilt sensing, impact detection, freefall detection and vibration monitoring.
- 1 - ADXL345 with header pins soldered
- 4 - F to F connectors
Note that Board numbering is used, NOT Broadcom numbering
Refer to this diagram to understand the pins we are using
Note that Board numbering is used NOT Broadcom numbering
To run Ic2, several configurations are needed.
- The below script will install all dependanies
sudo apt-get install python3-dev python3-dev python3-pip python3-smbus i2c-tools -y
- Enable the I2C interface on the pi
- Run the command below to ensure the accelerometer is being detected
i2cdetect -y 1
# Print out x, y and z coordinate data
import time
import board
import busio
import adafruit_adxl34x
import subprocess
i2c = busio.I2C(board.SCL, board.SDA)
accelerometer = adafruit_adxl34x.ADXL343(i2c)
try:
while True:
print("%f %f %f" %accelerometer.acceleration)
time.sleep(.1)
subprocess.run("clear", shell=True)
except KeyboardInterrupt:
print("\nExiting...\n")
Code link.