Skip to content

Conversation

@gaboflowers
Copy link
Contributor

We must measure from several DS18B20 at once, so we setWaitForConversion(false), run the multiple requestTemperaturesByAddress() needed, and then use blockTillConversionComplete manually after the last request.

@RobTillaart
Copy link
Contributor

RobTillaart commented Oct 7, 2020

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
    }
  }
 ...
}
  1. If you time test the sensors you might tweak 750 with a lower value representing the 'slowest' sensor.
  2. If all sensors are on one bus a single call might be more efficient
void requestTemperatures(void); 

@milesburton milesburton merged commit 03159c4 into milesburton:master Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants