-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholeddht.py
48 lines (34 loc) · 852 Bytes
/
oleddht.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import time
import machine
import ssd1306
import dht
#sensor.measure()
i2c = machine.I2C(machine.Pin(5), machine.Pin(4))
oled = ssd1306.SSD1306_I2C(64, 48, i2c)
oled.text('Micro', 0, 0)
oled.text('Python', 10, 10)
oled.text('Weather', 0, 30)
oled.text('Station', 10, 40)
oled.show()
sensor = dht.DHT22(machine.Pin(2))
time.sleep(2)
def monitor():
sensor.measure()
kelembaban = sensor.humidity()
suhu = sensor.temperature()
print('kelembaban: {0:0.2f}'.format(kelembaban))
datahumid = '{0:0.2f}'.format(kelembaban)
oled.fill(0)
oled.text('suhu', 0, 0)
oled.text(str('{0:0.2f}'.format(suhu)), 0, 10)
oled.text('humid', 0, 20)
oled.text(str(datahumid), 0, 30)
time.sleep(2)
oled.show()
#time.sleep(0.5)
#for i in range(1,20):
while True:
try:
monitor()
except OSError:
pass