Skip to content

Instantly share code, notes, and snippets.

@AdoHaha
Created October 15, 2021 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdoHaha/134a0d1877af61867b0ba75696baa35b to your computer and use it in GitHub Desktop.
Save AdoHaha/134a0d1877af61867b0ba75696baa35b to your computer and use it in GitHub Desktop.
Read bma220 accelerometer micropython esp32
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