Created
January 26, 2022 17:15
-
-
Save djecken/0b0666499bdfd85e75c96c03fa6a338b to your computer and use it in GitHub Desktop.
Demo Code for TFT Feather ESP32-S2 with BMP280 Stemma QT Sensor
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
import time | |
import board | |
import displayio | |
import terminalio | |
import adafruit_bmp280 | |
import adafruit_imageload | |
from adafruit_display_text import label | |
from adafruit_bitmap_font import bitmap_font | |
from adafruit_lc709203f import LC709203F | |
i2c = board.I2C() # uses board.SCL and board.SDA | |
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c) | |
BatSensor = LC709203F(board.I2C()) | |
display = board.DISPLAY | |
font = bitmap_font.load_font("/Helvetica-Bold-24.bdf") | |
bitmap, palette = adafruit_imageload.load("/lcars240x135.bmp", | |
bitmap=displayio.Bitmap, | |
palette=displayio.Palette) | |
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette) | |
splash = displayio.Group() | |
splash.append(tile_grid) | |
# temperature | |
temp_label = label.Label(font, text="Temp", color=0x000000, scale=1) | |
temp_label.y = 24 | |
temp_label.x = 46 | |
# battery | |
bat_label = label.Label(font, text="Bat", color=0x000000, scale=1) | |
bat_label.y = 66 | |
bat_label.x = 46 | |
# pressure | |
pressure_label = label.Label(font, text="Pressure", color=0x000000, scale=1) | |
pressure_label.y = 110 | |
pressure_label.x = 46 | |
splash.append(temp_label) | |
splash.append(bat_label) | |
splash.append(pressure_label) | |
display.show(splash) | |
while True: | |
temp_label.text = '{:.2f}C'.format(bmp280.temperature) | |
bat_label.text = '{:0.1f}'.format(BatSensor.cell_percent) | |
pressure_label.text = '{:.2f} hPa'.format(bmp280.pressure) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment