Created
December 20, 2021 06:55
-
-
Save idriszmy/52734e404e5e0488e9c3e07429a4e90a to your computer and use it in GitHub Desktop.
Display image on graphic LCD using Maker Nano RP2040 and CircuitPython.
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
""" | |
Display image on graphic LCD using Maker Nano RP2040 and CircuitPython. | |
Items: | |
- Maker Pi Pico | |
https://my.cytron.io/p-maker-pi-pico | |
- Maker Nano RP2040 | |
https://my.cytron.io/maker-nano-rp2040-simplifying-projects-with-raspberry-pi-rp2040 | |
- 0.96" 160x80 IPS LCD (ST7735) | |
https://my.cytron.io/p-0.96-inch-160x80-ips-lcd-breakout-st7735 | |
- USB Micro B Cable | |
https://my.cytron.io/p-usb-micro-b-cable | |
Libraries required from bundle (https://circuitpython.org/libraries): | |
- adafruit_st7735r.mpy | |
References: | |
- https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-a-bitmap | |
Last update: 20 Dec 2021 | |
""" | |
import time | |
import board | |
import busio | |
import displayio | |
from adafruit_st7735r import ST7735R | |
# Release any resources currently in use for the displays | |
displayio.release_displays() | |
tft_clk = board.GP6 # SCL pin | |
tft_mosi = board.GP7 # SDA pin | |
spi = busio.SPI(tft_clk, MOSI=tft_mosi) | |
tft_rst = board.GP5 | |
tft_dc = board.GP4 | |
tft_cs = board.GP3 # Dummy | |
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst) | |
display = ST7735R( | |
display_bus, rotation=270, width=160, height=80, rowstart=1, colstart=26 | |
) | |
# Open the file | |
with open("/SpidermanNWH.bmp", "rb") as bitmap_file: | |
# Setup the file as the bitmap data source | |
bitmap = displayio.OnDiskBitmap(bitmap_file) | |
# Create a TileGrid to hold the bitmap | |
tile_grid = displayio.TileGrid( | |
bitmap, | |
pixel_shader = getattr( | |
bitmap, | |
'pixel_shader', | |
displayio.ColorConverter() | |
) | |
) | |
# Create a Group to hold the TileGrid | |
group = displayio.Group() | |
# Add the TileGrid to the Group | |
group.append(tile_grid) | |
# Add the Group to the Display | |
display.show(group) | |
# Loop forever so you can enjoy your image | |
while True: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment