Merge pull request #10715 from fablabbcn/bugfix/detection-on-0x69-address

Fixes on 0x69 address detection
This commit is contained in:
oscgonfer
2026-07-03 15:55:54 +02:00
committed by GitHub
co-authored by GitHub
6 changed files with 35 additions and 64 deletions
+12 -60
View File
@@ -156,44 +156,11 @@ bool ScanI2CTwoWire::i2cCommandResponseLength(ScanI2C::DeviceAddress addr, uint1
}
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_AIR_QUALITY_SENSOR
// FIXME Move to a separate file for detection of sensors that require more complex interactions?
// For SEN5X detection
// Note, this code needs to be called before setting the I2C bus speed
// for the screen at high speed. The speed needs to be at 100kHz, otherwise
// detection will not work
String readSEN5xProductName(TwoWire *i2cBus, uint8_t address)
#include "../modules/Telemetry/Sensor/SEN5XSensor.h"
bool probeSEN5X(TwoWire *i2cBus, uint8_t address, ScanI2C::I2CPort port)
{
uint8_t cmd[] = {0xD0, 0x14};
uint8_t response[48] = {0};
i2cBus->beginTransmission(address);
i2cBus->write(cmd, 2);
if (i2cBus->endTransmission() != 0)
return "";
delay(20);
if (i2cBus->requestFrom(address, (uint8_t)48) != 48)
return "";
for (int i = 0; i < 48 && i2cBus->available(); ++i) {
response[i] = i2cBus->read();
}
char productName[33] = {0};
int j = 0;
for (int i = 0; i < 48 && j < 32; i += 3) {
if (response[i] >= 32 && response[i] <= 126)
productName[j++] = response[i];
else
break;
if (response[i + 1] >= 32 && response[i + 1] <= 126)
productName[j++] = response[i + 1];
else
break;
}
return String(productName);
SEN5XSensor sen5xsensor;
return sen5xsensor.probe(i2cBus, address, port);
}
#endif
@@ -861,33 +828,18 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
type = ICM42607P;
logFoundDevice("ICM-42607-P", (uint8_t)addr.address);
break;
}
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_AIR_QUALITY_SENSOR
String prod = "";
prod = readSEN5xProductName(i2cBus, addr.address);
if (prod.startsWith("SEN55")) {
type = SEN5X;
logFoundDevice("Sensirion SEN55", addr.address);
break;
} else if (prod.startsWith("SEN54")) {
type = SEN5X;
logFoundDevice("Sensirion SEN54", addr.address);
break;
} else if (prod.startsWith("SEN50")) {
type = SEN5X;
logFoundDevice("Sensirion SEN50", addr.address);
break;
}
#endif
if (addr.address == BMX160_ADDR) {
type = BMX160;
logFoundDevice("BMX160", (uint8_t)addr.address);
break;
} else {
} else if (registerValue == 0x68) { // WHO_AM_I from datasheet
type = MPU6050;
logFoundDevice("MPU6050", (uint8_t)addr.address);
break;
}
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_AIR_QUALITY_SENSOR
if (probeSEN5X(i2cBus, addr.address, port)) {
type = SEN5X;
logFoundDevice("SEN5X", addr.address);
break;
}
#endif
}
break;
@@ -39,4 +39,4 @@ class PMSA003ISensor : public TelemetrySensor
#endif
};
#endif
#endif
+1 -1
View File
@@ -52,4 +52,4 @@ class SCD30Sensor : public TelemetrySensor
meshtastic_AdminMessage *response) override;
};
#endif
#endif
+1 -1
View File
@@ -62,4 +62,4 @@ class SCD4XSensor : public TelemetrySensor
meshtastic_AdminMessage *response) override;
};
#endif
#endif
@@ -75,6 +75,24 @@ bool SEN5XSensor::findModel()
return true;
}
bool SEN5XSensor::probe(TwoWire *bus, uint8_t address, ScanI2C::I2CPort port)
{
LOG_INFO("SEN5X: probing sensor");
_bus = bus;
_address = address;
#ifdef SEN5X_I2C_CLOCK_SPEED
_port = port;
reClockI2C.setup(_bus, _port);
#endif /* SEN5X_I2C_CLOCK_SPEED */
if (!findModel()) {
LOG_DEBUG("SEN5X: can't find SEN5X model");
return false;
}
return true;
}
bool SEN5XSensor::sendCommand(uint16_t command)
{
uint8_t nothing;
+2 -1
View File
@@ -155,6 +155,7 @@ See: https://sensirion.com/resource/application_note/low_power_mode/sen5x
public:
SEN5XSensor();
bool probe(TwoWire *bus, uint8_t address, ScanI2C::I2CPort port);
virtual bool initDevice(TwoWire *bus, ScanI2C::FoundDevice *dev) override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
@@ -169,4 +170,4 @@ See: https://sensirion.com/resource/application_note/low_power_mode/sen5x
meshtastic_AdminMessage *response) override;
};
#endif
#endif