diff --git a/Documentation/ADXL345_PinDetails.jpg b/Documentation/ADXL345_PinDetails.jpg new file mode 100644 index 0000000..a2f425c Binary files /dev/null and b/Documentation/ADXL345_PinDetails.jpg differ diff --git a/Documentation/roll-pitch-yaw.webp b/Documentation/roll-pitch-yaw.webp new file mode 100644 index 0000000..5632b91 Binary files /dev/null and b/Documentation/roll-pitch-yaw.webp differ diff --git a/uC/main_uC/Mentor/_Sandbox/ADXL345/adxl345.py b/uC/main_uC/Mentor/_Sandbox/ADXL345/adxl345.py new file mode 100644 index 0000000..7c11499 --- /dev/null +++ b/uC/main_uC/Mentor/_Sandbox/ADXL345/adxl345.py @@ -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 \ No newline at end of file diff --git a/uC/main_uC/Mentor/_Sandbox/ADXL345/main.py b/uC/main_uC/Mentor/_Sandbox/ADXL345/main.py new file mode 100644 index 0000000..9415e2e --- /dev/null +++ b/uC/main_uC/Mentor/_Sandbox/ADXL345/main.py @@ -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))