Skip to content

Commit 977dbb6

Browse files
authored
Merge pull request #72 from FoamyGuy/displayio_example
displayio example
2 parents 41fca05 + 1370df1 commit 977dbb6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import time
5+
import board
6+
from adafruit_display_text.bitmap_label import Label
7+
from terminalio import FONT
8+
from displayio import Group
9+
import adafruit_bme680
10+
11+
# create a main_group to hold anything we want to show on the display.
12+
main_group = Group()
13+
14+
# Create sensor object, communicating over the board's default I2C bus
15+
i2c = board.I2C() # uses board.SCL and board.SDA
16+
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
17+
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False)
18+
19+
# change this to match the location's pressure (hPa) at sea level
20+
bme680.sea_level_pressure = 1013.25
21+
22+
# You will usually have to add an offset to account for the temperature of
23+
# the sensor. This is usually around 5 degrees but varies by use. Use a
24+
# separate temperature sensor to calibrate this one.
25+
temperature_offset = -5
26+
27+
# Create a Label to show the readings. If you have a very small
28+
# display you may need to change to scale=1.
29+
display_output_label = Label(FONT, text="", scale=2)
30+
31+
# place the label near the top left corner with anchored positioning
32+
display_output_label.anchor_point = (0, 0)
33+
display_output_label.anchored_position = (4, 4)
34+
35+
# add the label to the main_group
36+
main_group.append(display_output_label)
37+
38+
# set the main_group as the root_group of the built-in DISPLAY
39+
board.DISPLAY.root_group = main_group
40+
41+
# begin main loop
42+
while True:
43+
# Update the label.text property to change the text on the display
44+
display_output_label.text = """Temperature: {:.1f} C
45+
Humidity: {:.1f} %""".format(
46+
bme680.temperature + temperature_offset, bme680.relative_humidity
47+
)
48+
49+
# wait for a bit
50+
time.sleep(1)

0 commit comments

Comments
 (0)