Skip to content

Commit c229d64

Browse files
author
JPOSADA202020
committed
adding_displayio_example
1 parent 9517905 commit c229d64

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

docs/examples.rst

+9
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@ parameters supported by the sensor.
1616
.. literalinclude:: ../examples/bmp280_normal_mode.py
1717
:caption: examples/bmp280_normal_mode.py
1818
:linenos:
19+
20+
DisplayIO Simpletest
21+
---------------------
22+
23+
This is a simple test for boards with built-in display.
24+
25+
.. literalinclude:: ../examples/bmp280_displayio_simpletest.py
26+
:caption: examples/bmp280_displayio_simpletest.py
27+
:linenos:
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2024 Jose D. Montoya
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
import time
7+
import board
8+
from adafruit_display_text.bitmap_label import Label
9+
from terminalio import FONT
10+
from displayio import Group
11+
import adafruit_bmp280
12+
13+
# Simple demo of the BMP280 barometric pressure sensor.
14+
# create a main_group to hold anything we want to show on the display.
15+
main_group = Group()
16+
# Initialize I2C bus and sensor.
17+
i2c = board.I2C() # uses board.SCL and board.SDA
18+
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c)
19+
20+
# change this to match the location's pressure (hPa) at sea level
21+
bmp280.sea_level_pressure = 1013.25
22+
23+
# Create two Labels to show the readings. If you have a very small
24+
# display you may need to change to scale=1.
25+
tempandpress_output_label = Label(FONT, text="", scale=2)
26+
altitude_output_label = Label(FONT, text="", scale=2)
27+
28+
# place the labels in the middle of the screen with anchored positioning
29+
tempandpress_output_label.anchor_point = (0, 0)
30+
tempandpress_output_label.anchored_position = (4, board.DISPLAY.height // 2)
31+
altitude_output_label.anchor_point = (0, 0)
32+
altitude_output_label.anchored_position = (4, board.DISPLAY.height // 2 + 20)
33+
34+
35+
# add the label to the main_group
36+
main_group.append(tempandpress_output_label)
37+
main_group.append(altitude_output_label)
38+
39+
# set the main_group as the root_group of the built-in DISPLAY
40+
board.DISPLAY.root_group = main_group
41+
42+
# begin main loop
43+
while True:
44+
# Update the label.text property to change the text on the display
45+
tempandpress_output_label.text = f"Temperature:{bmp280.temperature:0.1f} C, Pressure:{bmp280.pressure:0.1f} hPa"
46+
altitude_output_label.text = f"Altitude:{bmp280.altitude:0.2f} mts"
47+
# wait for a bit
48+
time.sleep(2.0)

0 commit comments

Comments
 (0)