From 2b6dbec27a2d9de6617db2e183ca5c9e03ed2b16 Mon Sep 17 00:00:00 2001 From: "Snakey Maker Cat =^.^=" <4115613+snkYmkrct@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:20:14 +0200 Subject: [PATCH 1/3] Add displayio example --- examples/sht4x_displayio_simpletest.py | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/sht4x_displayio_simpletest.py diff --git a/examples/sht4x_displayio_simpletest.py b/examples/sht4x_displayio_simpletest.py new file mode 100644 index 0000000..ef88e15 --- /dev/null +++ b/examples/sht4x_displayio_simpletest.py @@ -0,0 +1,52 @@ +# 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_sht4x + +# 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 +sht = adafruit_sht4x.SHT4x(i2c) + +print("Found SHT4x with serial number", hex(sht.serial_number)) + +sht.mode = adafruit_sht4x.Mode.NOHEAT_HIGHPRECISION +# Can also set the mode to enable heater +# sht.mode = adafruit_sht4x.Mode.LOWHEAT_100MS +# print("Current mode is: ", adafruit_sht4x.Mode.string[sht.mode]) + + +# 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: + temperature, relative_humidity = sht.measurements + # Update the label.text property to change the text on the display + display_output_label.text = ( + f"Temperature: {temperature:.1f} C \nHumidity: {relative_humidity:.1f} %" + ) + # Wait for a bit + time.sleep(1) From 5dd1422e398a16423e96a67cf557d0de9ffbbec5 Mon Sep 17 00:00:00 2001 From: "Snakey Maker Cat =^.^=" <4115613+snkYmkrct@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:32:30 +0200 Subject: [PATCH 2/3] add copyright text --- examples/sht4x_displayio_simpletest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/sht4x_displayio_simpletest.py b/examples/sht4x_displayio_simpletest.py index ef88e15..3a39624 100644 --- a/examples/sht4x_displayio_simpletest.py +++ b/examples/sht4x_displayio_simpletest.py @@ -1,3 +1,4 @@ +# SPDX-FileCopyrightText: 2024 # SPDX-License-Identifier: MIT import time From dda9e404e4dcbde5178e4059d0484c0ef72cf320 Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Wed, 2 Oct 2024 15:55:57 +0200 Subject: [PATCH 3/3] Fixed black error --- examples/sht4x_displayio_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sht4x_displayio_simpletest.py b/examples/sht4x_displayio_simpletest.py index 3a39624..4f3c696 100644 --- a/examples/sht4x_displayio_simpletest.py +++ b/examples/sht4x_displayio_simpletest.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2024 +# SPDX-FileCopyrightText: 2024 # SPDX-License-Identifier: MIT import time