I am working on a project that is using the DS18B20 temperature sensor. I am reading the temperature perfectly but, the delay is now seriously slowing up my program. I have looked at various sites but no one seems to have a solution.
I have tried wiring the sensor in the normal mode (non Parasite power mode) but seems to make no difference.
Looking at the One-Wire and the Dallas codes I see there are several uses of the delay function. I was thinking of modifying the code to use time without delay instead. The other option would be to reduce the resolution as 12 bit is more than I need.
I was wondering if anyone else as come across the need to do other things whilst the temperature is being read and what solutions you came up with.
It is routine to do other things while the temperature is being read. Any delay you use is only to make sure the sensor has sufficient time to do its job.
It would help if you were less secretive about the frequency you need for the readings. The reason why you cannot find any solutions is probably because nobody else has the problem.
I bet you never had a good reason not to use normal power. The difference with using parasite power is that you ensure the sensor takes the longest possible time to get the reading, which is 750ms. I don't know why this is as it is an issue that doesn't merit investigating.
You are right in that reducing the resolution does increase the read time, and quite dramatically. Check the data sheets, that I don't have to hand, and if setting it to nine is still too slow, you are misunderstanding the problem or have the wrong type of sensor - most likely the former.
I assume you are talking about the conversion delay of up to 750ms.
If you setWaitForConversion( false ), then requestTemperature does not delay, it returns after telling the DS18B20 to start a conversion. Your sketch can continue processing other things.
When your sketch knows it has been long enough (depending on the resolution), it can call getTempC or getTempF to ask the DS18B20 for the temperature it converted while the sketch was doing those "other things".
This is really an example of doing Two Things At Once. The "timed" temperature conversion is one of those things: request it, then get it after 750ms. The other things your sketch needs to do can be timed like this, or performed continuously in loop.