-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPicoPim.py
57 lines (51 loc) · 1.64 KB
/
PicoPim.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
49
50
51
52
53
54
55
56
from machine import I2C, Pin, SPI
import uasyncio
from scd4x4 import SCD4X
from ST7735 import TFT
from seriffont import seriffont
i2c = I2C(0)
scd41 = SCD4X(i2c)
scd41.start_periodic_measurement()
co2 = 400
temp = 25
hum = 50
spi = SPI(0, baudrate=20000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(19),miso=Pin(16))
tft=TFT(spi,20,22,17)
tft.initr()
tft.rgb(True)
tft.rotation(1)
lcd = "on"
async def mesure():
if scd41.data_ready:
try:
global co2, temp, hum
co2 = round(scd41.co2)
temp = round(scd41.temperature, 1)
hum = round(scd41.relative_humidity, 1)
except:
pass
async def affichage(co2,temp,hum,state):
#### display the data on the prettty lcd
global lcd
if lcd == "on":
tft.fill(TFT.BLACK)
tft.text((10, 30), str(co2), TFT.WHITE, seriffont, 5, nowrap=True)
tft.text((10, 82), str(temp) + "C", TFT.WHITE, seriffont, 2, nowrap=True)
tft.text((90, 82), str(hum) + "%", TFT.WHITE, seriffont, 2, nowrap=True)
if state == True:
lcd = "off"
tft.on(False)
else:
if state == True:
lcd = "on"
tft.on()
tft.fill(TFT.BLACK)
tft.text((10, 30), str(co2), TFT.WHITE, seriffont, 5, nowrap=True)
tft.text((10, 82), str(temp) + "C", TFT.WHITE, seriffont, 2, nowrap=True)
tft.text((90, 82), str(hum) + "%", TFT.WHITE, seriffont, 2, nowrap=True)
async def main():
while 1:
uasyncio.create_task(mesure())
uasyncio.create_task(affichage(co2,temp,hum,state))
await uasyncio.sleep_ms(5100)
uasyncio.run(main())