Added Mentor Sandbox and ADXL345 test code and library from https://github.com/rsxtrix/ESP32-ADXL345-MicroPython-Driver

This commit is contained in:
Jarrad Brown 2026-02-27 14:59:10 -06:00
parent 190e194da5
commit 0113af8926
4 changed files with 39 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -0,0 +1,26 @@
from micropython import const
from machine import Pin, SoftI2C
# ADXL-345 Registers
_DATA_FORMAT = const(0x31)
_POWER_CTL = const(0x2D)
_DATAX0 = const(0x32)
class ADXL345:
def __init__(self, i2c, address=0x53):
self.i2c = i2c
self.address = address
self.i2c.start()
self.i2c.writeto(self.address, bytearray([_POWER_CTL, 0x08])) # power on
self.i2c.writeto(self.address, bytearray([_DATA_FORMAT, 0x08])) # full resolution mode
self.i2c.stop()
def read(self):
self.i2c.start()
self.i2c.writeto(self.address, bytearray([_DATAX0]))
data = self.i2c.readfrom(self.address, 6)
self.i2c.stop()
x = ((data[1] << 8) | data[0])
y = ((data[3] << 8) | data[2])
z = ((data[5] << 8) | data[4])
return (x, y, z)d

View file

@ -0,0 +1,13 @@
from machine import Pin, SoftI2C
from adxl345 import ADXL345
# Define I2C pins
i2c = SoftI2C(scl=Pin(15), sda=Pin(16))
# Initialize ADXL345
accel = ADXL345(i2c)
# Read accelerometer data
while True:
x, y, z = accel.read()
print("x = {}, y = {}, z = {}".format(x, y, z))