From 8fcde43005ea6b4cab56516665eb84f08c60b522 Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Wed, 2 Oct 2024 18:30:01 +0200 Subject: [PATCH 1/2] Add displayio example --- examples/pm25_displayio_simpletest.py | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/pm25_displayio_simpletest.py diff --git a/examples/pm25_displayio_simpletest.py b/examples/pm25_displayio_simpletest.py new file mode 100644 index 0000000..31aa695 --- /dev/null +++ b/examples/pm25_displayio_simpletest.py @@ -0,0 +1,51 @@ +# SPDX-FileCopyrightText: 2024 +# SPDX-License-Identifier: MIT + +import time +import board +from adafruit_display_text.bitmap_label import Label +from displayio import Group +from terminalio import FONT + +from adafruit_pm25.i2c import PM25_I2C + +# Create sensor object, communicating over the board's default I2C bus +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector +pm25 = PM25_I2C(i2c, reset_pin=None) + + +# Example written for boards with built-in displays +display = board.DISPLAY + +# Create a main_group to hold anything we want to show on the display. +main_group = Group() + +# Create a Label 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 near the top left corner with anchored positioning +display_output_label.anchor_point = (0, 0) +display_output_label.anchored_position = (4, 4) + +# Add the label to the main_group +main_group.append(display_output_label) + +# Set the main_group as the root_group of the display +display.root_group = main_group + +# Begin main loop +while True: + try: + aqdata = pm25.read() + except RuntimeError: + continue + # Update the label.text property to change the text on the display + # show some of the values returned by the sensor read, one per line + display_output_label.text = f"PM 1.0: {aqdata["pm10 standard"]} \ + \nPM 2.5: {aqdata["pm25 standard"]} \ + \n1.0um / 0.1L: {aqdata["particles 10um"]} \ + \n2.5um / 0.1L: {aqdata["particles 25um"]} " + # Wait a bit between reads + time.sleep(1) \ No newline at end of file From a58057b5c4c23c56f3cedcdc355f9fba580e97e4 Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Wed, 2 Oct 2024 18:51:42 +0200 Subject: [PATCH 2/2] Fix lint error --- examples/pm25_displayio_simpletest.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/pm25_displayio_simpletest.py b/examples/pm25_displayio_simpletest.py index 31aa695..4fa6cdf 100644 --- a/examples/pm25_displayio_simpletest.py +++ b/examples/pm25_displayio_simpletest.py @@ -13,8 +13,8 @@ i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector pm25 = PM25_I2C(i2c, reset_pin=None) - - + + # Example written for boards with built-in displays display = board.DISPLAY @@ -43,9 +43,9 @@ continue # Update the label.text property to change the text on the display # show some of the values returned by the sensor read, one per line - display_output_label.text = f"PM 1.0: {aqdata["pm10 standard"]} \ - \nPM 2.5: {aqdata["pm25 standard"]} \ - \n1.0um / 0.1L: {aqdata["particles 10um"]} \ - \n2.5um / 0.1L: {aqdata["particles 25um"]} " + display_output_label.text = f"PM 1.0: { aqdata['pm10 standard'] } \ + \nPM 2.5: { aqdata['pm25 standard']} \ + \n1.0um / 0.1L: { aqdata['particles 10um'] } \ + \n2.5um / 0.1L: { aqdata['particles 25um'] }" # Wait a bit between reads - time.sleep(1) \ No newline at end of file + time.sleep(1)