From 7d6182472318261a7c512d113129f36f1a51a58b Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Wed, 17 Jun 2026 22:51:25 -0400 Subject: [PATCH] Resolve I2C pin conflict on Waveshare RLCD board, use SoftI2C for dynamic configurations, and add RTC/SHTC3 utilities to upload list --- lib/board_config.py | 28 ++++++++++++++++------------ lib/rtc_util.py | 3 ++- lib/shtc3_util.py | 3 ++- upload_files.py | 2 ++ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/board_config.py b/lib/board_config.py index 9cb9371..124faaa 100644 --- a/lib/board_config.py +++ b/lib/board_config.py @@ -68,11 +68,13 @@ def detect_board(): return # 2. We are on ESP32 platform. - # Try scanning I2C(0) on Hosyond pins (SDA=16, SCL=15) + # Use SoftI2C for dynamic detection scan to avoid hardware I2C pin conflicts + from machine import SoftI2C + + # Try scanning SDA=16, SCL=15 (Hosyond pins) try: - test_i2c = I2C(0, sda=Pin(16), scl=Pin(15)) + test_i2c = SoftI2C(sda=Pin(16), scl=Pin(15)) devices = test_i2c.scan() - # FT6336U touchscreen is at 0x38 on Hosyond if 0x38 in devices: print("Auto-detected: Hosyond ESP32-S3 Touchscreen board") BOARD_TYPE = 'HOSYOND' @@ -83,7 +85,8 @@ def detect_board(): has_rtc = False led_pin = 48 - i2c_bus = test_i2c + # Now initialize SoftI2C + i2c_bus = SoftI2C(sda=Pin(16), scl=Pin(15)) # Setup SPI spi_bus = SPI(1, baudrate=40000000, polarity=0, phase=0, sck=Pin(12), mosi=Pin(11), miso=Pin(13)) @@ -114,13 +117,12 @@ def detect_board(): return except Exception as e: - print("I2C scan on Hosyond pins failed:", e) + print("SoftI2C scan on Hosyond pins failed:", e) - # 3. Try scanning I2C(0) on Waveshare RLCD pins (SDA=13, SCL=14) + # 3. Try scanning SDA=13, SCL=14 (Waveshare RLCD pins) try: - test_i2c = I2C(0, sda=Pin(13), scl=Pin(14)) + test_i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) devices = test_i2c.scan() - # SHTC3 is at 0x70, PCF85063 RTC is at 0x51 if 0x70 in devices or 0x51 in devices: print("Auto-detected: Waveshare ESP32-S3-RLCD-4.2 board") BOARD_TYPE = 'WAVESHARE_RLCD' @@ -131,8 +133,6 @@ def detect_board(): has_rtc = True led_pin = 38 - i2c_bus = test_i2c - # Setup SPI spi_bus = SPI(1, baudrate=20000000, polarity=0, phase=0, sck=Pin(11), mosi=Pin(12)) @@ -140,6 +140,9 @@ def detect_board(): import rlcd display_instance = rlcd.RLCD(spi_bus, cs=Pin(40), dc=Pin(5), rst=Pin(41)) + # Now initialize SoftI2C (after SPI/Display setup to avoid MISO pin conflict on Pin 13) + i2c_bus = SoftI2C(sda=Pin(13), scl=Pin(14)) + # Audio pins & clocks configuration audio_mclk_pin = 16 audio_mclk_freq = 12288000 @@ -155,7 +158,7 @@ def detect_board(): return except Exception as e: - print("I2C scan on Waveshare RLCD pins failed:", e) + print("SoftI2C scan on Waveshare RLCD pins failed:", e) # 4. Fallback default if auto-detection failed completely print("Auto-detection failed. Falling back to Hosyond ESP32-S3 defaults...") @@ -166,7 +169,8 @@ def detect_board(): led_pin = 48 try: - i2c_bus = I2C(0, sda=Pin(16), scl=Pin(15)) + from machine import SoftI2C + i2c_bus = SoftI2C(sda=Pin(16), scl=Pin(15)) spi_bus = SPI(1, baudrate=40000000, polarity=0, phase=0, sck=Pin(12), mosi=Pin(11), miso=Pin(13)) import ili9341 display_instance = ili9341.ILI9341(spi_bus, cs=Pin(10), dc=Pin(46), bl=Pin(45), rst=None) diff --git a/lib/rtc_util.py b/lib/rtc_util.py index 9e98502..0277134 100644 --- a/lib/rtc_util.py +++ b/lib/rtc_util.py @@ -11,7 +11,8 @@ class PCF85063: def __init__(self, i2c=None): if i2c is None: # Default to ESP32-S3-RLCD-4.2 onboard I2C pins - self.i2c = I2C(0, sda=Pin(13), scl=Pin(14)) + from machine import SoftI2C + self.i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) else: self.i2c = i2c diff --git a/lib/shtc3_util.py b/lib/shtc3_util.py index 799ca34..b8915ea 100644 --- a/lib/shtc3_util.py +++ b/lib/shtc3_util.py @@ -13,7 +13,8 @@ class SHTC3: def __init__(self, i2c=None): if i2c is None: # Default to ESP32-S3-RLCD-4.2 onboard I2C pins - self.i2c = I2C(0, sda=Pin(13), scl=Pin(14)) + from machine import SoftI2C + self.i2c = SoftI2C(sda=Pin(13), scl=Pin(14)) else: self.i2c = i2c diff --git a/upload_files.py b/upload_files.py index 130e507..0d5af67 100644 --- a/upload_files.py +++ b/upload_files.py @@ -67,6 +67,8 @@ def main(): ("lib/battery_util.py", "lib/battery_util.py"), ("lib/rgb_led_util.py", "lib/rgb_led_util.py"), ("lib/audio_util.py", "lib/audio_util.py"), + ("lib/rtc_util.py", "lib/rtc_util.py"), + ("lib/shtc3_util.py", "lib/shtc3_util.py"), ("video_stream.py", "video_stream.py"), ("mcp_server.py", "mcp_server.py"), ("boot.py", "boot.py"),