My error-checking routine is very long, and because I use it in a couple commercial products, I don’t have it posted anywhere. I’ll summarize it here in pseudo-code though:
- grab 3 consecutive readings from all sensors and store them in a 2d array (if using 3 sensors, then something like… float values[3][3])
- compare the 3 readings and validate or invalidate them if they are > or < than 5 degrees apart.
- check the readings for consecutive 32 or 185 Fahrenheit values (could mean that the data pin is shorted to GND or VCC)
- if any sensors have readings that are invalid, take all the readings again until they pass the test
- if any readings are invalid after 10 cycles, then set a boolean flag to notify the application. its very unusual for this to ever occur as I’ve found this error-check routine to completely solve this issue for me even with very long wire runs.
- add a timeout feature (depends on sensor resolution you’re using) just in case something hangs
- make sure this entire routine is encased in SINGLE_THREADED_BLOCK() because the bit-bang of the DS18B20 is timing-sensitive.
- add Particle.process() at the end of every loop of this routine so things don’t pop offline in case a sensor fails. if you’re using 750ms resolution, then this loop can take almost 2.5 seconds just to take 3 readings from all sensors. if it runs 10 times because of a failed sensor, then it will take 25 seconds. if your application can afford the resolution reduction, use the 375ms setting so things get sped up.
If you’re still having problems after using something like this, you can always set up an ATtiny85 or ATmega328 as your data acquisition front end and communicate with them over I2C so the Photon can grab all the sensor data. Like I mentioned before, I’ve found that the AVR chips don’t have the same symptoms that the Photon does with the DS18B20’s. Maybe that has something to do with the 5V tolerance of the GPIO pins on the Photon where the AVR chips’ high input maximum is VDD + 0.5V. Also, since the Photon does not have a hardware watchdog, they also serve as an external watchdog because they regularly handshake over I2C.
Hope that’s all helpful. If you need further assistance or you get stuck, happy to help guide you.