I'm wondering if anyone else has seen the odd behaviour I have when using DS18B20 on one wire and a Mega2560 and what's the solution for it.
I've got a really simple sketch that will eventually form a part of something much bigger. There are six temperature sensors, each is sampled and the temperature is printed to serial monitor. Delay 2 seconds then loop and repeat.
It uses the Dallas temperature library and the One wire library and usually works just fine.
The sensors are supposed to work up to 135 deg.C but when one of them gets above about 75 deg.C it begins to show -127 degC, which is the default value for if the sensor isn't connected. Obviously a slightly duff sensor.
Problem is, all the other sensors on the bus then show -127 deg.C on the next loop. That's going to stuff things up royally when I've got about fifteen sensors on the same digital pin and I'm using some of the outputs for control purposes.
Has anyone come across this before and more importantly, is there a software fix to ignore the output of a rogue sensor and prevent it from corrupting the other values?
Yep, I have the 4.7k pullup. I'm already sampling each sensor sequentially using the address rather than getting them all globally and sorting them afterwards.
T1 = sensors.getTempC(sensor1); ................. and so on up to T6.
// Bla Bla Bla
// s e t u p ( )
//********************************************^************************************************
void setup()
{
// put your setup code here, to run once:
//*********************************
//Start the DS18B20 sensors
sensors.begin();
//start a new conversion request
sensors.setWaitForConversion(false);
sensors.requestTemperatures();
sensors.setWaitForConversion(true);
} //END of setup()
// l o o p ( )
//********************************************^************************************************
void loop()
{
// put your main code here, to run repeatedly:
//************************************************ T I M E R read temperatures
//is it time to read the temperature sensors ?
if (millis() - readTempTime >= 2000ul)
{
//restart this TIMER
readTempTime = millis();
//**********************************
//read all temperature sensors
temperatureFreezerC = sensors.getTempC(freezerAddress);
temperatureOutsideC = sensors.getTempC(outsideAddress);
// etc.
//**********************************
//start a new conversion request
sensors.setWaitForConversion(false);
sensors.requestTemperatures();
sensors.setWaitForConversion(true);
} //END of read temperatures TIMER
//************************************************
//other non blocking code
//************************************************
} //END of loop()
I moved your topic to an appropriate forum category @oldnewby.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.