Skip to content

Commit b01e767

Browse files
authored
Merge pull request #6 from jposada202020/adding_displayio_example
adding_displayio_example
2 parents 468c1d7 + 176e71a commit b01e767

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

docs/examples.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,22 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/ens160_simpletest.py
77
:caption: examples/ens160_simpletest.py
88
:linenos:
9+
10+
Advanced test
11+
--------------
12+
13+
Example showing more of the sensor capabilities.
14+
15+
.. literalinclude:: ../examples/ens160_advancedtest.py
16+
:caption: examples/ens160_advancedtest.py
17+
:linenos:
18+
19+
20+
DisplayIO Simpletest
21+
---------------------
22+
23+
This is a simple test for boards with built-in display.
24+
25+
.. literalinclude:: ../examples/ens160_displayio_simpletest.py
26+
:caption: examples/ens160_displayio_simpletest.py
27+
:linenos:
Lines changed: 48 additions & 0 deletions
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+
# Simple demo of the ENS160 air quality 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_ens160
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+
ens = adafruit_ens160.ENS160(i2c)
20+
21+
# Set the temperature compensation variable to the ambient temp
22+
# for best sensor calibration
23+
ens.temperature_compensation = 25
24+
# Same for ambient relative humidity
25+
ens.humidity_compensation = 50
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 in the middle of the screen with anchored positioning
32+
display_output_label.anchor_point = (0, 0)
33+
display_output_label.anchored_position = (4, board.DISPLAY.height // 2)
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 = (
45+
f"AQI:{ens.AQI} (1-5), TVOC:{ens.TVOC} ppb, eCO2:{ens.eCO2} ppm"
46+
)
47+
# wait for a bit
48+
time.sleep(1.0)

0 commit comments

Comments
 (0)