diff --git a/src/helpers/sensors/EnvironmentSensorManager.cpp b/src/helpers/sensors/EnvironmentSensorManager.cpp index bb675c276..42dc3e557 100644 --- a/src/helpers/sensors/EnvironmentSensorManager.cpp +++ b/src/helpers/sensors/EnvironmentSensorManager.cpp @@ -189,9 +189,26 @@ bool EnvironmentSensorManager::begin() { #endif #if ENV_INCLUDE_BME280 - if (BME280.begin(TELEM_BME280_ADDRESS, TELEM_WIRE)) { - MESH_DEBUG_PRINTLN("Found BME280 at address: %02X", TELEM_BME280_ADDRESS); + uint8_t bme280_address = TELEM_BME280_ADDRESS; + bool bme280_ok = BME280.begin(bme280_address, TELEM_WIRE); + if (!bme280_ok) { + const uint8_t alt_address = (TELEM_BME280_ADDRESS == 0x76) ? 0x77 : 0x76; + bme280_ok = BME280.begin(alt_address, TELEM_WIRE); + if (bme280_ok) { + bme280_address = alt_address; + MESH_DEBUG_PRINTLN("Found BME280 at alternate address: %02X", alt_address); + } + } + if (bme280_ok) { + MESH_DEBUG_PRINTLN("Found BME280 at address: %02X", bme280_address); MESH_DEBUG_PRINTLN("BME sensor ID: %02X", BME280.sensorID()); + // Use forced mode to align with takeForcedMeasurement() in querySensors(). + BME280.setSampling(Adafruit_BME280::MODE_FORCED, + Adafruit_BME280::SAMPLING_X1, // temperature + Adafruit_BME280::SAMPLING_X1, // pressure + Adafruit_BME280::SAMPLING_X1, // humidity + Adafruit_BME280::FILTER_OFF, + Adafruit_BME280::STANDBY_MS_1000); BME280_initialized = true; } else { BME280_initialized = false; diff --git a/variants/xiao_nrf52/XiaoNrf52Board.cpp b/variants/xiao_nrf52/XiaoNrf52Board.cpp index 396880abc..e5742a40d 100644 --- a/variants/xiao_nrf52/XiaoNrf52Board.cpp +++ b/variants/xiao_nrf52/XiaoNrf52Board.cpp @@ -34,6 +34,9 @@ void XiaoNrf52Board::begin() { #endif #if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL) + // Enable weak pullups for external I2C devices if no onboard pullups exist. + pinMode(PIN_WIRE_SDA, INPUT_PULLUP); + pinMode(PIN_WIRE_SCL, INPUT_PULLUP); Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL); #endif @@ -93,4 +96,4 @@ bool XiaoNrf52Board::startOTAUpdate(const char *id, char reply[]) { return true; } -#endif \ No newline at end of file +#endif diff --git a/variants/xiao_nrf52/platformio.ini b/variants/xiao_nrf52/platformio.ini index edbf6275e..34a6fcdf6 100644 --- a/variants/xiao_nrf52/platformio.ini +++ b/variants/xiao_nrf52/platformio.ini @@ -24,8 +24,8 @@ build_flags = ${nrf52_base.build_flags} -D SX126X_DIO3_TCXO_VOLTAGE=1.8 -D SX126X_CURRENT_LIMIT=140 -D SX126X_RX_BOOSTED_GAIN=1 - -D PIN_WIRE_SCL=D6 - -D PIN_WIRE_SDA=D7 + -D PIN_WIRE_SDA=D6 + -D PIN_WIRE_SCL=D7 -D PIN_USER_BTN=PIN_BUTTON1 -D DISPLAY_CLASS=NullDisplayDriver build_src_filter = ${nrf52_base.build_src_filter} @@ -106,4 +106,4 @@ build_flags = ; -D MESH_PACKET_LOGGING=1 ; -D MESH_DEBUG=1 build_src_filter = ${Xiao_nrf52.build_src_filter} - +<../examples/simple_room_server/*.cpp> \ No newline at end of file + +<../examples/simple_room_server/*.cpp> diff --git a/variants/xiao_nrf52/variant.h b/variants/xiao_nrf52/variant.h index 3f4d7afeb..9f3cf8320 100644 --- a/variants/xiao_nrf52/variant.h +++ b/variants/xiao_nrf52/variant.h @@ -111,11 +111,11 @@ static const uint8_t A5 = PIN_A5; // Wire Interfaces #define WIRE_INTERFACES_COUNT (1) -// #define PIN_WIRE_SDA (17) // 4 and 5 are used for the sx1262 ! -// #define PIN_WIRE_SCL (16) // use WIRE1_SDA +#define PIN_WIRE_SDA (6) // D4/D5 used by SX1262, move I2C to D6/D7 +#define PIN_WIRE_SCL (7) -// static const uint8_t SDA = PIN_WIRE_SDA; -// static const uint8_t SCL = PIN_WIRE_SCL; +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; //#define PIN_WIRE1_SDA (17) //#define PIN_WIRE1_SCL (16)