Skip to content

Instantly share code, notes, and snippets.

@vitorio
Created January 15, 2024 01:18
Show Gist options
  • Save vitorio/0360b4af4d02a93d7bdb72e96df101d2 to your computer and use it in GitHub Desktop.
Save vitorio/0360b4af4d02a93d7bdb72e96df101d2 to your computer and use it in GitHub Desktop.
CO2 monitor using Pimoroni Breakout Garden + 1.12" Mono OLED SPI + SCD41 breakouts, MicroPython 1.21
from pimoroni import BREAKOUT_GARDEN_I2C_PINS
from pimoroni_i2c import PimoroniI2C
import breakout_scd41
from machine import Pin, SPI
import sh1107 # https://github.com/peter-l5/SH1107
import random
MESSAGE = '0000'
co2 = 0
i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS)
breakout_scd41.init(i2c)
breakout_scd41.start()
spi0 = SPI(0, baudrate=1_000_000, sck=Pin(18), mosi=Pin(19), miso=Pin(16))
display = sh1107.SH1107_SPI(128, 128, spi0, dc=Pin(16), res=Pin(20), cs=Pin(22), rotate=90)
display.contrast(0)
display.fill(0)
while True:
if breakout_scd41.ready():
co2, temperature, humidity = breakout_scd41.measure()
MESSAGE = f'{co2: <4}' # this is okay because it's a fixed-width font
display.fill(0)
OLED_X = random.randint(-7, 7)
OLED_Y = random.randint(-3, 103)
if co2 < 1000:
OLED_X = random.randint(-7, 40)
display.large_text(MESSAGE, OLED_X, OLED_Y, 4)
display.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment