更新飞翔的库

This commit is contained in:
dahanzimin
2025-09-16 18:03:23 +08:00
parent 6fa10e5451
commit 4adf341226
5 changed files with 461 additions and 26 deletions

View File

@@ -3,12 +3,10 @@ QMI8658
Micropython library for the QMI8658(Accelerometer+Gyroscope)
=======================================================
#Preliminary composition 20220716
dahanzimin From the Mixly Team
@dahanzimin From the Mixly Team
"""
import time
from math import atan, sqrt, degrees
from micropython import const
QMI8658_REG_DEVICE_ID = const(0x00)
@@ -54,7 +52,7 @@ class QMI8658:
raise AttributeError("Cannot find a QMI8658")
self._wreg(QMI8658_REG_Ctrl9,0xA2) #做selftest提高精度
time.sleep(1)
time.sleep(0.1)
self._wreg(QMI8658_REG_Ctrl1,0x60)
self._wreg(QMI8658_REG_Ctrl7,0x03) #启动
self._wreg(QMI8658_REG_Ctrl2,(AccRange<< 4)|Acc_Gyr_Odr) #ACC-500HZ/8G
@@ -78,8 +76,9 @@ class QMI8658:
return self._rreg(QMI8658_REG_StatusInt)
def u2s(self,n):
return n if n < (1 << 15) else n - (1 << 16)
return n if n < (1 << 15) else n - (1 << 16)
@property
def getdata(self):
while self.status() == 0x81:
time.sleep(0.001)
@@ -92,12 +91,21 @@ class QMI8658:
gyr_y=float(self.u2s(_buffer[11]<<8|_buffer[10]))/self.gyr_lsb_div
gyr_z=float(self.u2s(_buffer[13]<<8|_buffer[12]))/self.gyr_lsb_div
return (acc_x,acc_y,acc_z),(gyr_x,gyr_y,gyr_z),round(tmp,2)
def accelerometer(self):
return self.getdata()[0]
def acceleration(self):
return self.getdata[0]
def strength(self):
return sqrt(self.getdata[0][0]**2+self.getdata[0][1]**2+self.getdata[0][2]**2)
def gyroscope(self):
return self.getdata()[1]
return self.getdata[1]
def temperature(self):
return self.getdata()[2]
return self.getdata[2]
def eulerangles(self,upright=False):
x,y,z = self.acceleration()
pitch = degrees(atan(z / sqrt(x ** 2 + y ** 2))) if upright else degrees(atan(y / sqrt(x ** 2 + z ** 2)))
roll = degrees(atan(x / sqrt(y ** 2 + z ** 2)))
return round(pitch,2),round(roll,2)