Go Down

Topic: DS18B20 750ms delay bypass? (Read 8 times) previous topic - next topic


May 22, 2011, 03:45 am Last Edit: May 22, 2011, 09:23 pm by Molehs Reason: 1
I have 5 sensors oneWire DS18B20's that work just fine, but after some research I found that the reason my menu buttons are sluggish is that there is a 750ms delay for conversion as discussed at the bottom of the first page of this thread:


So I see the code and I kinda can follow it, but I'm a bit intimidated as to how to shoe horn it into my sketch. His code uses a number of syntax that I'm not familiar with.

Is there a newer/better/streamlined method for not holding up the loop while it converts the temps for 750ms?

I'm kind of guessing not, but I figured I ask before spending the next week trying to figure out how to make it work in my 1600+ lines of code... :smiley-sad-blue:

Jack Christensen

May 22, 2011, 05:38 am Last Edit: May 22, 2011, 05:51 am by Jack Christensen Reason: 1
The technique I use is as follows. The main loop of the sketch has a section that gets executed once per second. It calls a function to read the temperature from the DS18B20. This function will start the temperature conversion on one call, then read the temperature on the next call and store the result in a global variable. Actually the function watches the time from a RTC, and starts the conversion when the seconds reach a certain value. So it only reads the sensor once per minute, but this would be easy to change for more (or less) frequent readings.

I'm using the OneWire library from http://www.pjrc.com/teensy/td_libs_OneWire.html
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/


Would you mind sharing your code for that section? If I had a 2nd example of how to code that it would be easier for me to decipher. Thanks.


For the 3.7.0 version of the - http://www.milesburton.com/Dallas_Temperature_Control_Library - I have introduced the asynchronuous reading of the DS18B20 family. Although officially still in beta I've not encountered any failure with the code yet. There are sample sketches showing how to use it.


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


So when it says "you can choose to manage the delay in your own code " does that mean setting the resolution? And if I have mine set to 9 for all 5 sensors it should take a very small am mount of time to convert the temps, i.e. less than 100ms according to the WaitingForConversion2 sketch serial print out?

This seems to work for the most part. Basically it would seem that at resolution I now have a 10% chance of hitting a button during the conversion. Does that sound about right?

Not quite the perfect solution but it does make it a lot more responsive than it was.

I'd still be interested if there was less codely way of using the scratchpad to effectively elimination the delay/lag, but for now I'm happy.

Thanks for the help guys.

Go Up