From 7bd360d7d7ef539c10e59df11a694cf0990bfd8b Mon Sep 17 00:00:00 2001 From: jposada2020 Date: Sun, 2 Feb 2025 10:53:04 -0500 Subject: [PATCH 1/4] adding displayio example --- docs/examples.rst | 9 +++++ examples/mpl115a2_displayio_simpletest,py | 42 +++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 examples/mpl115a2_displayio_simpletest,py diff --git a/docs/examples.rst b/docs/examples.rst index bde7f75..67187fa 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,12 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/mpl115a2_simpletest.py :caption: examples/mpl115a2_simpletest.py :linenos: + +DisplayIO Simpletest +--------------------- + +This is a simple test for boards with built-in display. + +.. literalinclude:: ../examples/mpl115a2_displayio_simpletest.py + :caption: examples/mpl115a2_displayio_simpletest.py + :linenos: diff --git a/examples/mpl115a2_displayio_simpletest,py b/examples/mpl115a2_displayio_simpletest,py new file mode 100644 index 0000000..d20e75e --- /dev/null +++ b/examples/mpl115a2_displayio_simpletest,py @@ -0,0 +1,42 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# SPDX-FileCopyrightText: 2025 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +import time +import board +from adafruit_display_text.bitmap_label import Label +from terminalio import FONT +from displayio import Group +import adafruit_mpl115a2 + +# Simple demo of using the built-in display. +# create a main_group to hold anything we want to show on the display. +main_group = Group() +# Initialize I2C bus and sensor. +i2c = board.I2C() # uses board.SCL and board.SDA +mpl = adafruit_mpl115a2.MPL115A2(i2c) + +# Create Label(s) to show the readings. If you have a very small +# display you may need to change to scale=1. +display_output_label = Label(FONT, text="", scale=2) + +# place the label(s) in the middle of the screen with anchored positioning +display_output_label.anchor_point = (0, 0) +display_output_label.anchored_position = ( + 4, + board.DISPLAY.height // 2 - 60, +) + +# add the label(s) to the main_group +main_group.append(display_output_label) + +# set the main_group as the root_group of the built-in DISPLAY +board.DISPLAY.root_group = main_group + +# begin main loop +while True: + # update the text of the label(s) to show the sensor readings + display_output_label.text = f"Pressure: {mpl.pressure:.2f} hPa\nTemperature: {mpl.temperature:.2f} C" + # wait for a bit + time.sleep(0.5) From 3ef207192350b1a0b62405a2222c9f157244831c Mon Sep 17 00:00:00 2001 From: jposada2020 Date: Sun, 2 Feb 2025 11:00:07 -0500 Subject: [PATCH 2/4] fixing filename --- examples/mpl115a2_displayio_simpletest.py | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 examples/mpl115a2_displayio_simpletest.py diff --git a/examples/mpl115a2_displayio_simpletest.py b/examples/mpl115a2_displayio_simpletest.py new file mode 100644 index 0000000..d20e75e --- /dev/null +++ b/examples/mpl115a2_displayio_simpletest.py @@ -0,0 +1,42 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# SPDX-FileCopyrightText: 2025 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +import time +import board +from adafruit_display_text.bitmap_label import Label +from terminalio import FONT +from displayio import Group +import adafruit_mpl115a2 + +# Simple demo of using the built-in display. +# create a main_group to hold anything we want to show on the display. +main_group = Group() +# Initialize I2C bus and sensor. +i2c = board.I2C() # uses board.SCL and board.SDA +mpl = adafruit_mpl115a2.MPL115A2(i2c) + +# Create Label(s) to show the readings. If you have a very small +# display you may need to change to scale=1. +display_output_label = Label(FONT, text="", scale=2) + +# place the label(s) in the middle of the screen with anchored positioning +display_output_label.anchor_point = (0, 0) +display_output_label.anchored_position = ( + 4, + board.DISPLAY.height // 2 - 60, +) + +# add the label(s) to the main_group +main_group.append(display_output_label) + +# set the main_group as the root_group of the built-in DISPLAY +board.DISPLAY.root_group = main_group + +# begin main loop +while True: + # update the text of the label(s) to show the sensor readings + display_output_label.text = f"Pressure: {mpl.pressure:.2f} hPa\nTemperature: {mpl.temperature:.2f} C" + # wait for a bit + time.sleep(0.5) From 259e729034dbf475350700ae8be50cb8c0758225 Mon Sep 17 00:00:00 2001 From: jposada2020 Date: Sun, 2 Feb 2025 11:01:06 -0500 Subject: [PATCH 3/4] fixing_example --- examples/mpl115a2_displayio_simpletest,py | 42 ----------------------- 1 file changed, 42 deletions(-) delete mode 100644 examples/mpl115a2_displayio_simpletest,py diff --git a/examples/mpl115a2_displayio_simpletest,py b/examples/mpl115a2_displayio_simpletest,py deleted file mode 100644 index d20e75e..0000000 --- a/examples/mpl115a2_displayio_simpletest,py +++ /dev/null @@ -1,42 +0,0 @@ -# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries -# SPDX-FileCopyrightText: 2025 Jose D. Montoya -# -# SPDX-License-Identifier: MIT - -import time -import board -from adafruit_display_text.bitmap_label import Label -from terminalio import FONT -from displayio import Group -import adafruit_mpl115a2 - -# Simple demo of using the built-in display. -# create a main_group to hold anything we want to show on the display. -main_group = Group() -# Initialize I2C bus and sensor. -i2c = board.I2C() # uses board.SCL and board.SDA -mpl = adafruit_mpl115a2.MPL115A2(i2c) - -# Create Label(s) to show the readings. If you have a very small -# display you may need to change to scale=1. -display_output_label = Label(FONT, text="", scale=2) - -# place the label(s) in the middle of the screen with anchored positioning -display_output_label.anchor_point = (0, 0) -display_output_label.anchored_position = ( - 4, - board.DISPLAY.height // 2 - 60, -) - -# add the label(s) to the main_group -main_group.append(display_output_label) - -# set the main_group as the root_group of the built-in DISPLAY -board.DISPLAY.root_group = main_group - -# begin main loop -while True: - # update the text of the label(s) to show the sensor readings - display_output_label.text = f"Pressure: {mpl.pressure:.2f} hPa\nTemperature: {mpl.temperature:.2f} C" - # wait for a bit - time.sleep(0.5) From 41e2d2720b74137a0b49fd36116e11e8a1d58444 Mon Sep 17 00:00:00 2001 From: jposada2020 Date: Sun, 2 Feb 2025 11:06:26 -0500 Subject: [PATCH 4/4] make ruff happy --- examples/mpl115a2_displayio_simpletest.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/mpl115a2_displayio_simpletest.py b/examples/mpl115a2_displayio_simpletest.py index d20e75e..fb1ba2c 100644 --- a/examples/mpl115a2_displayio_simpletest.py +++ b/examples/mpl115a2_displayio_simpletest.py @@ -4,10 +4,12 @@ # SPDX-License-Identifier: MIT import time + import board from adafruit_display_text.bitmap_label import Label -from terminalio import FONT from displayio import Group +from terminalio import FONT + import adafruit_mpl115a2 # Simple demo of using the built-in display. @@ -37,6 +39,8 @@ # begin main loop while True: # update the text of the label(s) to show the sensor readings - display_output_label.text = f"Pressure: {mpl.pressure:.2f} hPa\nTemperature: {mpl.temperature:.2f} C" + display_output_label.text = ( + f"Pressure: {mpl.pressure:.2f} hPa\nTemperature: {mpl.temperature:.2f} C" + ) # wait for a bit time.sleep(0.5)