From 822f3354aac2cd180f78cc3b4ff76fbea3a62dfe Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Thu, 28 Jul 2022 18:39:12 +0100 Subject: [PATCH] add SD card example for Inky Frame --- micropython/examples/inky_frame/README.md | 12 ++++++++-- micropython/examples/inky_frame/sd_test.py | 26 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 micropython/examples/inky_frame/sd_test.py diff --git a/micropython/examples/inky_frame/README.md b/micropython/examples/inky_frame/README.md index 02b18ad5..fc837cfa 100644 --- a/micropython/examples/inky_frame/README.md +++ b/micropython/examples/inky_frame/README.md @@ -10,6 +10,7 @@ - [PlaceKitten](#placekitten) - [Quote of the Day](#quote-of-the-day) - [Random Joke](#random-joke) + - [SD Card Test](#sd-card-test) - [XKCD Daily](#xkcd-daily) ## PicoGraphics @@ -30,7 +31,9 @@ Finally for examples loading images, you'll need `sdcard.mpy` from `common/lib`. ### Button Test [button_test.py](button_test.py) -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. +Inky Frame's buttons (and the RTC alarm, busy signal from the screen and external trigger from the hack header) are connected to a shift register to help conserve pins, and to allow these inputs to wake the board up from sleep. + +This example demonstrates a simple way of reading when a button has been pushed by reading the shift register and checking if the bit in a specific position is 0 or 1. ### Daily Activity [inky_frame_daily_activity.py](inky_frame_daily_activity.py) @@ -38,7 +41,7 @@ This example shows you a simple, non-interrupt way of reading Inky Frame's butto Generate a random activity from Bored API. ### Image Gallery -[/image_gallery](/image_gallery) +[/image_gallery](../inky_frame/image_gallery) This photo frame example displays local images on Inky Frame and lets you switch between them with the buttons. Use `image_gallery.py` if your images are stored on your Pico, or `image_gallery_sd.py` if the images are on your SD card. @@ -74,6 +77,11 @@ Jokes are rendered into images "offline" by our feed2image service for two reaso For bugs/contributions or to complain about a joke, see: https://github.com/pimoroni/feed2image +### SD Card Test +[sd_test.py](sd_test.py) + +This simple example shows how to read and write from the SD card on Inky Frame. + ### XKCD Daily [inky_frame_xkcd_daily.py](inky_frame_xkcd_daily.py) diff --git a/micropython/examples/inky_frame/sd_test.py b/micropython/examples/inky_frame/sd_test.py new file mode 100644 index 00000000..d76d4860 --- /dev/null +++ b/micropython/examples/inky_frame/sd_test.py @@ -0,0 +1,26 @@ +# This simple example shows how to read and write from the SD card on Inky Frame. +from machine import Pin, SPI +import sdcard +import os + +# set up the SD card +sd_spi = SPI(0, sck=Pin(18, Pin.OUT), mosi=Pin(19, Pin.OUT), miso=Pin(16, Pin.OUT)) +sd = sdcard.SDCard(sd_spi, Pin(22)) +os.mount(sd, "/sd") + +# create a file and add some text +# if this file already exists it will be overwritten +with open("/sd/inkytest.txt", "w") as f: + f.write("Hello Inky!\r\n") + f.close() + +# open the file and append some text (useful for logging!) +with open("/sd/inkytest.txt", "a") as f: + f.write("We're appending some text\r\n") + f.close() + +# read the file and print the contents to the console +with open("/sd/inkytest.txt", "r") as f: + data = f.read() + print(data) + f.close()