This commit is contained in:
Kacper 2022-03-01 14:33:09 +00:00
parent ac5f883981
commit 4c10e5de06
2 changed files with 4 additions and 1 deletions

View file

@ -100,6 +100,8 @@ class lis3dh:
X = int.from_bytes(x.buf[0],"big")
Y = int.from_bytes(y.buf[0],"big")
Z = int.from_bytes(z.buf[0],"big")
# Convert from binary 2s complement to useful data
new_values = []
for D in [X,Y,Z]:
MSB = D >> 7
@ -108,6 +110,7 @@ class lis3dh:
else:
res = (D*self.resolution)/128
new_values.append(res)
return new_values
else:
return None # Should never get here lol

View file

@ -3,7 +3,7 @@ from datetime import datetime
print("Raspberry Pi Zero W, up and running!")
bus = smbus2.SMBus(1)
accel = lis3dh(bus,2,10)
accel = lis3dh(bus,2,1)
print("LIS3DH initiated successfully!")