Skip to content

Commit 39b0825

Browse files
committed
Further (non-working) progress in SEN5X
1 parent 65ba676 commit 39b0825

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/detect/ScanI2CTwoWire.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,12 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
522522
case ICM20948_ADDR_ALT: // same as MPU6050_ADDR
523523
// ICM20948 Register check
524524
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x00), 1);
525-
prod = readSEN5xProductName(i2cBus, addr.address);
526525
if (registerValue == 0xEA) {
527526
type = ICM20948;
528527
logFoundDevice("ICM20948", (uint8_t)addr.address);
529528
break;
530529
} else {
530+
prod = readSEN5xProductName(i2cBus, addr.address);
531531
if (prod.startsWith("SEN55")) {
532532
type = SEN5X;
533533
logFoundDevice("Sensirion SEN55", addr.address);

src/modules/Telemetry/Sensor/SEN5XSensor.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ bool SEN5XSensor::sendCommand(uint16_t command, uint8_t* buffer, uint8_t byteNum
101101
}
102102

103103
// Transmit the data
104+
LOG_INFO("Beginning connection to SEN5X: 0x%x", address);
104105
bus->beginTransmission(address);
105106
size_t writtenBytes = bus->write(toSend, bufferSize);
106107
uint8_t i2c_error = bus->endTransmission();
@@ -164,17 +165,33 @@ uint8_t SEN5XSensor::CRC(uint8_t* buffer)
164165
return crc;
165166
}
166167

168+
bool SEN5XSensor::I2Cdetect(TwoWire *_Wire, uint8_t address)
169+
{
170+
_Wire->beginTransmission(address);
171+
byte error = _Wire->endTransmission();
172+
173+
if (error == 0) return true;
174+
else return false;
175+
}
176+
167177
int32_t SEN5XSensor::runOnce()
168178
{
179+
state = SEN5X_NOT_DETECTED;
169180
LOG_INFO("Init sensor: %s", sensorName);
170181
if (!hasSensor()) {
171182
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
172183
}
173184

174185
bus = nodeTelemetrySensorsMap[sensorType].second;
186+
address = (uint8_t)nodeTelemetrySensorsMap[sensorType].first;
175187
// sen5x.begin(*bus);
176188

177-
delay(50); // without this there is an error on the deviceReset function
189+
if (!I2Cdetect(bus, address)) {
190+
LOG_INFO("SEN5X ERROR no device found on adress");
191+
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
192+
}
193+
194+
delay(25);
178195

179196
if (!sendCommand(SEN5X_RESET)) {
180197
LOG_ERROR("SEN5X: Error reseting device");

src/modules/Telemetry/Sensor/SEN5XSensor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class SEN5XSensor : public TelemetrySensor
4949
bool sendCommand(uint16_t wichCommand, uint8_t* buffer, uint8_t byteNumber=0);
5050
uint8_t readBuffer(uint8_t* buffer, uint8_t byteNumber); // Return number of bytes received
5151
uint8_t CRC(uint8_t* buffer);
52+
bool I2Cdetect(TwoWire *_Wire, uint8_t address);
5253

5354
protected:
5455
virtual void setup() override;

0 commit comments

Comments
 (0)