Added Mentor Sandbox and ADXL345 test code and library from https://github.com/rsxtrix/ESP32-ADXL345-MicroPython-Driver
This commit is contained in:
parent
190e194da5
commit
0113af8926
4 changed files with 39 additions and 0 deletions
BIN
Documentation/ADXL345_PinDetails.jpg
Normal file
BIN
Documentation/ADXL345_PinDetails.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 96 KiB |
BIN
Documentation/roll-pitch-yaw.webp
Normal file
BIN
Documentation/roll-pitch-yaw.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
26
uC/main_uC/Mentor/_Sandbox/ADXL345/adxl345.py
Normal file
26
uC/main_uC/Mentor/_Sandbox/ADXL345/adxl345.py
Normal 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
|
||||
13
uC/main_uC/Mentor/_Sandbox/ADXL345/main.py
Normal file
13
uC/main_uC/Mentor/_Sandbox/ADXL345/main.py
Normal 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))
|
||||
Loading…
Reference in a new issue