From 93dff218dc95c2d531f56bb8bea7aaa3c6985ba8 Mon Sep 17 00:00:00 2001 From: thirdr Date: Mon, 6 Feb 2023 15:27:47 +0000 Subject: [PATCH 01/17] updated main launcher for 7 --- .../examples/inky_frame/inkylauncher/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/micropython/examples/inky_frame/inkylauncher/main.py b/micropython/examples/inky_frame/inkylauncher/main.py index b0b602b6b..c9d9995b5 100644 --- a/micropython/examples/inky_frame/inkylauncher/main.py +++ b/micropython/examples/inky_frame/inkylauncher/main.py @@ -4,8 +4,9 @@ import inky_helper as ih # Uncomment the line for your Inky Frame display size -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" +# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 4.0" # Create a secrets.py with your Wifi details to be able to get the time # @@ -27,6 +28,10 @@ def launcher(): # Apply an offset for the Inky Frame 5.7". if HEIGHT == 448: y_offset = 20 + # Inky Frame 7.3" + elif HEIGHT == 480: + y_offset = 35 + # Inky Frame 4" else: y_offset = 0 @@ -38,8 +43,9 @@ def launcher(): graphics.set_pen(5) graphics.rectangle(0, 0, WIDTH, 50) graphics.set_pen(0) - len = graphics.measure_text("Launcher", 4) // 2 - graphics.text("Launcher", (WIDTH // 2 - len), 10, WIDTH, 4) + title = "Launcher" + title_len = graphics.measure_text(title, 4) // 2 + graphics.text(title, (WIDTH // 2 - title_len), 10, WIDTH, 4) graphics.set_pen(4) graphics.rectangle(30, HEIGHT - (340 + y_offset), WIDTH - 100, 50) @@ -74,7 +80,9 @@ def launcher(): graphics.rectangle(WIDTH - 300, HEIGHT - (100 + y_offset), 270, 50) graphics.set_pen(0) - graphics.text("Hold A + E, then press Reset, to return to the Launcher", 65, HEIGHT - 30, 600, 2) + note = "Hold A + E, then press Reset, to return to the Launcher" + note_len = graphics.measure_text(note, 2) // 2 + graphics.text(note, (WIDTH // 2 - note_len), HEIGHT - 30, 600, 2) ih.led_warn.on() graphics.update() From 66fbdde5e12d79076fc159510f3a629788465577 Mon Sep 17 00:00:00 2001 From: thirdr Date: Mon, 6 Feb 2023 15:34:00 +0000 Subject: [PATCH 02/17] 7.3 Frame support for Nasa APOD --- micropython/examples/inky_frame/inkylauncher/nasa_apod.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/micropython/examples/inky_frame/inkylauncher/nasa_apod.py b/micropython/examples/inky_frame/inkylauncher/nasa_apod.py index 8bc8aecfb..01e128761 100644 --- a/micropython/examples/inky_frame/inkylauncher/nasa_apod.py +++ b/micropython/examples/inky_frame/inkylauncher/nasa_apod.py @@ -38,6 +38,8 @@ def update(): elif HEIGHT == 400: # Image for Inky Frame 4.0 IMG_URL = "https://pimoroni.github.io/feed2image/nasa-apod-640x400-daily.jpg" + elif HEIGHT == 480: + IMG_URL = "https://pimoroni.github.io/feed2image/nasa-apod-800x480-daily.jpg" try: # Grab the data From 44cc9d6e5ecf5aafe2851422e82b7dbaf49dc510 Mon Sep 17 00:00:00 2001 From: thirdr Date: Tue, 7 Feb 2023 09:55:12 +0000 Subject: [PATCH 03/17] comment change --- micropython/examples/inky_frame/inkylauncher/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/examples/inky_frame/inkylauncher/main.py b/micropython/examples/inky_frame/inkylauncher/main.py index c9d9995b5..01a073c35 100644 --- a/micropython/examples/inky_frame/inkylauncher/main.py +++ b/micropython/examples/inky_frame/inkylauncher/main.py @@ -6,7 +6,7 @@ # Uncomment the line for your Inky Frame display size # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 4.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" # Create a secrets.py with your Wifi details to be able to get the time # From 1fe071b713eac418ce0f3bdde81a5d6bf36cf636 Mon Sep 17 00:00:00 2001 From: thirdr Date: Tue, 7 Feb 2023 09:56:08 +0000 Subject: [PATCH 04/17] support for inky 7 --- micropython/examples/inky_frame/inkylauncher/word_clock.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/micropython/examples/inky_frame/inkylauncher/word_clock.py b/micropython/examples/inky_frame/inkylauncher/word_clock.py index 665339827..cf700e378 100644 --- a/micropython/examples/inky_frame/inkylauncher/word_clock.py +++ b/micropython/examples/inky_frame/inkylauncher/word_clock.py @@ -63,6 +63,12 @@ def draw(): y = 10 line_space = 70 letter_space = 40 + elif WIDTH == 800: + default_x = 5 + x = default_x + y = 70 + line_space = 60 + letter_space = 50 else: # Inky Frame 5.7" default_x = 20 x = default_x From e8ff06dac8408ecfd9d22ab7e77e299af5aac151 Mon Sep 17 00:00:00 2001 From: thirdr Date: Tue, 7 Feb 2023 11:29:57 +0000 Subject: [PATCH 05/17] Updated standalone examples for Inky Frame 7 --- micropython/examples/inky_frame/button_demo.py | 3 ++- micropython/examples/inky_frame/inky_frame_daily_activity.py | 3 ++- micropython/examples/inky_frame/inky_frame_news.py | 3 ++- micropython/examples/inky_frame/inky_frame_placekitten.py | 3 ++- micropython/examples/inky_frame/inky_frame_quote_of_the_day.py | 3 ++- micropython/examples/inky_frame/inky_frame_random_joke.py | 3 ++- micropython/examples/inky_frame/inky_frame_xkcd_daily.py | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/micropython/examples/inky_frame/button_demo.py b/micropython/examples/inky_frame/button_demo.py index 42f9bba9d..ad979e0e3 100644 --- a/micropython/examples/inky_frame/button_demo.py +++ b/micropython/examples/inky_frame/button_demo.py @@ -1,8 +1,9 @@ # This example shows you a simple, non-interrupt way of reading Inky Frame's buttons with a loop that checks to see if buttons are pressed. from pimoroni import ShiftRegister -from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" from machine import Pin display = PicoGraphics(display=DISPLAY) diff --git a/micropython/examples/inky_frame/inky_frame_daily_activity.py b/micropython/examples/inky_frame/inky_frame_daily_activity.py index 7e1b039e5..2fa0cb967 100644 --- a/micropython/examples/inky_frame/inky_frame_daily_activity.py +++ b/micropython/examples/inky_frame/inky_frame_daily_activity.py @@ -4,8 +4,9 @@ import uasyncio import ujson from urllib import urequest -from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" from machine import Pin from pimoroni_i2c import PimoroniI2C from pcf85063a import PCF85063A diff --git a/micropython/examples/inky_frame/inky_frame_news.py b/micropython/examples/inky_frame/inky_frame_news.py index 5340d444a..e9ef1410f 100644 --- a/micropython/examples/inky_frame/inky_frame_news.py +++ b/micropython/examples/inky_frame/inky_frame_news.py @@ -1,5 +1,6 @@ -from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" from network_manager import NetworkManager import uasyncio from urllib import urequest diff --git a/micropython/examples/inky_frame/inky_frame_placekitten.py b/micropython/examples/inky_frame/inky_frame_placekitten.py index 5d3ba880e..385b85cd3 100644 --- a/micropython/examples/inky_frame/inky_frame_placekitten.py +++ b/micropython/examples/inky_frame/inky_frame_placekitten.py @@ -8,8 +8,9 @@ import WIFI_CONFIG from urllib import urequest from network_manager import NetworkManager -from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" """ random placekitten (from a very small set) diff --git a/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py b/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py index 886d10e9d..0317a3eb1 100644 --- a/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py +++ b/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py @@ -5,8 +5,9 @@ import WIFI_CONFIG from urllib import urequest from network_manager import NetworkManager -from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" ENDPOINT = "https://en.wikiquote.org/w/api.php?format=json&action=expandtemplates&prop=wikitext&text={{{{Wikiquote:Quote%20of%20the%20day/{3}%20{2},%20{0}}}}}" diff --git a/micropython/examples/inky_frame/inky_frame_random_joke.py b/micropython/examples/inky_frame/inky_frame_random_joke.py index 23eb606d4..75937c4c6 100644 --- a/micropython/examples/inky_frame/inky_frame_random_joke.py +++ b/micropython/examples/inky_frame/inky_frame_random_joke.py @@ -6,8 +6,9 @@ import WIFI_CONFIG import uasyncio from network_manager import NetworkManager -from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" from urllib import urequest diff --git a/micropython/examples/inky_frame/inky_frame_xkcd_daily.py b/micropython/examples/inky_frame/inky_frame_xkcd_daily.py index 3eff8bb9e..7e76eadb2 100644 --- a/micropython/examples/inky_frame/inky_frame_xkcd_daily.py +++ b/micropython/examples/inky_frame/inky_frame_xkcd_daily.py @@ -7,8 +7,9 @@ import WIFI_CONFIG from urllib import urequest from network_manager import NetworkManager -from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" """ xkcd daily From bc89afb58c832ffeba11a04e9befb3eb60fe69ff Mon Sep 17 00:00:00 2001 From: thirdr Date: Tue, 7 Feb 2023 12:13:42 +0000 Subject: [PATCH 06/17] Updated layout for Inky Frame 7 & 4 --- micropython/examples/inky_frame/inky_frame_news.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/micropython/examples/inky_frame/inky_frame_news.py b/micropython/examples/inky_frame/inky_frame_news.py index e9ef1410f..ee2179e7f 100644 --- a/micropython/examples/inky_frame/inky_frame_news.py +++ b/micropython/examples/inky_frame/inky_frame_news.py @@ -174,11 +174,11 @@ def get_rss(): graphics.text(feed[2]["description"], 10, 395 if graphics.measure_text(feed[2]["title"]) < 650 else 375, WIDTH - 150, 2) code.set_text(feed[0]["guid"]) - draw_qr_code(490, 40, 100, code) + draw_qr_code(WIDTH - 110, 40, 100, code) code.set_text(feed[1]["guid"]) draw_qr_code(10, 180, 100, code) code.set_text(feed[2]["guid"]) - draw_qr_code(490, 320, 100, code) + draw_qr_code(WIDTH - 110, 320, 100, code) else: graphics.set_pen(4) From 2357e8225b99b4a4b7901784e3db9f3733a12d24 Mon Sep 17 00:00:00 2001 From: thirdr Date: Thu, 23 Feb 2023 09:36:59 +0000 Subject: [PATCH 07/17] removed taupe colour from launcher --- micropython/examples/inky_frame/inkylauncher/main.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/micropython/examples/inky_frame/inkylauncher/main.py b/micropython/examples/inky_frame/inkylauncher/main.py index 01a073c35..5a2036471 100644 --- a/micropython/examples/inky_frame/inkylauncher/main.py +++ b/micropython/examples/inky_frame/inkylauncher/main.py @@ -72,13 +72,6 @@ def launcher(): graphics.set_pen(1) graphics.text("E. Random Joke", 35, HEIGHT - (85 + y_offset), 600, 3) - graphics.set_pen(7) - graphics.rectangle(WIDTH - 100, HEIGHT - (340 + y_offset), 70, 50) - graphics.rectangle(WIDTH - 150, HEIGHT - (280 + y_offset), 120, 50) - graphics.rectangle(WIDTH - 200, HEIGHT - (220 + y_offset), 170, 50) - graphics.rectangle(WIDTH - 250, HEIGHT - (160 + y_offset), 220, 50) - graphics.rectangle(WIDTH - 300, HEIGHT - (100 + y_offset), 270, 50) - graphics.set_pen(0) note = "Hold A + E, then press Reset, to return to the Launcher" note_len = graphics.measure_text(note, 2) // 2 From 9f8596c0318ac7271785ce9fa5616aa4bf7530ed Mon Sep 17 00:00:00 2001 From: thirdr Date: Thu, 23 Feb 2023 09:51:35 +0000 Subject: [PATCH 08/17] Switched from Taupe to Orange background text --- micropython/examples/inky_frame/inkylauncher/word_clock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/examples/inky_frame/inkylauncher/word_clock.py b/micropython/examples/inky_frame/inkylauncher/word_clock.py index cf700e378..e2cb3ad5e 100644 --- a/micropython/examples/inky_frame/inkylauncher/word_clock.py +++ b/micropython/examples/inky_frame/inkylauncher/word_clock.py @@ -84,7 +84,7 @@ def draw(): if word in time_string: graphics.set_pen(0) else: - graphics.set_pen(7) + graphics.set_pen(6) for letter in word: text_length = graphics.measure_text(letter, scale, spacing) From 797c0bbfd4cad3bbd2471e5f899fe7151f0fd582 Mon Sep 17 00:00:00 2001 From: thirdr Date: Thu, 23 Feb 2023 10:23:30 +0000 Subject: [PATCH 09/17] added exception handling --- micropython/examples/inky_frame/inkylauncher/word_clock.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/micropython/examples/inky_frame/inkylauncher/word_clock.py b/micropython/examples/inky_frame/inkylauncher/word_clock.py index e2cb3ad5e..11146c8ca 100644 --- a/micropython/examples/inky_frame/inkylauncher/word_clock.py +++ b/micropython/examples/inky_frame/inkylauncher/word_clock.py @@ -34,7 +34,10 @@ def approx_time(hours, minutes): def update(): global time_string # grab the current time from the ntp server and update the Pico RTC - ntptime.settime() + try: + ntptime.settime() + except OSError: + print("Unable to contact NTP server") current_t = rtc.datetime() time_string = approx_time(current_t[4] - 12 if current_t[4] > 12 else current_t[4], current_t[5]) From d29666b87a0bb46c488965b3dd69e4b7e42245a7 Mon Sep 17 00:00:00 2001 From: thirdr Date: Mon, 27 Feb 2023 08:58:01 +0000 Subject: [PATCH 10/17] colour adjustments --- micropython/examples/inky_frame/inkylauncher/main.py | 7 +++++++ micropython/examples/inky_frame/inkylauncher/word_clock.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/micropython/examples/inky_frame/inkylauncher/main.py b/micropython/examples/inky_frame/inkylauncher/main.py index 5a2036471..8f74b7e97 100644 --- a/micropython/examples/inky_frame/inkylauncher/main.py +++ b/micropython/examples/inky_frame/inkylauncher/main.py @@ -72,6 +72,13 @@ def launcher(): graphics.set_pen(1) graphics.text("E. Random Joke", 35, HEIGHT - (85 + y_offset), 600, 3) + graphics.set_pen(graphics.create_pen(220,220,220)) + graphics.rectangle(WIDTH - 100, HEIGHT - (340 + y_offset), 70, 50) + graphics.rectangle(WIDTH - 150, HEIGHT - (280 + y_offset), 120, 50) + graphics.rectangle(WIDTH - 200, HEIGHT - (220 + y_offset), 170, 50) + graphics.rectangle(WIDTH - 250, HEIGHT - (160 + y_offset), 220, 50) + graphics.rectangle(WIDTH - 300, HEIGHT - (100 + y_offset), 270, 50) + graphics.set_pen(0) note = "Hold A + E, then press Reset, to return to the Launcher" note_len = graphics.measure_text(note, 2) // 2 diff --git a/micropython/examples/inky_frame/inkylauncher/word_clock.py b/micropython/examples/inky_frame/inkylauncher/word_clock.py index 11146c8ca..1b5560d72 100644 --- a/micropython/examples/inky_frame/inkylauncher/word_clock.py +++ b/micropython/examples/inky_frame/inkylauncher/word_clock.py @@ -87,7 +87,7 @@ def draw(): if word in time_string: graphics.set_pen(0) else: - graphics.set_pen(6) + graphics.set_pen(graphics.create_pen(220,220,220)) for letter in word: text_length = graphics.measure_text(letter, scale, spacing) From 36458436bc15c6c93e4dce65248d4a4e2819565d Mon Sep 17 00:00:00 2001 From: thirdr Date: Mon, 27 Feb 2023 08:59:36 +0000 Subject: [PATCH 11/17] oops, linting fix --- micropython/examples/inky_frame/inkylauncher/main.py | 2 +- micropython/examples/inky_frame/inkylauncher/word_clock.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/micropython/examples/inky_frame/inkylauncher/main.py b/micropython/examples/inky_frame/inkylauncher/main.py index 8f74b7e97..1ed250fdb 100644 --- a/micropython/examples/inky_frame/inkylauncher/main.py +++ b/micropython/examples/inky_frame/inkylauncher/main.py @@ -72,7 +72,7 @@ def launcher(): graphics.set_pen(1) graphics.text("E. Random Joke", 35, HEIGHT - (85 + y_offset), 600, 3) - graphics.set_pen(graphics.create_pen(220,220,220)) + graphics.set_pen(graphics.create_pen(220, 220, 220)) graphics.rectangle(WIDTH - 100, HEIGHT - (340 + y_offset), 70, 50) graphics.rectangle(WIDTH - 150, HEIGHT - (280 + y_offset), 120, 50) graphics.rectangle(WIDTH - 200, HEIGHT - (220 + y_offset), 170, 50) diff --git a/micropython/examples/inky_frame/inkylauncher/word_clock.py b/micropython/examples/inky_frame/inkylauncher/word_clock.py index 1b5560d72..b2e0fc2bd 100644 --- a/micropython/examples/inky_frame/inkylauncher/word_clock.py +++ b/micropython/examples/inky_frame/inkylauncher/word_clock.py @@ -87,7 +87,7 @@ def draw(): if word in time_string: graphics.set_pen(0) else: - graphics.set_pen(graphics.create_pen(220,220,220)) + graphics.set_pen(graphics.create_pen(220, 220, 220)) for letter in word: text_length = graphics.measure_text(letter, scale, spacing) From b762ee886117e85da2a4eb02c0724e6a7e22f3ce Mon Sep 17 00:00:00 2001 From: thirdr Date: Mon, 27 Feb 2023 10:54:35 +0000 Subject: [PATCH 12/17] more colour and layout adjustments --- micropython/examples/inky_frame/inkylauncher/main.py | 2 +- .../examples/inky_frame/inkylauncher/news_headlines.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/micropython/examples/inky_frame/inkylauncher/main.py b/micropython/examples/inky_frame/inkylauncher/main.py index 1ed250fdb..d7a8e1b76 100644 --- a/micropython/examples/inky_frame/inkylauncher/main.py +++ b/micropython/examples/inky_frame/inkylauncher/main.py @@ -40,7 +40,7 @@ def launcher(): graphics.clear() graphics.set_pen(0) - graphics.set_pen(5) + graphics.set_pen(graphics.create_pen(255, 215, 0)) graphics.rectangle(0, 0, WIDTH, 50) graphics.set_pen(0) title = "Launcher" diff --git a/micropython/examples/inky_frame/inkylauncher/news_headlines.py b/micropython/examples/inky_frame/inkylauncher/news_headlines.py index 268caab6d..f6e01ce02 100644 --- a/micropython/examples/inky_frame/inkylauncher/news_headlines.py +++ b/micropython/examples/inky_frame/inkylauncher/news_headlines.py @@ -138,6 +138,9 @@ def draw(): if feed: # Title + graphics.set_pen(graphics.create_pen(200, 0, 0)) + graphics.rectangle(0, 0, WIDTH, 40) + graphics.set_pen(1) graphics.text("Headlines from BBC News:", 10, 10, 320, 3) graphics.set_pen(4) @@ -155,6 +158,9 @@ def draw(): code.set_text(feed[1]["guid"]) draw_qr_code(10, 265, 100, code) + graphics.set_pen(graphics.create_pen(200, 0, 0)) + graphics.rectangle(0, HEIGHT - 20, WIDTH, 20) + else: graphics.set_pen(4) graphics.rectangle(0, (HEIGHT // 2) - 20, WIDTH, 40) From 579b8daa4ec3c1b33f133f4bc066077bec626b20 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Tue, 28 Feb 2023 12:54:28 +0000 Subject: [PATCH 13/17] fix typo --- micropython/examples/inky_frame/inkylauncher/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/examples/inky_frame/inkylauncher/main.py b/micropython/examples/inky_frame/inkylauncher/main.py index d7a8e1b76..6bfcc6f96 100644 --- a/micropython/examples/inky_frame/inkylauncher/main.py +++ b/micropython/examples/inky_frame/inkylauncher/main.py @@ -6,7 +6,7 @@ # Uncomment the line for your Inky Frame display size # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" # Create a secrets.py with your Wifi details to be able to get the time # From de6b7e282869321abeb75ddb2fe37c444f009682 Mon Sep 17 00:00:00 2001 From: Hel Gibbons Date: Tue, 28 Feb 2023 13:10:44 +0000 Subject: [PATCH 14/17] Inky Frame: fix more typo --- micropython/examples/inky_frame/button_demo.py | 2 +- micropython/examples/inky_frame/inky_frame_daily_activity.py | 2 +- micropython/examples/inky_frame/inky_frame_news.py | 2 +- micropython/examples/inky_frame/inky_frame_placekitten.py | 2 +- micropython/examples/inky_frame/inky_frame_quote_of_the_day.py | 2 +- micropython/examples/inky_frame/inky_frame_random_joke.py | 2 +- micropython/examples/inky_frame/inky_frame_xkcd_daily.py | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/micropython/examples/inky_frame/button_demo.py b/micropython/examples/inky_frame/button_demo.py index ad979e0e3..8feed68a0 100644 --- a/micropython/examples/inky_frame/button_demo.py +++ b/micropython/examples/inky_frame/button_demo.py @@ -3,7 +3,7 @@ from pimoroni import ShiftRegister # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" from machine import Pin display = PicoGraphics(display=DISPLAY) diff --git a/micropython/examples/inky_frame/inky_frame_daily_activity.py b/micropython/examples/inky_frame/inky_frame_daily_activity.py index 2fa0cb967..a21e6b3a2 100644 --- a/micropython/examples/inky_frame/inky_frame_daily_activity.py +++ b/micropython/examples/inky_frame/inky_frame_daily_activity.py @@ -6,7 +6,7 @@ from urllib import urequest # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" from machine import Pin from pimoroni_i2c import PimoroniI2C from pcf85063a import PCF85063A diff --git a/micropython/examples/inky_frame/inky_frame_news.py b/micropython/examples/inky_frame/inky_frame_news.py index ee2179e7f..b59df0956 100644 --- a/micropython/examples/inky_frame/inky_frame_news.py +++ b/micropython/examples/inky_frame/inky_frame_news.py @@ -1,6 +1,6 @@ # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" from network_manager import NetworkManager import uasyncio from urllib import urequest diff --git a/micropython/examples/inky_frame/inky_frame_placekitten.py b/micropython/examples/inky_frame/inky_frame_placekitten.py index 385b85cd3..ba36b9a7c 100644 --- a/micropython/examples/inky_frame/inky_frame_placekitten.py +++ b/micropython/examples/inky_frame/inky_frame_placekitten.py @@ -10,7 +10,7 @@ from network_manager import NetworkManager # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" """ random placekitten (from a very small set) diff --git a/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py b/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py index 0317a3eb1..ed07297fb 100644 --- a/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py +++ b/micropython/examples/inky_frame/inky_frame_quote_of_the_day.py @@ -7,7 +7,7 @@ from network_manager import NetworkManager # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" ENDPOINT = "https://en.wikiquote.org/w/api.php?format=json&action=expandtemplates&prop=wikitext&text={{{{Wikiquote:Quote%20of%20the%20day/{3}%20{2},%20{0}}}}}" diff --git a/micropython/examples/inky_frame/inky_frame_random_joke.py b/micropython/examples/inky_frame/inky_frame_random_joke.py index 75937c4c6..f67c778e1 100644 --- a/micropython/examples/inky_frame/inky_frame_random_joke.py +++ b/micropython/examples/inky_frame/inky_frame_random_joke.py @@ -8,7 +8,7 @@ from network_manager import NetworkManager # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" from urllib import urequest diff --git a/micropython/examples/inky_frame/inky_frame_xkcd_daily.py b/micropython/examples/inky_frame/inky_frame_xkcd_daily.py index 7e76eadb2..69e090930 100644 --- a/micropython/examples/inky_frame/inky_frame_xkcd_daily.py +++ b/micropython/examples/inky_frame/inky_frame_xkcd_daily.py @@ -9,7 +9,7 @@ from network_manager import NetworkManager # from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" # from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0" -from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.0" +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" """ xkcd daily From 45a12892b8ccb9a37f047292f932b2ebb02a277b Mon Sep 17 00:00:00 2001 From: thirdr Date: Tue, 28 Feb 2023 13:36:25 +0000 Subject: [PATCH 15/17] adding blank secrets.py --- micropython/examples/inky_frame/inkylauncher/secrets.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 micropython/examples/inky_frame/inkylauncher/secrets.py diff --git a/micropython/examples/inky_frame/inkylauncher/secrets.py b/micropython/examples/inky_frame/inkylauncher/secrets.py new file mode 100644 index 000000000..9454e28f8 --- /dev/null +++ b/micropython/examples/inky_frame/inkylauncher/secrets.py @@ -0,0 +1,3 @@ +# secrets.py should contain: +WIFI_SSID = "" +WIFI_PASSWORD = "" From 0cec01cf371257041ef574d048c9e56c8281885f Mon Sep 17 00:00:00 2001 From: thirdr Date: Wed, 1 Mar 2023 11:08:49 +0000 Subject: [PATCH 16/17] Switching from using JPEG to JSON files --- .../inky_frame/inkylauncher/random_joke.py | 79 +++++++++++++------ 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/micropython/examples/inky_frame/inkylauncher/random_joke.py b/micropython/examples/inky_frame/inkylauncher/random_joke.py index ebfb827fa..c86d069b1 100644 --- a/micropython/examples/inky_frame/inkylauncher/random_joke.py +++ b/micropython/examples/inky_frame/inkylauncher/random_joke.py @@ -1,7 +1,8 @@ import gc import random -import jpegdec from urllib import urequest +from ujson import load +import qrcode gc.collect() # We're really gonna need that RAM! @@ -13,19 +14,39 @@ FILENAME = "random-joke.jpg" JOKE_IDS = "https://pimoroni.github.io/feed2image/jokeapi-ids.txt" -JOKE_IMG = "https://pimoroni.github.io/feed2image/jokeapi-{}-{}x{}.jpg" +JOKE_IMG = "https://pimoroni.github.io/feed2image/jokeapi-{}.json" UPDATE_INTERVAL = 60 gc.collect() # Claw back some RAM! - # We don't have the RAM to store the list of Joke IDs in memory. # the first line of `jokeapi-ids.txt` is a COUNT of IDs. # Grab it, then pick a random line between 0 and COUNT. # Seek to that line and ...y'know... there's our totally random joke ID +joke = [] + + +def measure_qr_code(size, code): + w, h = code.get_size() + module_size = int(size / w) + return module_size * w, module_size + + +def draw_qr_code(ox, oy, size, code): + size, module_size = measure_qr_code(size, code) + graphics.set_pen(1) + graphics.rectangle(ox, oy, size, size) + graphics.set_pen(0) + for x in range(size): + for y in range(size): + if code.get_module(x, y): + graphics.rectangle(ox + x * module_size, oy + y * module_size, module_size, module_size) + + def update(): + global joke try: socket = urequest.urlopen(JOKE_IDS) @@ -49,34 +70,48 @@ def update(): print("Random joke ID: {}".format(random_joke_id)) - url = JOKE_IMG.format(random_joke_id, WIDTH, HEIGHT) + url = JOKE_IMG.format(random_joke_id) - socket = urequest.urlopen(url) + gc.collect() - # Stream the image data from the socket onto disk in 1024 byte chunks - # the 600x448-ish jpeg will be roughly ~24k, we really don't have the RAM! - data = bytearray(1024) - with open(FILENAME, "wb") as f: - while True: - if socket.readinto(data) == 0: - break - f.write(data) - socket.close() - del data - gc.collect() # We really are tight on RAM! + # Grab the data + try: + socket = urequest.urlopen(url) + gc.collect() + j = load(socket) + socket.close() + joke = j + del j + gc.collect() + except OSError as e: + print(e) def draw(): - jpeg = jpegdec.JPEG(graphics) - gc.collect() # For good measure... + code = qrcode.QRCode() graphics.set_pen(1) graphics.clear() - try: - jpeg.open_file(FILENAME) - jpeg.decode() - except OSError: + if joke: + if joke['type'] == "single": + graphics.set_pen(4) + graphics.text(joke['joke'], 10, 10, WIDTH - 75, 5) + if joke['type'] == "twopart": + graphics.set_pen(4) + graphics.text(joke['setup'], 10, 10, WIDTH - 75, 5) + graphics.set_pen(3) + graphics.text(joke['delivery'], 10, 290, WIDTH - 75, 5) + + graphics.set_pen(0) + # Donate link QR + code.set_text("https://github.com/sponsors/Sv443") + draw_qr_code(WIDTH - 75, HEIGHT - 75, 75, code) + + graphics.text("curated by jokeapi.dev", 10, HEIGHT - 15, WIDTH, 1) + graphics.text("donate <3", WIDTH - 65, HEIGHT - 12, WIDTH, 1) + + else: graphics.set_pen(4) graphics.rectangle(0, (HEIGHT // 2) - 20, WIDTH, 40) graphics.set_pen(1) From b66fc524ae5dcb1ac9f7bf5ddaae3877c6f54235 Mon Sep 17 00:00:00 2001 From: thirdr Date: Wed, 1 Mar 2023 12:11:18 +0000 Subject: [PATCH 17/17] adjustment to joke delivery position --- micropython/examples/inky_frame/inkylauncher/random_joke.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/examples/inky_frame/inkylauncher/random_joke.py b/micropython/examples/inky_frame/inkylauncher/random_joke.py index c86d069b1..86388c1fa 100644 --- a/micropython/examples/inky_frame/inkylauncher/random_joke.py +++ b/micropython/examples/inky_frame/inkylauncher/random_joke.py @@ -101,7 +101,7 @@ def draw(): graphics.set_pen(4) graphics.text(joke['setup'], 10, 10, WIDTH - 75, 5) graphics.set_pen(3) - graphics.text(joke['delivery'], 10, 290, WIDTH - 75, 5) + graphics.text(joke['delivery'], 10, 250, WIDTH - 75, 5) graphics.set_pen(0) # Donate link QR