@@ -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+
167177int32_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" );
0 commit comments