From 9702a310535410b83f2459431007b2efd45b2ed0 Mon Sep 17 00:00:00 2001 From: dahanzimin <353767514@qq.com> Date: Wed, 16 Apr 2025 18:47:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=94=AF=E6=8C=81MINI-G5?= =?UTF-8?q?=E5=BA=93=EF=BC=8C=E5=8F=8A=E4=BF=AE=E5=A4=8DHX720=E8=B4=9F?= =?UTF-8?q?=E6=95=B0=E8=BD=AC=E6=8D=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micropython/origin/build/lib/ci130x.py | 2 +- .../micropython/origin/build/lib/hx720.py | 20 +++++++------ .../origin/build/lib/mini_g5.py | 30 +++++++++++++++++++ 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 boards/default_src/micropython_esp32c2/origin/build/lib/mini_g5.py diff --git a/boards/default_src/micropython/origin/build/lib/ci130x.py b/boards/default_src/micropython/origin/build/lib/ci130x.py index 7a6bdc38..7fd34940 100644 --- a/boards/default_src/micropython/origin/build/lib/ci130x.py +++ b/boards/default_src/micropython/origin/build/lib/ci130x.py @@ -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") diff --git a/boards/default_src/micropython/origin/build/lib/hx720.py b/boards/default_src/micropython/origin/build/lib/hx720.py index 43c6bc45..4079cdf5 100644 --- a/boards/default_src/micropython/origin/build/lib/hx720.py +++ b/boards/default_src/micropython/origin/build/lib/hx720.py @@ -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) diff --git a/boards/default_src/micropython_esp32c2/origin/build/lib/mini_g5.py b/boards/default_src/micropython_esp32c2/origin/build/lib/mini_g5.py new file mode 100644 index 00000000..5038dfdc --- /dev/null +++ b/boards/default_src/micropython_esp32c2/origin/build/lib/mini_g5.py @@ -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()