From 18e08cd9f9132ec61254ae68fa8e7d88c77d6834 Mon Sep 17 00:00:00 2001 From: Paolo Leggio Date: Thu, 16 Oct 2025 15:06:10 +0200 Subject: [PATCH] Added support for BH1750 during i2C detection --- src/detect/ScanI2C.h | 3 ++- src/detect/ScanI2CTwoWire.cpp | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 2e602338c..e7bdf58c5 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -82,7 +82,8 @@ class ScanI2C BHI260AP, BMM150, TSL2561, - DRV2605 + DRV2605, + BH1750 } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index da2a57fee..ef438d27b 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -485,7 +485,26 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) SCAN_SIMPLE_CASE(LTR390UV_ADDR, LTR390UV, "LTR390UV", (uint8_t)addr.address); SCAN_SIMPLE_CASE(PCT2075_ADDR, PCT2075, "PCT2075", (uint8_t)addr.address); SCAN_SIMPLE_CASE(CST328_ADDR, CST328, "CST328", (uint8_t)addr.address); - SCAN_SIMPLE_CASE(LTR553ALS_ADDR, LTR553ALS, "LTR553ALS", (uint8_t)addr.address); + case LTR553ALS_ADDR: // 0x23 - condiviso con BH1750 + // Test first LTR553ALS (has identifiable registers) + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x86), 1); // Part ID register + if (registerValue == 0x92) { // LTR553ALS Part ID + type = LTR553ALS; + logFoundDevice("LTR553ALS", (uint8_t)addr.address); + } else { + // Test BH1750 - send power on command + i2cBus->beginTransmission(addr.address); + i2cBus->write(0x01); // Power On command + uint8_t bh1750_error = i2cBus->endTransmission(); + if (bh1750_error == 0) { + type = BH1750; + logFoundDevice("BH1750", (uint8_t)addr.address); + } else { + LOG_INFO("Device found at address 0x%x was not able to be enumerated", (uint8_t)addr.address); + } + } + break; + SCAN_SIMPLE_CASE(BHI260AP_ADDR, BHI260AP, "BHI260AP", (uint8_t)addr.address); SCAN_SIMPLE_CASE(SCD4X_ADDR, SCD4X, "SCD4X", (uint8_t)addr.address); SCAN_SIMPLE_CASE(BMM150_ADDR, BMM150, "BMM150", (uint8_t)addr.address);