Springe zum Inhalt oder Footer
SerloDie freie Lernplattform

3Display

ToDo

Bild
1import time
2import board
3import busio
4import adafruit_bmp280
5import adafruit_sht31d
6import adafruit_ssd1306
7
8# Create the I2C interface.
9i2c = busio.I2C(board.SCL, board.SDA)
10# Create the BMP280 Sensor class.
11bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
12# change this to match the location's pressure (hPa) at sea level
13bmp280.sea_level_pressure = 1013.25
14# Create the SHT31-D Sensor class.
15sht31d = adafruit_sht31d.SHT31D(i2c)
16# Create the SSD1306 OLED class.
17display = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c)
18
19while True:
20    print("Temperatur: {:.1f} C".format(bmp280.temperature))
21    print("Luftdruck:  {:.1f} hPa".format(bmp280.pressure))
22    print("Seehöhe:    {:.2f} m".format(bmp280.altitude))
23    print("Luftfeuchtigkeit: {:.1f} %".format(sht31d.relative_humidity))
24
25    display.fill(0)
26    display.text("Temperatur: {:.1f} C".format(bmp280.temperature)        , 0, 10, 1)
27    display.text("Luftdruck: {:.1f} hPa".format(bmp280.pressure)          , 0, 25, 1)
28    display.text("Seehoehe:  {:.2f} m".format(bmp280.altitude)            , 0, 40, 1)
29    display.text("Feuchtigkeit: {:.1f} %".format(sht31d.relative_humidity), 0, 55, 1)
30    display.show()
31
32    time.sleep(2)

Dieses Werk steht unter der freien Lizenz
CC BY-SA 4.0Was bedeutet das?