Pico Display Pack
Here is a little code that will hopefully pull images from the internet and display on the screen every 10 minutes.
import time
import busio
import digitalio
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_esp32spi
import adafruit_imageload
import adafruit_display_text.label
import adafruit_fancyled.adafruit_fancyled as fancy
import adafruit_ili9341
# Set up the ESP32SPI interface and pins
esp32_cs = digitalio.DigitalInOut(board.GP17)
esp32_ready = digitalio.DigitalInOut(board.GP16)
esp32_reset = digitalio.DigitalInOut(board.GP20)
spi = busio.SPI(board.GP18, board.GP19, board.GP16)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
# Set up the socket for HTTP requests
socket.set_interface(esp)
requests.set_socket(socket, esp)
# Set up the Pico Display Pack
display_bus = busio.SPI(board.GP10, MOSI=board.GP11, SCK=board.GP12)
display_cs = board.GP13
display_dc = board.GP14
display_reset = board.GP15
display = adafruit_ili9341.ILI9341(display_bus, cs=display_cs, dc=display_dc, rst=display_reset)
# Set up the font for the label
font = bitmap_font.load_font("/fonts/Arial-12.bdf")
font.load_glyphs(b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()')
# Set up the timer to pull a new image every 10 minutes
last_update = time.monotonic()
while True:
# Pull a new image every 10 minutes
if time.monotonic() - last_update >= 600:
try:
# Get the image from picsum.photos
image_url = "https://picsum.photos/240/135"
response = requests.get(image_url)
image_file = response.content
image = adafruit_imageload.load(image_file, bitmap=displayio.Bitmap, palette=displayio.Palette)
# Display the image on the Pico Display Pack
display.show(image)
# Create a label with the time the image was pulled and display it on the Pico Display Pack
label = adafruit_display_text.label.Label(font, text="Updated at {}".format(time.strftime("%H:%M:%S")))
label.x = 20
label.y = 20
display.show(label)
# Reset the timer
last_update = time.monotonic()
except Exception as e:
print("Error: ", e)
# Wait for button press to exit
if not button.value:
break
Comments are closed.