From 5e2e85695ce349f5707b616e04e621523589e24b Mon Sep 17 00:00:00 2001 From: William Clark Date: Wed, 20 Dec 2023 16:40:22 +0000 Subject: [PATCH] it finds device on i2c --- lis3dh.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lis3dh.py diff --git a/lis3dh.py b/lis3dh.py new file mode 100644 index 0000000..ee08dfb --- /dev/null +++ b/lis3dh.py @@ -0,0 +1,22 @@ +# LIS3DH + +from time import sleep +from machine import I2C +import struct + +LIS3DH_I2C_ADDR = 0x18 + +sda_pin = machine.Pin(16) +scl_pin = machine.Pin(17) + +i2c = I2C(0, scl=scl_pin, sda=sda_pin, freq=400000) + +def read(reg, n): + return i2c.readfrom_mem(LIS3DH_I2C_ADDR, reg, n) + +def write(reg, val): + i2c.writeto_mem(LIS3DH_I2C_ADDR, reg, val) + +# WHO_AM_I +if read(0x0F, 1)[0] == 0x33: + print("found LIS3DH")