You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.13
When connecting to the particle sensor using the uart, the sensor will after about a minute fail continuously and not give any output. Removing this check allows the sensor to eventually resolve and continue functioning:
It looks like the sensor won't send any more data until the bogus bytes are read. After they are consumed the sensor will continue forward, fail the checksum and re-stabilize.
Although, there may be other situations that could cause this deadlock to arise, like a noisy serial connection. I think both of these changes might be worth making, the consequence being some reads might fail the checksum, but as it is the reads fail continuously anyway.
This is the approach I ended up taking. It's an alternative to #10 but incorporates those fixes and fixes this issue. It also simplifies the code (aside from reusing the buffer). Hopefully I didn't overlook anything / introduce any bugs but it seems to be working and I tested a few cases. Sorry its not a PR I just ran out of time!
uint16_tconsumed=0;
uint8_tbuffer[32];
boolread_aqi(PM25_AQI_Data*data) {
// check that the aqi data structure is allocatedif (!data) {
return false;
}
// recycle any failed buffer if possible, by finding a new start byteif (consumed==32) {
uint16_ti, j;
for (i=1; i<32&&buffer[i] !=0x42; i++) {}
consumed=32-i;
for (j=0; j<consumed; j++) {
buffer[j] =buffer[i+j];
}
}
// attempt to read a complete messagewhile (Serial1.available() &&consumed<32) {
buffer[consumed] =Serial1.read();
consumed++;
}
// if unable to read enough bytes, exit and continue next timeif (consumed<32) {
return false;
}
// check the start bytesif (buffer[0] !=0x42||buffer[1] !=0x4d) {
return false;
}
// compute check sumuint16_tsum=0;
for (uint8_ti=0; i<30; i++) {
sum+=buffer[i];
}
// the data comes in endian'd, this solves it so it works on all platformsuint16_tbuffer_u16[15];
for (uint8_ti=0; i<15; i++) {
buffer_u16[i] =buffer[2+i*2+1];
buffer_u16[i] += (buffer[2+i*2] << 8);
}
// put it into a nice struct :)memcpy((void*)data, (void*)buffer_u16, 30);
// validate the checksumif (sum!=data->checksum) {
return false;
}
// success!consumed=0;
return true;
}
When connecting to the particle sensor using the uart, the sensor will after about a minute fail continuously and not give any output. Removing this check allows the sensor to eventually resolve and continue functioning:
Adafruit_PM25AQI/Adafruit_PM25AQI.cpp
Lines 117 to 121 in ba3f10c
It looks like the sensor won't send any more data until the bogus bytes are read. After they are consumed the sensor will continue forward, fail the checksum and re-stabilize.
This PR would help prevent the issue: #10
Although, there may be other situations that could cause this deadlock to arise, like a noisy serial connection. I think both of these changes might be worth making, the consequence being some reads might fail the checksum, but as it is the reads fail continuously anyway.
Also in the forums it looks like these issues have been what these two people refer to, and sounds like it caused them to return their sensors:
https://forums.adafruit.com/viewtopic.php?t=200668&sid=ddf03cb5dfe45415ac3b76f599fcfa4e&start=15
The text was updated successfully, but these errors were encountered: