Anyone use a DS18B20 and poll for complete conversion rather than wait?

So all of the sample code I see related to the onewire library issues the 0x44 begin conversion command then does a delay(1000). reading the data sheet this is needed if you are using parasitic power, but suggests that if you are using dedicated power you can poll for conversion complete (suggesting it can be done MUCH faster). in my application I don't mind powering the DS18B20 with a separate wire, so would like to not take the performance hit of such a long delay. I have been trying to do this, but can't seem to get it right.

Has anyone tried/done this? can you share sample code of how you did the polling for completion?

here is the code I am using for the conversion.

ds.reset(); // reset onewire bus
ds.select(addr); // ROM select
ds.write(0x44,0); // start conversion, 1=parasite power

//delay(750); // 750ms needed for parasite mode

ds.write_bit(1);
delay(5);
while(!ds.read_bit()){ //issue a write/read slot and poll to see if the conversion is done. the read_bit will return 1 when the conversion is done.
ds.write_bit(1);
delay(5);
}

present = ds.reset(); // 1=device(s) found
ds.select(addr); // ROM select
ds.write(0xBE); // read scratchpad

for ( i = 0; i < 9; i++) { // get 9-12 bytes
data = ds.read();

  • }*

My reading of the datasheet was that you need to allow 750 mSec for the conversion, even when not using parasitic power.

You can use the BlinkWithoutDelay example as a basis for code that requests a conversion and reads it 750 mSec later.

It won't run faster if you poll, you will probably be waiting somewhat less since you don't need to allow for the worst-case delay. However if you talk down the signal line during the sensor's ADC conversion you may inject more noise into the sensor and reduce the accuracy slightly. Using blink-without-delay techniques (non-blocking IO in other words) is always a good thing anyway.

I have some sensor boards that wake up, set the DS18B20 converting, go back to sleep for 800ms, wake up and retrieve the result, then send it via ISM wireless module, go back to sleep. Runs for months and months - if I polled for the result the processor would be active for .75 seconds every 5 minutes and reduce the battery life considerably...

The - MilesBurton.com - has examples to work in async mode to start conversion and do a read afterwards. Although the name says beta it is quite stable.

It is still on my todo list to detect the signal that conversion is ready - line goes up - and to test it (extensively) But as I do not need it myself it is quite low on the list ... But the above version should work.