from machine import Pin, SoftI2C # pour créer l'i2c
import ssd1306
import writer
import calibri40
import time
import dht
import machine
#instanciation_i2c à partir de SoftI2C
i2c = SoftI2C(scl=Pin(7), sda=Pin(6), freq=400000) #broches utilisées 21 et 20
#instanciation_oled
oled = ssd1306.SSD1306_I2C(128,64,i2c)
# instanciation Writer avec le oled et la police
wri = writer.Writer(oled, calibri40)
#instanciation capteur
d = dht.DHT22(machine.Pin(22))
import framebuf
thermo_buf = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1e\x00\x00\x00\x7f\x80\x00\x00\xe0\xc0\x00\x00\xc0\xe0\x00\x01\x80\x67\xc0\x01\x80\x67\xc0\x01\x80\x60\x00\x01\x8c\x60\x00\x01\x9e\x67\xc0\x01\x9e\x67\xc0\x01\x9e\x60\x00\x01\x9e\x60\x00\x01\x9e\x67\xc0\x01\x9e\x67\xc0\x01\x9e\x60\x00\x01\x9e\x60\x00\x01\x9e\x67\xc0\x01\x9e\x67\xc0\x01\x9e\x60\x00\x01\x9e\x60\x00\x01\x9e\x67\xc0\x01\x9e\x67\xc0\x01\x9e\x60\x00\x01\x9e\x60\x00\x03\x9e\x70\x00\x0f\x1e\x38\x00\x0e\x3f\x1c\x00\x1c\xff\xce\x00\x18\xff\xc6\x00\x19\xff\xe7\x00\x19\xff\xe7\x00\x19\xff\xe7\x00\x19\xff\xe6\x00\x1c\xff\xc6\x00\x0c\x7f\x8c\x00\x0e\x0c\x1c\x00\x07\x80\x78\x00\x03\xff\xe0\x00\x00\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
fb_thermo = framebuf.FrameBuffer(thermo_buf, 30, 47, framebuf.MONO_HLSB)
degre_buf = bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x78\x0f\x80\x48\x3f\xc0\x48\x70\xe0\x48\xc0\x60\x78\xc0\x60\x00\xc0\x60\x00\xc0\x00\x00\xc0\x00\x00\xc0\x00\x00\xc0\x00\x00\xc0\x60\x00\x60\x60\x00\x70\xe0\x00\x3f\xc0\x00\x0f\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00')
fb_degres = framebuf.FrameBuffer(degre_buf, 23, 21, framebuf.MONO_HLSB)
while True :
d.measure()
temp= str(int(d.temperature()))
print(temp)
oled.fill(0)
wri.set_textpos(45,20) #position fixe
wri.printstring(temp)
oled.rect(0, 0, 127, 63, 1)
oled.blit(fb_thermo, 10, 10)
oled.blit(fb_degres, 100, 10)
oled.show()
time.sleep(0.1)
Loading
ssd1306
ssd1306