3.3. Temperature Humidity and Pressure Sensor¶
In order to run this example program, connect the Temperature Humidity and Pressure Sensor to an I2C port on whichever platform (GoPiGo3, GrovePi or BrickPi3) and then run the following script.
The source file for this example program can be found here on github.
from time import sleep
from di_sensors.easy_temp_hum_press import EasyTHPSensor
print("Example program for reading a Dexter Industries Temperature Humidity Pressure Sensor on an I2C port.")
my_thp = EasyTHPSensor()
while True:
# Read the temperature
temp = my_thp.safe_celsius()
# Read the relative humidity
hum = my_thp.safe_humidity()
# Read the pressure
press = my_thp.safe_pressure()
# Print the values
print("Temperature: {:5.3f} Humidity: {:5.3f} Pressure: {:5.3f}".format(temp, hum, press))
sleep(0.02)
The console output of this script should look like:
Example program for reading a Dexter Industries Temperature Humidity Pressure Sensor on an I2C port.
Temperature: 28.139 Humidity: 48.687 Pressure: 101122.691
Temperature: 28.141 Humidity: 48.698 Pressure: 101122.840
Temperature: 28.145 Humidity: 48.385 Pressure: 101122.900
Temperature: 28.151 Humidity: 48.715 Pressure: 101122.889
Temperature: 28.157 Humidity: 48.436 Pressure: 101122.607
Temperature: 28.163 Humidity: 48.464 Pressure: 101122.836
Temperature: 28.171 Humidity: 48.674 Pressure: 101123.085
Temperature: 28.180 Humidity: 48.120 Pressure: 101123.114