Created
January 22, 2024 18:41
-
-
Save FoamyGuy/6afb40993cb5c4b1a7011c07de759e86 to your computer and use it in GitHub Desktop.
Download and display a bmp file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ssl | |
import wifi | |
import socketpool | |
from displayio import Group, OnDiskBitmap, TileGrid | |
import adafruit_requests as requests | |
import board | |
import storage | |
import sdcardio | |
import os | |
print("Connecting to %s" % os.getenv("CIRCUITPY_WIFI_SSID")) | |
wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")) | |
print("Connected") | |
print("My IP address is", wifi.radio.ipv4_address) | |
socket = socketpool.SocketPool(wifi.radio) | |
https = requests.Session(socket, ssl.create_default_context()) | |
sd = sdcardio.SDCard(board.SPI(), board.SD_CS) | |
vfs = storage.VfsFat(sd) | |
storage.mount(vfs, '/sd') | |
#print(os.listdir('/sd')) | |
url = "https://cdn-learn.adafruit.com/assets/assets/000/074/681/original/purple.bmp?1555717198" | |
# print(url) | |
response = requests.get(url) | |
print(f"Downloading: {url}") | |
with open("/sd/downloaded.bmp", 'wb', ) as f: | |
for chunk in response.iter_content(chunk_size=32): | |
f.write(chunk) | |
print("download complete") | |
response.close() | |
main_group = Group() | |
odb = OnDiskBitmap("/sd/downloaded.bmp") | |
tg = TileGrid(bitmap=odb, pixel_shader=odb.pixel_shader) | |
main_group.append(tg) | |
board.DISPLAY.root_group = main_group | |
while True: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment