From 35fbd67bb40f8f86b8825afa00719b983440cee9 Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Wed, 2 Oct 2024 17:17:54 +0200 Subject: [PATCH 1/3] Add displayio example --- examples/scd4x_displayio_simpletest.py | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 examples/scd4x_displayio_simpletest.py diff --git a/examples/scd4x_displayio_simpletest.py b/examples/scd4x_displayio_simpletest.py new file mode 100644 index 0000000..4a6b5d6 --- /dev/null +++ b/examples/scd4x_displayio_simpletest.py @@ -0,0 +1,50 @@ +# 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 + +import adafruit_scd4x + +# 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 +scd4x = adafruit_scd4x.SCD4X(i2c) + +print("Serial number:", [hex(i) for i in scd4x.serial_number]) + +# Put sensor into working mode, one measurement every 5s +scd4x.start_periodic_measurement() + + +# 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: + if scd4x.data_ready: + # Update the label.text property to change the text on the display + # one sensor value per line + display_output_label.text = f"CO2: {scd4x.CO2} ppm \ + \nTemperature: {scd4x.temperature:.1f} C \ + \nHumidity: {scd4x.relative_humidity:.1f} %" From e9a819eeefeadbe44645379a34575e70bba5fcea Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Wed, 2 Oct 2024 17:19:37 +0200 Subject: [PATCH 2/3] black error fix --- examples/scd4x_displayio_simpletest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/scd4x_displayio_simpletest.py b/examples/scd4x_displayio_simpletest.py index 4a6b5d6..efbd9f4 100644 --- a/examples/scd4x_displayio_simpletest.py +++ b/examples/scd4x_displayio_simpletest.py @@ -18,8 +18,8 @@ # Put sensor into working mode, one measurement every 5s scd4x.start_periodic_measurement() - - + + # Example written for boards with built-in displays display = board.DISPLAY From 3a96e59e9a6bd42302f729683886ba37a26093d3 Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Wed, 2 Oct 2024 17:29:48 +0200 Subject: [PATCH 3/3] pylint error fix --- examples/scd4x_displayio_simpletest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/scd4x_displayio_simpletest.py b/examples/scd4x_displayio_simpletest.py index efbd9f4..a2c727f 100644 --- a/examples/scd4x_displayio_simpletest.py +++ b/examples/scd4x_displayio_simpletest.py @@ -1,7 +1,6 @@ # SPDX-FileCopyrightText: 2024 # SPDX-License-Identifier: MIT -import time import board from adafruit_display_text.bitmap_label import Label from displayio import Group