From 4c10e5de06989f7c822bdcc09e4ab875b8759509 Mon Sep 17 00:00:00 2001 From: Kacper Date: Tue, 1 Mar 2022 14:33:09 +0000 Subject: [PATCH] Tweaking --- lis3dh.py | 3 +++ main.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lis3dh.py b/lis3dh.py index 770083e..9e3c606 100644 --- a/lis3dh.py +++ b/lis3dh.py @@ -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 \ No newline at end of file diff --git a/main.py b/main.py index a6cc3f5..756a94d 100644 --- a/main.py +++ b/main.py @@ -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!")