Open-source weather station for astronomy
1from machine import Pin
2from time import sleep
3import math
4import dht
5
6sensor = dht.DHT22(Pin(0))
7
8def dew_point(tc, rh):
9 # tc: Temperature in Celsius
10 # rh: Relative humidity
11 # From: https://en.wikipedia.org/wiki/Dew_point#Calculating_the_dew_point
12 b = 17.625
13 c = 243.04 # degC
14 gamma = math.log(rh/100) + b*tc/(c+tc)
15 td = c*gamma/(b-gamma)
16 return td
17
18while True:
19 try:
20 sleep(1) # the DHT22 returns at most 1 measurement every 2s
21 sensor.measure() # Recovers measurements from the sensor
22 tc = sensor.temperature()
23 rh = sensor.humidity()
24 td = dew_point(tc, rh)
25 print(f"Temperature : {tc:.1f}°C")
26 print(f"Humidity : {rh:.1f}%")
27 print(f"Dew point : {td:.1f}°C")
28 except OSError as e:
29 print("Failed reception")