Closed gaboflowers closed 3 years ago
According to the datasheet waiting 750 ms (12 bit assumed) guarantees all will be ready. so a simple delay or while loop will do the trick. So if you wait 750 ms delay(750);
after you started the first one you can start reading them.
[pseudo code]
uint32_t start;
void loop()
{
...
start = millis();
for (int i = 0; i < sensorCount; i++) requestTemperatureByAddress(address[i]);
while (millis() - start < 750); // blocking wait or // delay(750);
for (int i = 0; i < sensorCount; i++)
{
float t = getTempC(address[i]);
process(t); // whatever
}
...
}
Better is not to block your code like
bool requestInProgress = false;
uint32_t start;
void loop()
{
if (requestInProgress == false)
{
requestInProgress = true;
start = millis();
for (int i = 0; i < sensorCount; i++) requestTemperatureByAddress(address[i]);
}
if (requestInProgress && (millis() - start >= 750))
{
for (int i = 0; i < sensorCount; i++)
{
float t = getTempC(address[i]);
process(t); // whatever
}
}
...
}
void requestTemperatures(void);
We must measure from several DS18B20 at once, so we
setWaitForConversion(false)
, run the multiplerequestTemperaturesByAddress()
needed, and then useblockTillConversionComplete
manually after the last request.