更新支持MINI-G5库,及修复HX720负数转换问题

This commit is contained in:
dahanzimin
2025-04-16 18:47:26 +08:00
parent 325d6e90dc
commit 9702a31053
3 changed files with 42 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ class CI130X:
self._rreg(_CI_ID_GET, 3)
except:
try: #C130X 启动慢,加延时判断
time.sleep_ms(500)
time.sleep_ms(850)
self._rreg(_CI_ID_GET, 3)
except:
raise AttributeError("Cannot find a CI130X")

View File

@@ -50,18 +50,20 @@ class HX720:
self._sck.value(1)
self._sck.value(0)
return raw_data | 0xFF000000 if raw_data & 0x800000 else raw_data
return raw_data if raw_data < (1 << (DATA_BITS - 1)) else raw_data - (1 << DATA_BITS)
def tare(self, times=10):
"""清零传感器"""
total = 0
for _ in range(times):
total += self.read_raw()
self.offset = total / times
_values = []
for _ in range(max(times, 5)):
_values.append(self.read_raw())
_values = sorted(_values)[2: -2]
self.offset = sum(_values) / len(_values)
def read_weight(self, times=5):
"""读取重量数据,返回去掉偏移量的平均值"""
total = 0
for _ in range(times):
total += self.read_raw()
return round((total / times - self.offset) / self.scale, 2)
_values = []
for _ in range(max(times, 3)):
_values.append(self.read_raw())
_values = sorted(_values)[1: -1]
return round((sum(_values) / len(_values)- self.offset) / self.scale, 2)

View File

@@ -0,0 +1,30 @@
"""
MINI G5 -MixGo MINI EXT G5
MicroPython library for the MINI G5 (Expansion board for MixGo MINI)
=======================================================
@dahanzimin From the Mixly Team
"""
import gc
from machine import Pin, SoftI2C
'''i2c-extboard'''
ext_i2c = SoftI2C(scl=Pin(7), sda=Pin(8), freq=400000)
'''RFID_Sensor'''
try :
import rc522
ext_rfid = rc522.RC522(ext_i2c)
except Exception as e:
print("Warning: Failed to communicate with SI522A (RFID) or",e)
'''ASR_Sensor'''
try :
import ci130x
ext_asr = ci130x.CI130X(ext_i2c)
except Exception as e:
print("Warning: Failed to communicate with CI130X (ASR) or",e)
'''Reclaim memory'''
gc.collect()