Toggle Navigation
Hatchery
Eggs
Grove BME280 Baro/Hygro/Thermo
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
from machine import I2C, Pin from grove_bme280_barohygrothermo import bme280 import ugfx, time def main(): ugfx.init() ugfx.orientation(90) ugfx.set_lut(ugfx.LUT_FULL) ugfx.clear(ugfx.WHITE) ugfx.string(0, 20, "Initializing", "Roboto_Regular12", ugfx.BLACK) ugfx.flush() i2c = I2C(sda=Pin(26), scl=Pin(27), freq=100000) sensor = bme280.BME280(i2c=i2c) ugfx.string(0, 35, "Done!", "PermanentMarker22", ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() time.sleep(3) ugfx.set_lut(ugfx.LUT_FASTEST) ugfx.string(0, 35, "BME280", "PermanentMarker22", ugfx.BLACK) ugfx.string(0, 80, "Temperature:", "Roboto_Regular12", ugfx.BLACK) ugfx.circle(98, 108, 3, ugfx.BLACK) ugfx.string(100, 100, "C", "PermanentMarker22", ugfx.BLACK) ugfx.string(0, 150, "Pressure:", "Roboto_Regular12", ugfx.BLACK) ugfx.string(0, 220, "Humidity:", "Roboto_Regular12", ugfx.BLACK) ugfx.flush() while True: pressure = sensor.pressure temperature = sensor.temperature humidity = sensor.humidity ugfx.area(0, 100, 90, 35, ugfx.WHITE) ugfx.area(0, 170, 128, 35, ugfx.WHITE) ugfx.area(0, 240, 128, 35, ugfx.WHITE) ugfx.string(0, 100, ("%.2f" % temperature).replace(".",","), "PermanentMarker22", ugfx.BLACK) ugfx.string(0, 170, ("%.2f hPa" % pressure).replace(".",","), "PermanentMarker22", ugfx.BLACK) ugfx.string(0, 240, ("%.2f %%" % humidity).replace(".",","), "PermanentMarker22", ugfx.BLACK) ugfx.flush() time.sleep(1) main()