Raspinen
Posts: 2
Joined: Mon Feb 25, 2013 12:38 pm

DS18B20 and wrong temps

Mon Mar 04, 2013 9:04 am

I made temp logging system with Pi and 4 DS18b20. Sometimes it give wrong temperatures, room/out temp is -999.9 C or -0.1 C or -110 C. What is wrong, Raspberry or wires ?

Sorry my english.

ant_thomas
Posts: 115
Joined: Fri May 04, 2012 4:33 pm

Re: DS18B20 and wrong temps

Mon Mar 04, 2013 5:29 pm

Raspinen wrote:I made temp logging system with Pi and 4 DS18b20. Sometimes it give wrong temperatures, room/out temp is -999.9 C or -0.1 C or -110 C. What is wrong, Raspberry or wires ?

Sorry my english.
I occasionally get output of "-0.1 C" from my DS18B20 sensors too. It's not really bothered me but you could write in some sort of check that if the output is "-999.9 C or -0.1 C or -110 C" it gets the temperature again.

LesTroyer
Posts: 14
Joined: Wed Aug 29, 2012 2:38 pm

Re: DS18B20 and wrong temps

Tue Mar 05, 2013 5:58 pm

Are you waiting for the status to return 1 after sending a convert request??

ThomasH
Posts: 5
Joined: Wed Mar 06, 2013 9:06 pm

Re: DS18B20 and wrong temps

Wed Mar 06, 2013 9:33 pm

When I started with my 1-wire sensors I had frequent read errors.
After disabling some software / services like motion for the USB-cam, I do not a have a single read error anymore.
Hence I deem that there is a timing problem caused by too much load on the raspberry before.

Raspinen
Posts: 2
Joined: Mon Feb 25, 2013 12:38 pm

Re: DS18B20 and wrong temps

Thu Mar 07, 2013 2:52 pm

Thanks for help.

ThomasH
Posts: 5
Joined: Wed Mar 06, 2013 9:06 pm

Re: DS18B20 and wrong temps

Thu Mar 07, 2013 7:29 pm

Beside a range check you can do a check on the CRC as well.

PHP (provided by Heinz)

Code: Select all

$crcfail = preg_match("/NO/", $thermometerReadings);
while ($crcfail) {
   sleep(2);
   $thermometer = fopen($thermometer_sensor_path, "r");
   $thermometerReadings = fread($thermometer, filesize($thermometer_sensor_path));
   $crcfail = preg_match("/NO/", $thermometerReadings);
}
Python

Code: Select all

import re

def read_sensor(sensor_slave):

  device= '/sys/bus/w1/devices/' + str(sensor_slave) + '/w1_slave'

  with open(device, 'r') as searchfile:  # check CRC of Sensor
    for line in searchfile:
      if re.search( r'\NO\s', line, re.M|re.I):
        return(9999)   # return dummy value which is indicating read error

Return to “Automation, sensing and robotics”