Skip to content

Instantly share code, notes, and snippets.

@wildestpixel
Last active March 12, 2021 08:03
Show Gist options
  • Save wildestpixel/6b85cacbad8c1a62dc76eefab8690278 to your computer and use it in GitHub Desktop.
Save wildestpixel/6b85cacbad8c1a62dc76eefab8690278 to your computer and use it in GitHub Desktop.
BME 280 Matrix Breakout Pico
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# Download the latest version of the IS31FL3731 library: https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731/archive/master.zip
# soon available from https://circuitpython.org/libraries in the "Bundle Version 6.x"
# Also take the adafruit_framebuf too from the library bundle
#
# Download the font font5x8.bin from https://github.com/adafruit/Adafruit_CircuitPython_framebuf/blob/master/examples/font5x8.bin
# also available from https://circuitpython.org/libraries in the "Bundle Examples" in the adafruit_framebuf library
#
# Put the libraries in either *.py or *.mpy in the /lib folder from your CIRCUITPYTHON drive_mode
# Put the font5x8.bin in the root, together with this file as code.py
# Enjoy
#
import board
import busio
import adafruit_framebuf
import adafruit_bme280
# uncomment next line if you are using Pimoroni 11x7 LED Matrix Breakout
from adafruit_is31fl3731.matrix_11x7 import Matrix11x7 as Display
# Create the I2C bus
i2c = busio.I2C(board.GP21, board.GP20)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, 0x76)
#display = Display(i2c)
display = Display(i2c)
#text_to_show = "Hello Wildestpixel"
#text_to_show = "Temperature: %0.1f C" % bme280.temperature
# Create a framebuffer for our display
buf = bytearray(32) # 2 bytes tall x 16 wide = 32 bytes (9 bits is 2 bytes)
fb = adafruit_framebuf.FrameBuffer(
buf, display.width, display.height, adafruit_framebuf.MVLSB
)
frame = 0 # start with frame 0
while True:
text_to_show = "Temp: %0.1fC" % bme280.temperature + " RH: %0.1f%%" % bme280.relative_humidity + " Pressure: %0.1f hPa" % bme280.pressure
for i in range(len(text_to_show) * 9):
fb.fill(0)
fb.text(text_to_show, -i + display.width, 0, color=1)
# to improve the display flicker we can use two frame
# fill the next frame with scrolling text, then
# show it.
display.frame(frame, show=False)
# turn all LEDs off
display.fill(0)
for x in range(display.width):
# using the FrameBuffer text result
bite = buf[x]
for y in range(display.height):
bit = 1 << y & bite
# if bit > 0 then set the pixel brightness
if bit:
display.pixel(x, y, 50)
# now that the frame is filled, show it.
display.frame(frame, show=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment