-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyHumidity.py
More file actions
30 lines (21 loc) · 806 Bytes
/
MyHumidity.py
File metadata and controls
30 lines (21 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import time
import board
import adafruit_dht
import MySensor
# Initial the dht device, with data pin connected to:
dhtDevice = adafruit_dht.DHT11(board.D10)
# you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio.
# This may be necessary on a Linux single board computer like the Raspberry Pi,
# but it will not work in CircuitPython.
# dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False)
def read():
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = dhtDevice.humidity
return MySensor.checkInput(humidity,-1,101)
except Exception as error:
#Fails a lot!
#print(error.args[0])
return MySensor.ERROR