2

I have my Arduino Uno connected to the PC via USB when prototyping. I am developing a thermometer with memory, using DS18B20 sensors.

When PC is shut down, there is no power on the USB and the Arduino is off. Sometimes, when my PC is turned off for several hours and then, when I turn it on, the Arduino is started, but it behaves "strange" - the program is showing buggy values on the display, looking like if there is some bug in the sketch. However, when I upload the sketch again, it works fine.

The buggy values are the averages for the run, computed simply by summing a float and dividing by int. What I see is e.g. instead of seeing something around 23.5 I see 85.1. The current values read from the sensor look OK (show 23.5 as expected), but I cannot tell for sure if perhaps some value read early might be wrong.

It is not easy to reproduce, I see it only sometimes, always when powering Arduino on after several hours without power.

My first idea is either the sketch got corrupted during the long power down, or variables are initialized wrong, and the sample sum / sample count is not zero.

However I though the sketches are uploaded into the Flash RAM, which should be non-volatile according to the docs. Is there something obvious I am missing, some explanation why is the sketch working differently after long power down?

  • Are you storing any values to EEPROM? The problem sounds odd. The brown out detector on the AVR is supposed to ensure a clean power off, meaning no unpredictable behaviour. – user2973 Aug 6 '14 at 10:13
  • @user2973 No EEPROM. Moreover, I did not see the problem recently. I will watch the behaviour and will post if I learn anything new. – Suma Aug 6 '14 at 12:39
  • 1
    @mpflaga "Global and static variables are guaranteed to be initialized to 0 by the C standard. avr-gcc does this by placing the appropriate code into section .init4" – Gerben Aug 6 '14 at 14:30
  • 1
    They should be, cleared. I would print them and then clear them after a number of delays. To determine where the corruption is coming from. – mpflaga Aug 6 '14 at 14:46
  • 2
    Maxim DS18b20 data sheet, rev 042208, page 4, in a footnote to Table 1, says: *The power-on reset value of the temperature register is +85°C. Maybe a premature attempt to read? – JRobert Aug 9 '14 at 0:14
3

There should be no difference between turning on your computer and plugging in a USB cable. The embedded devices typically plugged into a USB ports such as mice, keyboards, wireless adapters, hard drives, etc don't have their FLASH memory corrupted when the computer is turned on so it is unlikely that your Arduino would.

To confirm there isn't something dodgy going on with the USB power supplied to the board, use a multimeter to monitor the 5V pin of the Arduino. If the voltage isn't going too high or too low then everything should be fine. Even if it goes too low, the microcontroller will have brown-out-detect enabled to shut it down in this event.

You mentioned a display. Perhaps, and this is pure speculation, some how the display is being initialised wrongly due to the Arduino being reset by USB connection. If the display has a general reset command, or a reset pin, enable it at the start of your sketch to ensure the display is in its default state.

  • The display is fine, it is displaying values with good format, only the values are wrong (min/max temperatures out of possible range). Those min/max are stored in SRAM only, therefore they were freshly calculated since the Arduino was powered. Multimeter shows clean 5.00 V, but I cannot rule out some short spike, I am not sure the multimeter would show that (the response of the one I have is not immediate). – Suma Aug 6 '14 at 12:44
  • Would you be able to post the code? Just in case there is something obvious. :P – geometrikal Aug 6 '14 at 13:26
  • The code seems too long to post here. If I will see it again, I will try to create an isolated example, if possible. – Suma Aug 6 '14 at 14:15
  • 1
    What is the temperature sensor in use? Is it a thermistor, or some chip with i2c/2wire or a dallas 1 wire? Maybe it requires some initialisation step and not being reset properly? – Danny Staple Aug 6 '14 at 16:54
  • @danny It is "dallas 1 wire" (DS18B20 - packed as sparkfun.com/products/11050). I am using milesburton.com/Dallas_Temperature_Control_Library to control it. – Suma Aug 7 '14 at 12:23
4

I researched this once when I was getting consistent, exactly 85 degC readings from my sensors. The Maxim DS18b20 data sheet (rev 042208, page 4, in a footnote to Table 1) says:

"The power-on reset value of the temperature register is +85°C.

Double check that the Arduino code is follows the sensor communication protocol correctly.

  • 1
    You are correct. I am using DS library in async mode - setWaitForConversion(false) - therefore the library is not handling the wait for conversion for me and I have to wait on my own. – Suma Aug 12 '14 at 18:05
  • 1
    Thanks for the the feedback, Suma. That's useful to know. – JRobert Aug 12 '14 at 20:34
0

The number you are seeing instead - 85.1, is suspiciously close to a Farenheit reading instead of Celcius - my guess is that there maybe a setup step for the Dallas DB18B20 that you are issuing too early for it, before it has initialised, and so it is ignoring it.

My guess would be steps being a unit setting, and a calibration setting.

can you attempt to wait a little time (perhaps 100 millis) before initialising the temperature control library.

  • Interesting theory, however DB18B20 is not providing F or C reading, it provides a raw value which needs to be recalculated in the program. However I agree it might be somthing with the setup wrong. – Suma Aug 8 '14 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.