Skip to content

Commit d4b01a2

Browse files
authored
Merge pull request #25 from jposada202020/adding_displayio_example
adding_displayio_example
2 parents 0638716 + b1da083 commit d4b01a2

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

docs/examples.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/bmp3xx_simpletest.py
77
:caption: examples/bmp3xx_simpletest.py
88
:linenos:
9+
10+
DisplayIO Simpletest
11+
---------------------
12+
13+
This is a simple test for boards with built-in display.
14+
15+
.. literalinclude:: ../examples/bmp3xx_displayio_simpletest.py
16+
:caption: examples/bmp3xx_displayio_simpletest.py
17+
:linenos:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2024 Jose D. Montoya
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
# Simple demo of the BMP3XX pressure sensor using a built-in display.
7+
import time
8+
import board
9+
from adafruit_display_text.bitmap_label import Label
10+
from terminalio import FONT
11+
from displayio import Group
12+
import adafruit_bmp3xx
13+
14+
15+
# create a main_group to hold anything we want to show on the display.
16+
main_group = Group()
17+
# Initialize I2C bus and sensor.
18+
i2c = board.I2C() # uses board.SCL and board.SDA
19+
bmp = adafruit_bmp3xx.BMP3XX_I2C(i2c)
20+
21+
bmp.pressure_oversampling = 8
22+
bmp.temperature_oversampling = 2
23+
24+
# Create a Label to show the readings. If you have a very small
25+
# display you may need to change to scale=1.
26+
display_output_label = Label(FONT, text="", scale=2)
27+
28+
# place the label in the middle of the screen with anchored positioning
29+
display_output_label.anchor_point = (0, 0)
30+
display_output_label.anchored_position = (4, board.DISPLAY.height // 2)
31+
32+
# add the label to the main_group
33+
main_group.append(display_output_label)
34+
35+
# set the main_group as the root_group of the built-in DISPLAY
36+
board.DISPLAY.root_group = main_group
37+
38+
# begin main loop
39+
while True:
40+
# Update the label.text property to change the text on the display
41+
display_output_label.text = (
42+
f"Pressure: {bmp.pressure:6.4f} Temperature: {bmp.temperature:5.2f}"
43+
)
44+
# wait for a bit
45+
time.sleep(1)

0 commit comments

Comments
 (0)