Go Down

Topic: Speeding up readings of MULTIPLE SHT1x or SHT7x sensors (Read 1 time) previous topic - next topic

piashaw

Hi,

I was wondering if there is some way of reducing the time to get all the relevant measurementsf from multiple SHT7x sensors.

I am using the SHT1x library and reading 2 sensors but want to read more.

Just to do the following takes at least 5 seconds on an UNO. and this is only 2 sensors.

temperatureA = tempSensorA.readTemperatureC();
humidityA = tempSensorA.readHumidity();

temperatureB = tempSensorB.readTemperatureC();
humidityB = tempSensorB.readHumidity();

The rest of the code around works very fast. If I // these lines out, my other sensors are working very fast.

Thanks

Peter

KeithRB

How long does the data sheet say it takes to get a reading?

piashaw

The datasheet suggests not taking more than 1 reading per second to reduce the chance of self heating. But In reality I think it is quite a bit less. The point is that each time it reads a different sensor, it starts from the beginning.

I was wondering if there was a way with the same CLK signals etc read both / all sensors at the same time for example. So I could read them all in 1 second as opposed to 1 second or more for each?

I know that digitalwrites are fairly slow on the arduino and looking at the SHT1x code, it needs a lot of them,so I doubt without rewriting the library in C, it could be sped up much.

BUT there might be a way to read themall as I said at the same time. Unfortunately my programming skills and understanding all the datsheets isn't up to it. 

dc42

If you are using the library at https://github.com/practicalarduino/SHT1x/blob/master/SHT1x.cpp, you will see that there is a delay(10) call at line 140 of the .cpp file. Try using a much smaller delay such as delayMicroseconds(10), or even no delay.

You might also want to reduce the delay(10) at line 193 to delay(1), and increase the loop limit in line 191 from 100 to 1000.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

robtillaart


I had a similar problem with the DS18B20 long ago and I implemented an asynchronous call to the Dallas Temperature lib that allows me to do the following

Code: [Select]

...
void setup()
{
  Serial.begin(9600);
  if (!sensors1.getAddress(Thermometer1, 0)) Serial.println(F("Temp1 failure"));

  sensors1.setResolution(Thermometer1, 9);
  sensors1.setWaitForConversion(false);  // set async mode
  sensors1.requestTemperatures(); // request a new temperature reading
}

void loop()
{
 
  do some things

  if (millis() - lastTemp >=  94)
  {
    temp = sensors1.getTempC(Thermometer1);  // read the temperature
    sensors1.requestTemperatures();  // request a new measurement
    lastTemp = millis();
  }

   do other things here
}

The trick is that I decoupled the start of a new measurement and the reading of the result. By decoupling them I could save almost the complete conversion delay.

I don't know the SHT lib but a similar code addition might solve your performance issue.
Rob Tillaart

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

Go Up