diff --git a/README.md b/README.md index 108ac18a..71ac73b7 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ We also maintain a C++/CMake boilerplate with GitHub workflows configured for te * Inky Frame 4.0" (7-colour E Ink) - https://shop.pimoroni.com/products/inky-frame-4 * Badger 2040 W (E Ink badge) - https://shop.pimoroni.com/products/badger-2040-w * Cosmic Unicorn (32 x 32 LED matrix) - https://shop.pimoroni.com/products/cosmic-unicorn +* Inky Frame 7.3" (7-colour E Ink) - https://shop.pimoroni.com/products/inky-frame-7-3 ## Breakouts diff --git a/micropython/examples/common/README.md b/micropython/examples/common/README.md index ba560ed7..b0ff9c69 100644 --- a/micropython/examples/common/README.md +++ b/micropython/examples/common/README.md @@ -5,4 +5,4 @@ These files are compiled to .mpy to save RAM. You can find the original .py sour - [TinyWeb](https://github.com/belyalov/tinyweb) - [logging](https://github.com/pfalcon/pycopy-lib) - [urllib.urequest](https://github.com/pfalcon/pycopy-lib) -- [sdcard](https://github.com/micropython/micropython/blob/master/drivers/sdcard/sdcard.py) +- [sdcard](https://github.com/micropython/micropython-lib/blob/master/micropython/drivers/storage/sdcard/sdcard.py) diff --git a/micropython/examples/cosmic_unicorn/README.md b/micropython/examples/cosmic_unicorn/README.md index 66e483e9..9c289d32 100644 --- a/micropython/examples/cosmic_unicorn/README.md +++ b/micropython/examples/cosmic_unicorn/README.md @@ -22,6 +22,7 @@ - [NumPy examples](#numpy-examples) - [Other Examples](#other-examples) - [Launch (Demo Reel)](#launch-demo-reel) +- [Other Resources](#other-resources) ## About Cosmic Unicorn @@ -166,4 +167,10 @@ The examples in the folder use `numpy`-like array functions contained in the `ul [launch](launch) -If you want to get the demo reel that Cosmic Unicorn ships with back, copy the contents of this `launch` folder to your Pico W. \ No newline at end of file +If you want to get the demo reel that Cosmic Unicorn ships with back, copy the contents of this `launch` folder to your Pico W. + +## Other Resources + +Here are some cool Cosmic Unicorn community projects and resources that you might find useful / inspirational! Note that code at the links below has not been tested by us and we're not able to offer support with it. + +- :link: [Green Energy Display with Cosmic Unicorn](https://www.hackster.io/andreas-motzek/clock-and-green-energy-display-with-cosmic-unicorn-641dcb) diff --git a/micropython/examples/inky_frame/README.md b/micropython/examples/inky_frame/README.md index f73a9e9d..1420d0e1 100644 --- a/micropython/examples/inky_frame/README.md +++ b/micropython/examples/inky_frame/README.md @@ -3,16 +3,18 @@ - [PicoGraphics](#picographics) - [Examples](#examples) - [Button Test](#button-test) + - [Carbon Intensity](#carbon-intensity) - [Daily Activity](#daily-activity) + - [Dithering](#dithering) - [Image Gallery](#image-gallery) - [LED PWM](#led-pwm) - [News](#news) - [PlaceKitten](#placekitten) - [Quote of the Day](#quote-of-the-day) - [Random Joke](#random-joke) + - [RTC Demo](#rtc-demo) - [SD Card Test](#sd-card-test) - [XKCD Daily](#xkcd-daily) - - [Dithering](#dithering) ## PicoGraphics @@ -36,11 +38,23 @@ Inky Frame's buttons (and the RTC alarm, busy signal from the screen and externa 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. +### Carbon Intensity +[carbon_intensity.py](carbon_intensity.py) + +This example connects to the Carbon Intensity API to give you a regional forecast of how your (UK) electricity is being generated and its carbon impact. + +Find out more at https://carbonintensity.org.uk/ + ### Daily Activity [inky_frame_daily_activity.py](inky_frame_daily_activity.py) Generate a random activity from Bored API. +### Dithering +[inky_frame_dithering.py](inky_frame_dithering.py) + +A basic example showing automatic dithering in action, as PicoGraphics tries to use Inky Frame's limited colour palette to match arbitrary colours. + ### Image Gallery [/image_gallery](../inky_frame/image_gallery) @@ -78,6 +92,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 +### RTC Demo +[inky_frame_rtc_demo.py](inky_frame_rtc_demo.py) + +A basic example that sets the time/date from an NTP server, syncs the Inky and Pico RTCs and and makes Inky Frame wake up on a timer. + ### SD Card Test [sd_test.py](sd_test.py) @@ -92,8 +111,4 @@ The webcomic is rendered "offline" by our feed2image service since xkcd.com requ For bugs/contributions see: https://github.com/pimoroni/feed2image -### Dithering -[inky_frame_dithering.py](inky_frame_dithering.py) - -A basic example showing automatic dithering in action, as PicoGraphics tries to use Inky Frame's limited colour palette to match arbitrary colours. diff --git a/micropython/examples/inky_frame/carbon_intensity.py b/micropython/examples/inky_frame/carbon_intensity.py new file mode 100644 index 00000000..20c41421 --- /dev/null +++ b/micropython/examples/inky_frame/carbon_intensity.py @@ -0,0 +1,149 @@ +""" +This example connects to the Carbon Intensity API to give you a regional +forecast of how your (UK) electricity is being generated and its carbon impact. + +Carbon Intensity API only reports data from the UK National Grid. + +Find out more about what the numbers mean at: +https://carbonintensity.org.uk/ + +Make sure to uncomment the correct size for your display! + +""" + +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.3" +import urequests +import inky_frame +import uasyncio +from network_manager import NetworkManager +import WIFI_CONFIG + +# Set (the first half) of your UK postcode here +POSTCODE = "S9" + +URL = "https://api.carbonintensity.org.uk/regional/postcode/" + str(POSTCODE) + + +def get_data(): + global region, forecast, index, power_list, datetime_to, datetime_from + print(f"Requesting URL: {URL}") + r = urequests.get(URL) + # open the json data + j = r.json() + print("Data obtained!") + print(j) + + # parse the json data + region = j["data"][0]["shortname"] + + forecast = j["data"][0]["data"][0]["intensity"]["forecast"] + index = j["data"][0]["data"][0]["intensity"]["index"] + + power_list = [] + for power in j["data"][0]["data"][0]["generationmix"]: + power_list.append(power['perc']) + + datetime_to = j["data"][0]["data"][0]["to"].split("T") + datetime_from = j["data"][0]["data"][0]["from"].split("T") + + # close the socket + r.close() + + +def draw(): + global graphics + # we're setting up our PicoGraphics buffer after we've made our RAM intensive https request + graphics = PicoGraphics(DISPLAY) + w, h = graphics.get_bounds() + graphics.set_pen(inky_frame.WHITE) + graphics.clear() + + # draw lines + graphics.set_pen(inky_frame.BLACK) + graphics.line(0, int((h / 100) * 0), w, int((h / 100) * 0)) + graphics.line(0, int((h / 100) * 50), w, int((h / 100) * 50)) + graphics.set_font("bitmap8") + graphics.text('100%', w - 40, 10, scale=2) + graphics.text('50%', w - 40, int((h / 100) * 50 + 10), scale=2) + + # draw bars + bar_colours = [ + inky_frame.ORANGE, + inky_frame.RED, + inky_frame.ORANGE, + inky_frame.RED, + inky_frame.BLUE, + inky_frame.ORANGE, + inky_frame.GREEN, + inky_frame.GREEN, + inky_frame.GREEN + ] + for p in power_list: + graphics.set_pen(bar_colours[power_list.index(p)]) + graphics.rectangle(int(power_list.index(p) * w / 9), int(h - p * (h / 100)), + int(w / 9), int(h / 100 * p)) + + # draw labels + graphics.set_font('sans') + # once in white for a background + graphics.set_pen(inky_frame.WHITE) + labels = ['biomass', 'coal', 'imports', 'gas', 'nuclear', 'other', 'hydro', 'solar', 'wind'] + graphics.set_thickness(4) + for label in labels: + graphics.text(f'{label}', int((labels.index(label) * w / 9) + (w / 9) / 2), h - 10, angle=270, scale=1) + # again in black + graphics.set_pen(inky_frame.BLACK) + labels = ['biomass', 'coal', 'imports', 'gas', 'nuclear', 'other', 'hydro', 'solar', 'wind'] + graphics.set_thickness(2) + for label in labels: + graphics.text(f'{label}', int((labels.index(label) * w / 9) + (w / 9) / 2), h - 10, angle=270, scale=1) + + # draw header + graphics.set_thickness(3) + graphics.set_pen(inky_frame.GREEN) + if index in ['high', 'very high']: + graphics.set_pen(inky_frame.RED) + if index in ['moderate']: + graphics.set_pen(inky_frame.ORANGE) + graphics.set_font("sans") + graphics.text('Carbon Intensity', 10, 35, scale=1.2, angle=0) + + # draw small text + graphics.set_pen(inky_frame.BLACK) + graphics.set_font("bitmap8") + graphics.text(f'Region: {region}', int((w / 2) + 30), 10, scale=2) + graphics.text(f'{forecast} gCO2/kWh ({index})', int((w / 2) + 30), 30, scale=2) + graphics.text(f'{datetime_from[0]} {datetime_from[1]} to {datetime_to[1]}', int((w / 2) + 30), 50, scale=2) + + graphics.update() + + +def status_handler(mode, status, ip): + print(mode, status, ip) + + +inky_frame.led_busy.on() +network_manager = NetworkManager(WIFI_CONFIG.COUNTRY, status_handler=status_handler) + +# connect to wifi +try: + uasyncio.get_event_loop().run_until_complete(network_manager.client(WIFI_CONFIG.SSID, WIFI_CONFIG.PSK)) +except ImportError: + print("Add WIFI_CONFIG.py with your WiFi credentials") + +get_data() +draw() + +# Go to sleep if on battery power +inky_frame.turn_off() + +# Or comment out the line above and uncomment this one to wake up and update every half hour +# inky_frame.sleep_for(30) + +""" +Pico W RAM seems insufficient to decode a https request whilst having a PicoGraphics instance active. +If you are running off USB and want this to update periodically, you could incorporate a machine.reset() +to reset the Pico and start afresh every time. +""" diff --git a/micropython/examples/inky_frame/image_gallery/600x448/jwst1.jpg b/micropython/examples/inky_frame/image_gallery/600x448/jwst1.jpg new file mode 100644 index 00000000..6bfbb681 Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/600x448/jwst1.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/600x448/jwst2.jpg b/micropython/examples/inky_frame/image_gallery/600x448/jwst2.jpg new file mode 100644 index 00000000..5d0868d6 Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/600x448/jwst2.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/600x448/jwst3.jpg b/micropython/examples/inky_frame/image_gallery/600x448/jwst3.jpg new file mode 100644 index 00000000..d46e764d Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/600x448/jwst3.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/600x448/jwst4.jpg b/micropython/examples/inky_frame/image_gallery/600x448/jwst4.jpg new file mode 100644 index 00000000..0b9c7516 Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/600x448/jwst4.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/600x448/jwst5.jpg b/micropython/examples/inky_frame/image_gallery/600x448/jwst5.jpg new file mode 100644 index 00000000..05d86f1f Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/600x448/jwst5.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/640x400/jwst1.jpg b/micropython/examples/inky_frame/image_gallery/640x400/jwst1.jpg new file mode 100644 index 00000000..202e747a Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/640x400/jwst1.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/640x400/jwst2.jpg b/micropython/examples/inky_frame/image_gallery/640x400/jwst2.jpg new file mode 100644 index 00000000..103341e6 Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/640x400/jwst2.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/640x400/jwst3.jpg b/micropython/examples/inky_frame/image_gallery/640x400/jwst3.jpg new file mode 100644 index 00000000..4b66d651 Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/640x400/jwst3.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/640x400/jwst4.jpg b/micropython/examples/inky_frame/image_gallery/640x400/jwst4.jpg new file mode 100644 index 00000000..f1a541e3 Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/640x400/jwst4.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/640x400/jwst5.jpg b/micropython/examples/inky_frame/image_gallery/640x400/jwst5.jpg new file mode 100644 index 00000000..21a70f3e Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/640x400/jwst5.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/800x480/jwst1.jpg b/micropython/examples/inky_frame/image_gallery/800x480/jwst1.jpg new file mode 100644 index 00000000..c70f67ab Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/800x480/jwst1.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/800x480/jwst2.jpg b/micropython/examples/inky_frame/image_gallery/800x480/jwst2.jpg new file mode 100644 index 00000000..375775ff Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/800x480/jwst2.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/800x480/jwst3.jpg b/micropython/examples/inky_frame/image_gallery/800x480/jwst3.jpg new file mode 100644 index 00000000..38876f14 Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/800x480/jwst3.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/800x480/jwst4.jpg b/micropython/examples/inky_frame/image_gallery/800x480/jwst4.jpg new file mode 100644 index 00000000..21f0ee7f Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/800x480/jwst4.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/800x480/jwst5.jpg b/micropython/examples/inky_frame/image_gallery/800x480/jwst5.jpg new file mode 100644 index 00000000..6d243d8b Binary files /dev/null and b/micropython/examples/inky_frame/image_gallery/800x480/jwst5.jpg differ diff --git a/micropython/examples/inky_frame/image_gallery/README.md b/micropython/examples/inky_frame/image_gallery/README.md index 6f4ebe63..b31b62d9 100644 --- a/micropython/examples/inky_frame/image_gallery/README.md +++ b/micropython/examples/inky_frame/image_gallery/README.md @@ -1,21 +1,32 @@ # Image Gallery - [Image transfer instructions](#image-transfer-instructions) - - [image_gallery.py](#image_gallerypy) - - [image_gallery_sd.py](#image_gallery_sdpy) + - [image\_gallery.py](#image_gallerypy) + - [image\_gallery\_sd.py / image\_gallery\_sd\_random.py](#image_gallery_sdpy--image_gallery_sd_randompy) - [Image Credits](#image-credits) +Some example programs to display images on your Inky Frame, plus sample images in different sizes. + +Use: +640x400 for Inky Frame 4.0" +600x448 for Inky Frame 5.7" +800x480 for Inky Frame 7.3" + +If you want to use your own images, they will need to be the correct dimensions for your screen and saved *without progressive encoding*. + ## Image transfer instructions +In all cases the images will need to be copied to the root of your Pico W or SD card. + ### image_gallery.py Copy the images to your Pico W using Thonny. -### image_gallery_sd.py +### image_gallery_sd.py / image_gallery_sd_random.py Pop an SD card into your computer to copy the images across. (Alternatively, you can transfer them using Thonny, but you will have to mount the SD card using the REPL first). -This example requires `sdcard.mpy` from `common/lib` - copy this file into `lib` on your Pico W. +The SD card examples require `sdcard.mpy` from `common/lib` - copy this file into the `lib` directory on your Pico W. - [/micropython/examples/common](../../common) diff --git a/micropython/examples/inky_frame/image_gallery/image_gallery.py b/micropython/examples/inky_frame/image_gallery/image_gallery.py index 50488283..60b31e44 100644 --- a/micropython/examples/inky_frame/image_gallery/image_gallery.py +++ b/micropython/examples/inky_frame/image_gallery/image_gallery.py @@ -1,17 +1,19 @@ -# An offline image gallery that switches between five jpg images -# Copy them into the root of your Pico's flash using Thonny. +""" +An offline image gallery that switches between five jpg images. -# If you want to use your own images they must be the screen dimensions (or smaller) -# and saved as *non-progressive* jpgs. +Copy images into the root of your Pico's flash using Thonny. -# Make sure to uncomment the correct size for your display! +If you want to use your own images they must be the screen dimensions +(or smaller) and saved as *non-progressive* jpgs. -from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +Make sure to uncomment the correct size for your display! +""" + +# 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.3" -from machine import Pin +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" +import inky_frame import jpegdec -from pimoroni import ShiftRegister # you can change your file names here IMAGE_A = "jwst1.jpg" @@ -23,29 +25,6 @@ IMAGE_E = "jwst5.jpg" # set up the display graphics = PicoGraphics(DISPLAY) -# Inky Frame uses a shift register to read the buttons -SR_CLOCK = 8 -SR_LATCH = 9 -SR_OUT = 10 - -sr = ShiftRegister(SR_CLOCK, SR_LATCH, SR_OUT) - -# set up the button LEDs -button_a_led = Pin(11, Pin.OUT) -button_b_led = Pin(12, Pin.OUT) -button_c_led = Pin(13, Pin.OUT) -button_d_led = Pin(14, Pin.OUT) -button_e_led = Pin(15, Pin.OUT) - -# and the activity LED -activity_led = Pin(6, Pin.OUT) - -# set up and enable vsys hold so we don't go to sleep -HOLD_VSYS_EN_PIN = 2 - -hold_vsys_en_pin = Pin(HOLD_VSYS_EN_PIN, Pin.OUT) -hold_vsys_en_pin.value(True) - # Create a new JPEG decoder for our PicoGraphics j = jpegdec.JPEG(graphics) @@ -62,48 +41,35 @@ def display_image(filename): graphics.update() -# setup -activity_led.on() -# update the image on Inky every time it's powered up -# comment these lines out if running on battery power -# button_a_led.on() -# display_image(IMAGE_A) +print('Press a button to display an image!') while True: - button_a_led.off() - button_b_led.off() - button_c_led.off() - button_d_led.off() - button_e_led.off() + inky_frame.button_a.led_off() + inky_frame.button_b.led_off() + inky_frame.button_c.led_off() + inky_frame.button_d.led_off() + inky_frame.button_e.led_off() - # read the shift register - # we can tell which button has been pressed by checking if a specific bit is 0 or 1 - result = sr.read() - button_a = sr[7] - button_b = sr[6] - button_c = sr[5] - button_d = sr[4] - button_e = sr[3] - - # light up the activity LED when Inky is awake - activity_led.on() - - if button_a == 1: - button_a_led.on() + if inky_frame.button_a.read(): + print('Refreshing image A.') + inky_frame.button_a.led_on() display_image(IMAGE_A) - elif button_b == 1: - button_b_led.on() + elif inky_frame.button_b.read(): + print('Refreshing image B.') + inky_frame.button_b.led_on() display_image(IMAGE_B) - elif button_c == 1: - button_c_led.on() + elif inky_frame.button_c.read(): + print('Refreshing image C.') + inky_frame.button_c.led_on() display_image(IMAGE_C) - elif button_d == 1: - button_d_led.on() + elif inky_frame.button_d.read(): + print('Refreshing image D.') + inky_frame.button_d.led_on() display_image(IMAGE_D) - elif button_e == 1: - button_e_led.on() + elif inky_frame.button_e.read(): + print('Refreshing image E.') + inky_frame.button_e.led_on() display_image(IMAGE_E) # Go to sleep if on battery power - activity_led.off() - hold_vsys_en_pin.init(Pin.IN) + inky_frame.turn_off() diff --git a/micropython/examples/inky_frame/image_gallery/image_gallery_sd.py b/micropython/examples/inky_frame/image_gallery/image_gallery_sd.py index 4610d908..659ca291 100644 --- a/micropython/examples/inky_frame/image_gallery/image_gallery_sd.py +++ b/micropython/examples/inky_frame/image_gallery/image_gallery_sd.py @@ -1,20 +1,22 @@ -# An offline image gallery that switches between five jpg images -# on your SD card (copy them across by plugging your SD into a computer). +""" +An offline image gallery that switches between five jpg images on your SD card. -# If you want to use your own images they must be the screen dimensions (or smaller) -# and saved as *non-progressive* jpgs +Copy images to the root of your SD card by plugging it into a computer. -# Make sure to uncomment the correct size for your display! +If you want to use your own images they must be the screen dimensions +(or smaller) and saved as *non-progressive* jpgs. -from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7" +Make sure to uncomment the correct size for your display! +""" + +# 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.3" -from pimoroni import ShiftRegister +from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3" from machine import Pin, SPI import jpegdec import sdcard -import uos - +import os +import inky_frame # you can change your file names here IMAGE_A = "sd/jwst1.jpg" @@ -26,33 +28,10 @@ IMAGE_E = "sd/jwst5.jpg" # set up the display graphics = PicoGraphics(DISPLAY) -# Inky Frame uses a shift register to read the buttons -SR_CLOCK = 8 -SR_LATCH = 9 -SR_OUT = 10 - -sr = ShiftRegister(SR_CLOCK, SR_LATCH, SR_OUT) - -# set up the button LEDs -button_a_led = Pin(11, Pin.OUT) -button_b_led = Pin(12, Pin.OUT) -button_c_led = Pin(13, Pin.OUT) -button_d_led = Pin(14, Pin.OUT) -button_e_led = Pin(15, Pin.OUT) - -# and the activity LED -activity_led = Pin(6, Pin.OUT) - # 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)) -uos.mount(sd, "/sd") - -# set up and enable vsys hold so we don't go to sleep -HOLD_VSYS_EN_PIN = 2 - -hold_vsys_en_pin = Pin(HOLD_VSYS_EN_PIN, Pin.OUT) -hold_vsys_en_pin.value(True) +os.mount(sd, "/sd") # Create a new JPEG decoder for our PicoGraphics j = jpegdec.JPEG(graphics) @@ -71,47 +50,35 @@ def display_image(filename): # setup -activity_led.on() -# update the image on Inky every time it's powered up -# comment these lines out if running on battery power -# button_a_led.on() -# display_image(IMAGE_A) +print('Press a button to display an image!') while True: - button_a_led.off() - button_b_led.off() - button_c_led.off() - button_d_led.off() - button_e_led.off() + inky_frame.button_a.led_off() + inky_frame.button_b.led_off() + inky_frame.button_c.led_off() + inky_frame.button_d.led_off() + inky_frame.button_e.led_off() - # read the shift register - # we can tell which button has been pressed by checking if a specific bit is 0 or 1 - result = sr.read() - button_a = sr[7] - button_b = sr[6] - button_c = sr[5] - button_d = sr[4] - button_e = sr[3] - - # light up the activity LED when Inky is awake - activity_led.on() - - if button_a == 1: - button_a_led.on() + if inky_frame.button_a.read(): + print('Refreshing image A.') + inky_frame.button_a.led_on() display_image(IMAGE_A) - elif button_b == 1: - button_b_led.on() + elif inky_frame.button_b.read(): + print('Refreshing image B.') + inky_frame.button_b.led_on() display_image(IMAGE_B) - elif button_c == 1: - button_c_led.on() + elif inky_frame.button_c.read(): + print('Refreshing image C.') + inky_frame.button_c.led_on() display_image(IMAGE_C) - elif button_d == 1: - button_d_led.on() + elif inky_frame.button_d.read(): + print('Refreshing image D.') + inky_frame.button_d.led_on() display_image(IMAGE_D) - elif button_e == 1: - button_e_led.on() + elif inky_frame.button_e.read(): + print('Refreshing image E.') + inky_frame.button_e.led_on() display_image(IMAGE_E) - # go to sleep if on battery power - activity_led.off() - hold_vsys_en_pin.init(Pin.IN) + # Go to sleep if on battery power + inky_frame.turn_off() diff --git a/micropython/examples/inky_frame/image_gallery/image_gallery_sd_random.py b/micropython/examples/inky_frame/image_gallery/image_gallery_sd_random.py new file mode 100644 index 00000000..965610a8 --- /dev/null +++ b/micropython/examples/inky_frame/image_gallery/image_gallery_sd_random.py @@ -0,0 +1,67 @@ +""" +An offline image gallery that displays a random image from your SD card +and updates on a timer. + +Copy images to the root of your SD card by plugging it into a computer. + +If you want to use your own images they must be the screen dimensions +(or smaller) and saved as *non-progressive* jpgs. + +Make sure to uncomment the correct size for your display! +""" + +# 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.3" +from machine import Pin, SPI +import jpegdec +import sdcard +import os +import inky_frame +import random + +# how often to change image (in minutes) +UPDATE_INTERVAL = 60 + +# set up the display +graphics = PicoGraphics(DISPLAY) + +# 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 new JPEG decoder for our PicoGraphics +j = jpegdec.JPEG(graphics) + + +def display_image(filename): + + # Open the JPEG file + j.open_file(filename) + + # Decode the JPEG + j.decode(0, 0, jpegdec.JPEG_SCALE_FULL) + + # Display the result + graphics.update() + + +inky_frame.led_busy.on() + +# Get a list of files that are in the directory +files = os.listdir("/sd") +# remove files from the list that aren't .jpgs or .jpegs +files = [f for f in files if f.endswith(".jpg") or f.endswith(".jpeg")] + +while True: + # pick a random file + file = files[random.randrange(len(files))] + + # Open the file + print(f"Displaying /sd/{file}") + display_image("/sd/" + file) + + # Sleep or wait for a bit + print(f"Sleeping for {UPDATE_INTERVAL} minutes") + inky_frame.sleep_for(UPDATE_INTERVAL) diff --git a/micropython/examples/inky_frame/image_gallery/jwst1.jpg b/micropython/examples/inky_frame/image_gallery/jwst1.jpg deleted file mode 100644 index 66cf6b21..00000000 Binary files a/micropython/examples/inky_frame/image_gallery/jwst1.jpg and /dev/null differ diff --git a/micropython/examples/inky_frame/image_gallery/jwst2.jpg b/micropython/examples/inky_frame/image_gallery/jwst2.jpg deleted file mode 100644 index e46eaf86..00000000 Binary files a/micropython/examples/inky_frame/image_gallery/jwst2.jpg and /dev/null differ diff --git a/micropython/examples/inky_frame/image_gallery/jwst3.jpg b/micropython/examples/inky_frame/image_gallery/jwst3.jpg deleted file mode 100644 index ab21139f..00000000 Binary files a/micropython/examples/inky_frame/image_gallery/jwst3.jpg and /dev/null differ diff --git a/micropython/examples/inky_frame/image_gallery/jwst4.jpg b/micropython/examples/inky_frame/image_gallery/jwst4.jpg deleted file mode 100644 index dce3a5b2..00000000 Binary files a/micropython/examples/inky_frame/image_gallery/jwst4.jpg and /dev/null differ diff --git a/micropython/examples/inky_frame/image_gallery/jwst5.jpg b/micropython/examples/inky_frame/image_gallery/jwst5.jpg deleted file mode 100644 index 258d4afa..00000000 Binary files a/micropython/examples/inky_frame/image_gallery/jwst5.jpg and /dev/null differ diff --git a/micropython/modules/hub75/README.md b/micropython/modules/hub75/README.md index fafb31c9..cdf869fc 100644 --- a/micropython/modules/hub75/README.md +++ b/micropython/modules/hub75/README.md @@ -8,13 +8,13 @@ The Interstate 75 library is intended for the Interstate 75 and Interstate 75 W It can, in theory, be used with your own custom wiring, though custom pin assignments are not supported yet. -- [Notes On PIO & DMA Limitations](#notes-on-pio--dma-limitations) +- [Notes On PIO \& DMA Limitations](#notes-on-pio--dma-limitations) - [Getting Started](#getting-started) - [FM6216A Panels](#fm6216a-panels) - [Setting Colour Order](#setting-colour-order) - [Quick Reference](#quick-reference) - [Set A Pixel](#set-a-pixel) - - [Clear The Display](#clear-the-display) + - [Clear the display](#clear-the-display) ## Notes On PIO & DMA Limitations @@ -61,7 +61,7 @@ matrix = hub75.Hub75(WIDTH, HEIGHT, panel_type=hub75.PANEL_FM6126A) Some hub 75 panels have varying colour orders. A keyword argument is supplied to configure this: ```python -matrix = hub75.Hub75(WIDTH, HEIGHT, panel_type=hub75.COLOR_ORDER_RBG) +matrix = hub75.Hub75(WIDTH, HEIGHT, color_order=hub75.COLOR_ORDER_RBG) ``` The available orders are defined as constants in `hub75`: