import time
import machine
from machine import Pin, I2C
from machine_i2c_lcd import I2cLcd
from SSD1306 import SSD1306_I2C
from dht import DHT22
import network
time.sleep(1)
dht_sensor = DHT22(Pin(22, Pin.IN, Pin.PULL_UP))
pinR = Pin(19, Pin.OUT)
pinG = Pin(18, Pin.OUT)
pinB = Pin(17, Pin.OUT)
i2c_bus = I2C(0, sda=Pin(20), scl=Pin(21))
scr_addr = i2c_bus.scan()
lcd_scr = I2cLcd(i2c_bus, scr_addr[0], 2, 16)
latch_pin = Pin(1, Pin.OUT)
spi_bus = machine.SPI(0,
baudrate=1000000,
polarity=1,
phase=1,
bits=8,
firstbit=machine.SPI.MSB,
sck=machine.Pin(2),
mosi=machine.Pin(3),
miso=machine.Pin(16))
temp = 0
oldtemp = 0
humid = 0
oldhumid = 0
wlan_if = network.WLAN(network.STA_IF)
wlan_if.active(True)
[print(i) for i in wlan_if.scan()]
while True:
dht_sensor.measure()
temp = dht_sensor.temperature()
humid = dht_sensor.humidity()
if humid != oldhumid or temp != oldtemp:
lcd_scr.clear()
lcd_scr.putstr(f"Humidity: {humid}%\n")
lcd_scr.putstr(f"Temp: {temp:.1f}°C")
oldtemp = temp
oldhumid = humid
latch_pin.value(0)
if temp < 0:
spi_bus.write(bytearray([0b001]))
if temp > 30:
spi_bus.write(bytearray([0b100]))
if 0 < temp < 30:
spi_bus.write(bytearray([0b111]))
latch_pin.value(1)
time.sleep(0.5)
Loading
pi-pico-w
pi-pico-w
Loading
ssd1306
ssd1306