From 4df7ddb8a93a0f6a7165915e4db154919b8a7e33 Mon Sep 17 00:00:00 2001 From: JPOSADA202020 Date: Wed, 11 Dec 2024 10:29:28 -0500 Subject: [PATCH 1/4] adding_displayio_example --- docs/examples.rst | 36 +++++++++++++ examples/pcf8523_displayio.simpletest.py | 66 ++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 examples/pcf8523_displayio.simpletest.py diff --git a/docs/examples.rst b/docs/examples.rst index 0c1e7dd..04e4012 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -4,3 +4,39 @@ Demo .. literalinclude:: ../examples/pcf8523_simpletest.py :caption: examples/pcf8523_simpletest.py :linenos: + +Square wave generation +----------------------- + +Simple demo for clockout-mode (square-wave generation) + +.. literalinclude:: ../examples/pcf8523_clockout.py + :caption: examples/pcf8523_clockout.py + :linenos: + +Timer Flag Operation +----------------------- + +Simple demo for timer operation using the timer-flag + +.. literalinclude:: ../examples/pcf8523_timer_flag.py + :caption: examples/pcf8523_timer_flag.py + :linenos: + +Timer Interrupt +----------------------- + +Simple demo for timer operation, using the interrupt-pin + +.. literalinclude:: ../examples/pcf8523_timer_interrupt.py + :caption: examples/pcf8523_timer_interrupt.py + :linenos: + +DisplayIO Simpletest +--------------------- + +This is a simple test for boards with built-in display. + +.. literalinclude:: ../examples/pcf8523_displayio_simpletest.py + :caption: examples/pcf8523_displayio_simpletest.py + :linenos: diff --git a/examples/pcf8523_displayio.simpletest.py b/examples/pcf8523_displayio.simpletest.py new file mode 100644 index 0000000..8466904 --- /dev/null +++ b/examples/pcf8523_displayio.simpletest.py @@ -0,0 +1,66 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# SPDX-FileCopyrightText: 2024 Jose D. Montoya +# +# SPDX-License-Identifier: MIT + +# Simple demo of the PCF8523 real-time clock using a built-in display. +import time +import board +from adafruit_display_text.bitmap_label import Label +from terminalio import FONT +from displayio import Group +from adafruit_pcf8523.pcf8523 import PCF8523 + + +# 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 +rtc = PCF8523(i2c) + +# Lookup table for names of days (nicer printing). +days = ( + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + "Sunday", +) + +# Set the time +t = time.struct_time((2024, 12, 12, 10, 31, 0, 0, -1, -1)) +rtc.datetime = t +print("Setting time to:", t) + +# Create two Labels 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) +display_output_label2 = Label(FONT, text="", scale=2) + +# place the label 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) +display_output_label2.anchor_point = (0, 0) +display_output_label2.anchored_position = (4, 10 + board.DISPLAY.height // 2) + +# add the label to the main_group +main_group.append(display_output_label) +main_group.append(display_output_label2) + +# 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 label.text property to change the text on the display + t = rtc.datetime + display_output_label.text = ( + f"The date is {days[int(t.tm_wday)]} {t.tm_mday}/{t.tm_mon}/{t.tm_year}" + ) + display_output_label2.text = ( + f"The time is {t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}" + ) + # wait for a bit + time.sleep(1) From 96cfaf982d6c575de005814b165041452f5b15ed Mon Sep 17 00:00:00 2001 From: JPOSADA202020 Date: Wed, 11 Dec 2024 10:35:11 -0500 Subject: [PATCH 2/4] correcting_lines --- examples/pcf8523_displayio.simpletest.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/pcf8523_displayio.simpletest.py b/examples/pcf8523_displayio.simpletest.py index 8466904..3afe9d3 100644 --- a/examples/pcf8523_displayio.simpletest.py +++ b/examples/pcf8523_displayio.simpletest.py @@ -59,8 +59,6 @@ display_output_label.text = ( f"The date is {days[int(t.tm_wday)]} {t.tm_mday}/{t.tm_mon}/{t.tm_year}" ) - display_output_label2.text = ( - f"The time is {t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}" - ) + display_output_label2.text = f"The time is {t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}" # wait for a bit time.sleep(1) From 3de653adc07fa603195ab1d6728f97bd3f744752 Mon Sep 17 00:00:00 2001 From: JPOSADA202020 Date: Wed, 11 Dec 2024 10:41:19 -0500 Subject: [PATCH 3/4] correcting_typo --- ...23_displayio.simpletest.py => pcf8523_displayio_simpletest.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{pcf8523_displayio.simpletest.py => pcf8523_displayio_simpletest.py} (100%) diff --git a/examples/pcf8523_displayio.simpletest.py b/examples/pcf8523_displayio_simpletest.py similarity index 100% rename from examples/pcf8523_displayio.simpletest.py rename to examples/pcf8523_displayio_simpletest.py From ce17bf2d743dcd1111223ae498e063e7245cb297 Mon Sep 17 00:00:00 2001 From: JPOSADA202020 Date: Wed, 11 Dec 2024 14:02:32 -0500 Subject: [PATCH 4/4] changid_labels_name --- examples/pcf8523_displayio_simpletest.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/pcf8523_displayio_simpletest.py b/examples/pcf8523_displayio_simpletest.py index 3afe9d3..c89cc00 100644 --- a/examples/pcf8523_displayio_simpletest.py +++ b/examples/pcf8523_displayio_simpletest.py @@ -36,18 +36,18 @@ # Create two Labels 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) -display_output_label2 = Label(FONT, text="", scale=2) +date_output_label = Label(FONT, text="", scale=2) +time_output_label = Label(FONT, text="", scale=2) # place the label 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) -display_output_label2.anchor_point = (0, 0) -display_output_label2.anchored_position = (4, 10 + board.DISPLAY.height // 2) +date_output_label.anchor_point = (0, 0) +date_output_label.anchored_position = (4, board.DISPLAY.height // 2) +time_output_label.anchor_point = (0, 0) +time_output_label.anchored_position = (4, 20 + board.DISPLAY.height // 2) # add the label to the main_group -main_group.append(display_output_label) -main_group.append(display_output_label2) +main_group.append(date_output_label) +main_group.append(time_output_label) # set the main_group as the root_group of the built-in DISPLAY board.DISPLAY.root_group = main_group @@ -56,9 +56,9 @@ while True: # Update the label.text property to change the text on the display t = rtc.datetime - display_output_label.text = ( + date_output_label.text = ( f"The date is {days[int(t.tm_wday)]} {t.tm_mday}/{t.tm_mon}/{t.tm_year}" ) - display_output_label2.text = f"The time is {t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}" + time_output_label.text = f"The time is {t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}" # wait for a bit time.sleep(1)