Hello,
I created a project where I have an Arduino Mini 05 that through 1Wire connection, read 3 temperatures from 3 DS18B20 sensors.
Just for your understanding, it works perfeclty for some hours or a couple of days, then I start to get for all of them temperature = 0°. It's really strange.. the connection is a star and cables are long more or less 7-10 meters. I have others Arduino, same project, same hardware but with one only sensor and in that case it is working for months without a problem.
I'm using the serial for the cross communication so I can't debug too much, of course it could be software or hardware. About the software, I checked many times and it seems ok, I implemented all errors in my inter-communication but I never received any error from sensors.
This is the code:
switch (stepTemp) {
case 0:
if (TempDeviceNum > 0) {
requestTemperature(idTemp);
lastTempTime = millis();
stepTemp++;
}
break;
case 1:
if (temperatureReady(lastTempTime)) {
Temps[idTemp] = (int)(getTemperature(idTemp)*100.0);
idTemp++;
if (idTemp >= TempDeviceNum)
idTemp = 0;
stepTemp = 0;
}
break;
}
these are functions:
void requestTemperature(int idx){
//returns the temperature from one DS18B20 in DEG Celsius
ds.reset();
ds.select(adrOneWire[idx]);
ds.write(0x44); // start conversion, without parasite power on at the end
}
bool temperatureReady(unsigned long timeReq) {
unsigned long timeNow = millis();
switch (TEMP_RESOLUTION) {
case 12: // 750 ms
return ((timeNow - timeReq) >= 800);
case 11: // 375 ms
return ((timeNow - timeReq) >= 400);
case 10: // 187.5 ms
return ((timeNow - timeReq) >= 200);
case 9: // 93.75 ms
return ((timeNow - timeReq) >= 100);
default:
return (false);
}
// return (ds.read());
}
float getTemperature(int idx){
byte data[12];
ds.reset();
ds.select(adrOneWire[idx]);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
byte MSB = data[1];
byte LSB = data[0];
float tempRead = ((MSB << 8) | LSB);
float TemperatureSum = tempRead / 16.0;
return TemperatureSum;
}
Maybe you can see something...
The most important thing for me is understanding about harware, because I'm using the pin 8 and I have just a pull-up resistor 4k7.
I tried to add a resistor 120 ohm in series of every branch, i found on the web that it could stop the reflection of signal back.. but the behavior is the same.
The connection is with 3 wires, +5Vdc, segnal and GND.
Can you tell me what I can do from the hardware point of view?
Can I check the resistence between signal and +5Vdc? ..or to GND?
Can I add a terminator resistance where the sensor is placed?
Once I'm sure about hardware, then I will investigate deeply into the code.
Makes sense that I read temperature zero? why?
Thanks
Bye
Andrea