Created
March 21, 2022 10:20
-
-
Save lesp/0b8253306bb3e0090a9b219e0809cd43 to your computer and use it in GitHub Desktop.
Using a BME688 Temperature sensor with Pimoroni's Badger 2040. Code is based on the BME688 example, but with added Badger 2040 code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""BME688 / BME680 demo | |
This demo will work for both the BME680 and BME688. | |
""" | |
import time | |
from breakout_bme68x import BreakoutBME68X, STATUS_HEATER_STABLE | |
from pimoroni_i2c import PimoroniI2C | |
import badger2040 | |
import machine | |
badger = badger2040.Badger2040() | |
badger.update_speed(badger2040.UPDATE_FAST) | |
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} | |
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} | |
TEXT_SIZE = 0.7 | |
button_a = machine.Pin(badger2040.BUTTON_A, machine.Pin.IN, machine.Pin.PULL_DOWN) | |
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN) | |
bmp = BreakoutBME68X(i2c) | |
badger.pen(0) | |
badger.text("Tom's Temp Checker", 5, 20, TEXT_SIZE) | |
badger.update() | |
time.sleep(5) | |
badger.pen(15) | |
badger.clear() | |
while True: | |
temperature, pressure, humidity, gas, status, _, _ = bmp.read() | |
heater = "Stable" if status & STATUS_HEATER_STABLE else "Unstable" | |
print("{:0.2f}c, {:0.2f}Pa, {:0.2f}%, {:0.2f} Ohms, Heater: {}".format( | |
temperature, pressure, humidity, gas, heater)) | |
temp = str(round(temperature,1)) | |
press = str(round(pressure,1)) | |
humid = str(round(humidity,1)) | |
print(temp, press, humid) | |
badger.pen(0) | |
badger.text("Temperature "+temp+"C", 2, 10, TEXT_SIZE) | |
badger.text("Pressure "+press+"Pa", 2, 30, TEXT_SIZE) | |
badger.text("Humidity "+humid+"%", 2, 50, TEXT_SIZE) | |
badger.update() | |
time.sleep(5.0) | |
badger.pen(15) | |
badger.clear() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment