Refactor I2C device scanning and update display pin assignments
- Changed I2C scanning function to probe only expected device addresses, improving startup reliability. - Updated logging to provide clearer output for found and missing devices. - Modified I2C SDA and SCL pin assignments from 6 and 7 to 8 and 9, respectively, to accommodate hardware changes. - Added a timeout for I2C communication to enhance robustness.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -16,11 +16,12 @@ lib_deps =
|
||||
board_upload.flash_size = 16MB
|
||||
board_build.partitions = default_16MB.csv
|
||||
board_build.arduino.memory_type = qio_opi
|
||||
board_build.extra_flags = -DBOARD_HAS_PSRAM
|
||||
|
||||
; board_build.filesystem = spiffs
|
||||
|
||||
build_flags =
|
||||
-D BOARD_HAS_PSRAM
|
||||
-D ARDUINO_USB_CDC_ON_BOOT=1
|
||||
-D PB_VERSION=\"1.0.0\"
|
||||
-D PB_HOSTNAME=\"faceplant\"
|
||||
-D PB_TZ=\"America/New_York\"
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
#include "Display.h"
|
||||
|
||||
static void logI2CScan() {
|
||||
Serial.println("[Display] Scanning I2C bus...");
|
||||
static void logExpectedI2CDevices() {
|
||||
// Probe only expected addresses to reduce startup risk if the bus is unhealthy.
|
||||
const uint8_t addrs[] = {0x3C, 0x3D, 0x10, 0x36, 0x68}; // SH1106, VEML7700, MAX17048, MPU6050
|
||||
Serial.println("[Display] Probing expected I2C addresses...");
|
||||
uint8_t found = 0;
|
||||
for (uint8_t addr = 1; addr < 127; addr++) {
|
||||
for (uint8_t i = 0; i < sizeof(addrs); i++) {
|
||||
uint8_t addr = addrs[i];
|
||||
Wire.beginTransmission(addr);
|
||||
uint8_t err = Wire.endTransmission();
|
||||
Serial.print("[Display] 0x");
|
||||
if (addr < 16) Serial.print('0');
|
||||
Serial.print(addr, HEX);
|
||||
Serial.print(" -> ");
|
||||
if (err == 0) {
|
||||
Serial.print("[Display] I2C device @ 0x");
|
||||
if (addr < 16) Serial.print('0');
|
||||
Serial.println(addr, HEX);
|
||||
Serial.println("OK");
|
||||
found++;
|
||||
} else {
|
||||
Serial.print("ERR ");
|
||||
Serial.println(err);
|
||||
}
|
||||
}
|
||||
if (found == 0) Serial.println("[Display] No I2C devices found");
|
||||
if (found == 0) Serial.println("[Display] No expected I2C devices responded");
|
||||
}
|
||||
|
||||
void Display::begin() {
|
||||
@@ -27,8 +35,9 @@ void Display::begin() {
|
||||
Serial.println(OLED_ADDR, HEX);
|
||||
|
||||
Wire.begin(PIN_SDA, PIN_SCL);
|
||||
Wire.setTimeOut(20);
|
||||
delay(20);
|
||||
logI2CScan();
|
||||
logExpectedI2CDevices();
|
||||
|
||||
Serial.println("[Display] Initializing SH1106...");
|
||||
_ok = _oled.begin(OLED_ADDR, true);
|
||||
|
||||
@@ -18,8 +18,8 @@ public:
|
||||
bool displayEnabled() const { return _displayEnabled; }
|
||||
|
||||
private:
|
||||
static constexpr int PIN_SDA = 6;
|
||||
static constexpr int PIN_SCL = 7;
|
||||
static constexpr int PIN_SDA = 8;
|
||||
static constexpr int PIN_SCL = 9;
|
||||
static constexpr uint8_t OLED_ADDR = 0x3C; // try 0x3D if blank
|
||||
Adafruit_SH1106G _oled = Adafruit_SH1106G(128, 64, &Wire, -1);
|
||||
bool _ok = false;
|
||||
|
||||
Reference in New Issue
Block a user