OneWire Temp will read -160F

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
clete2
 
Posts: 30
Joined: Wed Oct 28, 2009 11:48 am

OneWire Temp will read -160F

Post by clete2 »

I'm using a DS18B20 sensor to measure temperature outside my window. I am basically using one of the OneWire example scripts, only modified for my use.

I just call the code in here to get temperatures and print them out. I do this on a 15-second basis. Every 6-30 hours it runs, it will just start reporting ~-160F and I cannot fix it. I later added some hack code to call the setup method every 75 times I read temperatures, to no avail. What could be happening here? I have a TMP36 that I read alongside this one and I don't experience issues with it.

I'm not using parasite power.

Code: Select all

// Data wire is plugged into port 8 on the Arduino
#define ONE_WIRE_BUS 8

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// arrays to hold device address
DeviceAddress insideThermometer;

int resetCounter;

void oneWireSetup(void)
{
  resetCounter = 0;
  // start serial port
  //Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // locate devices on the bus
  Serial.print("Locating devices...");
  sensors.begin();
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  
  // assign address manually.  the addresses below will beed to be changed
  // to valid device addresses on your bus.  device address can be retrieved
  // by using either oneWire.search(deviceAddress) or individually via
  // sensors.getAddress(deviceAddress, index)
  //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };

  // Method 1:
  // search for devices on the bus and assign based on an index.  ideally,
  // you would do this to initially discover addresses on the bus and then 
  // use those addresses and manually assign them (see above) once you know 
  // the devices on your bus (and assuming they don't change).
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  
  // method 2: search()
  // search() looks for the next device. Returns 1 if a new address has been
  // returned. A zero might mean that the bus is shorted, there are no devices, 
  // or you have already retrieved all of them.  It might be a good idea to 
  // check the CRC to make sure you didn't get garbage.  The order is 
  // deterministic. You will always get the same devices in the same order
  //
  // Must be called before search()
  //oneWire.reset_search();
  // assigns the first address found to insideThermometer
  //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  // set the resolution to 12 bit (Each Dallas/Maxim device is capable of several different resolutions)
  sensors.setResolution(insideThermometer, 12);
 
  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC); 
  Serial.println();
}

// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  // method 1 - slower
  //Serial.print("Temp C: ");
  //Serial.print(sensors.getTempC(deviceAddress));
  //Serial.print(" Temp F: ");
  //Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit

  // method 2 - faster
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");
  Serial.print(tempC);
  Serial.print(" Temp F: ");
  Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit
}

float getOneWireTempF(void)
{ 
  resetCounter++;
  if(resetCounter == 75){
      oneWire.reset();
      delay(200);
      oneWireSetup();
  }
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  
  // It responds almost immediately. Let's print out the data
  printTemperature(insideThermometer); // Use a simple function to print out the data

  return sensors.getTempF(insideThermometer);
}

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 11; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: OneWire Temp will read -160F

Post by Franklin97355 »

Are you using the pullup resistor?

User avatar
clete2
 
Posts: 30
Joined: Wed Oct 28, 2009 11:48 am

Re: OneWire Temp will read -160F

Post by clete2 »


User avatar
clete2
 
Posts: 30
Joined: Wed Oct 28, 2009 11:48 am

Re: OneWire Temp will read -160F

Post by clete2 »

In the picture I have grounded the positive line (forgot I did that). It made no difference using parasite power or not.

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: OneWire Temp will read -160F

Post by adafruit_support_bill »

Every 6-30 hours it runs, it will just start reporting ~-160F and I cannot fix it.
It reports correct temperatures up to that point?
I later added some hack code to call the setup method every 75 times I read temperatures, to no avail.
So resetting the device/library doesn't fix it. What about resetting the Arduino?

User avatar
clete2
 
Posts: 30
Joined: Wed Oct 28, 2009 11:48 am

Re: OneWire Temp will read -160F

Post by clete2 »

1) Yes, it is accurate up until that point.
2) Yes. I manually push the reset button. I don't know of a way to reset by code.

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: OneWire Temp will read -160F

Post by adafruit_support_bill »

If an Arduino reset fixes it, but a oneWire reset does not, then I would suspect that the problem is not with the device. Maybe a memory leak or something?

Is the -160F reading constant? Or does it vary somewhat.

User avatar
clete2
 
Posts: 30
Joined: Wed Oct 28, 2009 11:48 am

Re: OneWire Temp will read -160F

Post by clete2 »

Constant. I will check next time it does this to get the exact temperature.

User avatar
clete2
 
Posts: 30
Joined: Wed Oct 28, 2009 11:48 am

Re: OneWire Temp will read -160F

Post by clete2 »

What kind of memory management should I be doing in my scripts? I've never use malloc or free in the scripts.

Really what I'm using now is a few examples strung together (Pachube, OneWire, your TMP36 example, a floatToString function, and one script I wrote myself to hit a webpage), so I don't doubt that it could be a memory problem; I just don't know how I'm supposed to be managing memory in Arduino-land.

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: OneWire Temp will read -160F

Post by adafruit_support_bill »

The Arduino dialect of C++ discourages dynamic allocation - although it might be something going on in a library. I'm not familiar with all the libraries involved in your sketch. But the symptoms sound like something getting corrupted after some time.

What happens if you let it run for longer? Is there any further degradation?

User avatar
clete2
 
Posts: 30
Joined: Wed Oct 28, 2009 11:48 am

Re: OneWire Temp will read -160F

Post by clete2 »

I would upload the whole sketch but it might not do much good. I think the problem may lie in the OneWire library since the TMP36 keeps going just fine.

I once let it run for 9 or so hours in a broken state. The TMP36 never became corrupted and kept reporting properly. Of course, it completely messed up my Pachube page with the DS18B20, so I reset Pachube entirely. I watched and saw it connecting via RX and TX lights on the Ethernet shield. Everything was still going, except the DS18B20.

Is there a good way to reset the Arduino via software? I hate to use a hack like that. I may rewrite all the code from scratch; could be I'm doing something incorrectly. I hacked the code together as it is, in an attempt to get it all running quickly. (you see irony in this -- I hate to use a hack, but what I have is a hack). ;)

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: OneWire Temp will read -160F

Post by adafruit_support_bill »

Is there a good way to reset the Arduino via software?
http://www.arduino.cc/cgi-bin/yabb2/YaB ... 1242847196

User avatar
clete2
 
Posts: 30
Joined: Wed Oct 28, 2009 11:48 am

Re: OneWire Temp will read -160F

Post by clete2 »

Thanks. I'll try the watchdog timer.

User avatar
clete2
 
Posts: 30
Joined: Wed Oct 28, 2009 11:48 am

Re: OneWire Temp will read -160F

Post by clete2 »

So I have set the watchdog timer, but when I do that, it will just get stuck in an endless reboot.

I tried to upload the bootloader here using a USBTinyISP:
http://www.ladyada.net/library/arduino/bootloader.html

It uploaded successfully but afterward I am unable to program the Arduino using the IDE. The IDE will say that the programmer is unreachable. I Googled around but didn't find anything useful.

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: OneWire Temp will read -160F

Post by adafruit_support_bill »

When using the Adaboot bootloader, you need to select Dueminalove 328 as your board type.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”