Hello Everyone.
I am using Arduino Huzzah feather for SHT85 sensor. I have three such sensors connected to the Huzzah with the Adafruit TCA 9548A multiplexer.
The code that I have written records the temperature and humidity for all 3 sensors after every 3 seconds.
However I want each of the sensor to record temperature and humidity every second for 10 seconds and then print the average of the recorded values.
I am posting the code here. Any help is appreciated.
Tx.
// data and clock connections:
// TCA9548A SC2, SD2 ---- SHT85-1
// TCA9548A SC3, SD3 ---- SHT85-2
// TCA9548A SC4, SD4 ---- SHT85-3
#include <Wire.h>
#include "SHTSensor.h"
//creat one instance of the SHT85 sensor
SHTSensor sht1(SHTSensor::SHT3X);
SHTSensor sht2(SHTSensor::SHT3X);
SHTSensor sht3(SHTSensor::SHT3X);
#define TCAADDR 0x70
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
Wire.begin();
Serial.begin(9600);
delay(1000);
// intialize SHT85-1
tcaselect(2);
sht1.init();
// intialize SHT85-2
tcaselect(3);
sht2.init();
// intialize SHT85-3
tcaselect(4);
sht3.init();
}
void loop(void){
//switch (tcaselect(x)) and read the sensor values
tcaselect(2);
sht1.readSample();
Serial.print("SHT85-1 : ");
Serial.print("RH: ");
Serial.print(sht1.getHumidity(), 2);
Serial.print(" ");
Serial.print("T: ");
Serial.print(sht1.getTemperature(), 2);
//Serial.print("\n");
tcaselect(3);
sht2.readSample();
Serial.print(" SHT85-2: ");
Serial.print("RH: ");
Serial.print(sht2.getHumidity(), 2);
Serial.print(" ");
Serial.print("T: ");
Serial.print(sht2.getTemperature(), 2);
//Serial.print("\n");
tcaselect(4);
sht3.readSample();
Serial.print(" SHT85-3: ");
Serial.print("RH: ");
Serial.print(sht3.getHumidity(), 2);
Serial.print(" ");
Serial.print("T: ");
Serial.print(sht3.getTemperature(), 2);
Serial.print("\n");
delay(3000);
}