Created
October 15, 2021 14:54
-
-
Save AdoHaha/134a0d1877af61867b0ba75696baa35b to your computer and use it in GitHub Desktop.
Read bma220 accelerometer micropython esp32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import machine | |
i2c = machine.I2C(0) | |
import struct | |
import time | |
import math | |
def calib_g(val): | |
return val*0.613305+0.0124529 | |
while True: | |
time.sleep(0.1) | |
x,y,z = struct.unpack('bbb',i2c.readfrom_mem(10,0x04,3)) | |
x>>=2 | |
y>>=2 | |
z>>=2 | |
#print(math.sqrt(x**2+y**2+z**2)) | |
print(calib_g(x),calib_g(y),calib_g(z)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment