Hi! I’ve been using RaspberryPi + GrovePi to gather temperature and humidity data using the DHT sensor. I am making an outdoor case that can protect the device from the weather while at the same time can still retrieve the real data from the atmosphere, not only from inside of the box.
So, for some reason, I got an idea to run 2 sensors at the same time (1 sensor out of the box, 1 sensor in the box) so that I can see if they got the same data and make a calibration. There are 2 cases that I tried:
- Run the two sensors consecutively
- Run the two sensors simultaneously
The script for the first case is:
import grovepi
import math
import time
sensor1 = 3
sensor2 = 4
blue = 0
white = 1
with open('TH.csv', 'a') as th:
th.write("utc;temperature(1);humidity(1);temperature(2);humidity(2)" + '\n')
while True:
try:
[temp1, humidity1] = grovepi.dht(sensor1, white)
[temp2, humidity2] = grovepi.dht(sensor2, white)
if not math.isnan(temp1) or math.isnan(humidity1) or math.isnan(temp2) or math.isnan(humidity2):
utc=time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
print(utc + ";" + "temp1 = %.02f C humidity1 =%.02f%%"%(temp1, humidity1) + '\n' + utc + ";" + "temp2 = %.02f C humidity2 =%.02f%%"%(temp2, humidity2))
th.write(utc + ';' + str(temp1) + ';' + str(humidity1) + ";" + str(temp2) + ';' + str(humidity2) + '\n')
time.sleep(1)
except IOError:
print("Error")
and the scripts for the second case are:
import grovepi
import math
import time
sensor1 = 3
blue = 0
white = 1
with open('TH1.csv', 'a') as th1:
while True:
try:
[temp1, humidity1] = grovepi.dht(sensor1, white)
if not math.isnan(temp1) and not math.isnan(humidity1):
time1=time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
print(time1 + "temp1 = %.02f C humidity1 =%.02f%%"%(temp1, humidity1))
th1.write(time1 + ';' + str(temp1) + ';' + str(humidity1) + '\n')
time.sleep(1)
except IOError:
print("Error")
and
import grovepi
import math
import time
sensor2 = 4
blue = 0
white = 1
with open('TH2.csv', 'a') as th2:
while True:
try:
[temp2, humidity2] = grovepi.dht(sensor2, white)
if not math.isnan(temp2) and not math.isnan(humidity2):
time2=time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
print(time2 + "temp2 = %.02f C humidity2 =%.02f%%"%(temp2, humidity2))
th2.write(time2 + ';' + str(temp2) + ';' + str(humidity2) + '\n')
time.sleep(1)
except IOError:
print("Error")
The first case print the result as 1 CSV file and the later 2 separate CSV files.
However, running both cases, the readings from both sensors always show the same value, even when one of the sensor is isolated and I blew the other one.
My question is, is it even possible to run 2 identical DHT sensors at the same time? If yes, how to get the readings from these 2 separate sensor?
Many thanks in advance!