-
-
Save dglaude/a891cbf1266381a32471e7c78fb018e9 to your computer and use it in GitHub Desktop.
Pimoroni Pico Display Pack Circuitpython 6.2 b1 running code
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
""" | |
adapted from http://helloraspberrypi.blogspot.com/2021/01/raspberry-pi-picocircuitpython-st7789.html | |
""" | |
# Adapted for 240x240 MiniPiTFT from @Pimoroni | |
# Based on https://gist.github.com/wildestpixel/86ac1063bc456213f92972fcd7c7c2e1 | |
# Found thanks to https://www.recantha.co.uk/blog/?p=20820& | |
import os | |
import board | |
import time | |
import terminalio | |
import displayio | |
import busio | |
from adafruit_display_text import label | |
#from adafruit_st7789 import ST7789 | |
import adafruit_st7789 | |
print("==============================") | |
print(os.uname()) | |
print("Hello Raspberry Pi Pico/CircuitPython ST7789 SPI IPS Display") | |
print(adafruit_st7789.__name__ + " version: " + adafruit_st7789.__version__) | |
print() | |
# Release any resources currently in use for the displays | |
displayio.release_displays() | |
tft_cs = board.GP17 # 22 GP17 LCD_CS | |
tft_dc = board.GP16 # 21 GP16 LCD_DC | |
#tft_res = board.GP23 | |
spi_mosi = board.GP19 # 25 GP19 LCD_MOSI | |
spi_clk = board.GP18 # 24 GP18 LCD_SCLK | |
""" | |
classbusio.SPI(clock: microcontroller.Pin, | |
MOSI: Optional[microcontroller.Pin] = None, | |
MISO: Optional[microcontroller.Pin] = None) | |
""" | |
spi = busio.SPI(spi_clk, MOSI=spi_mosi) | |
#display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_res) | |
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) | |
# Config for display baudrate (default max is 24mhz): | |
# BAUDRATE = 24000000 | |
# Create the ST7789 display: | |
display = adafruit_st7789.ST7789( | |
display_bus, | |
width=240, | |
height=240, | |
rowstart=80, | |
colstart=0, | |
rotation=180, | |
) | |
# Make the display context | |
splash = displayio.Group(max_size=10) | |
display.show(splash) | |
color_bitmap = displayio.Bitmap(240, 240, 1) | |
color_palette = displayio.Palette(1) | |
color_palette[0] = 0x00FF00 | |
bg_sprite = displayio.TileGrid(color_bitmap, | |
pixel_shader=color_palette, x=0, y=0) | |
splash.append(bg_sprite) | |
# Draw a smaller inner rectangle | |
inner_bitmap = displayio.Bitmap(238, 238, 1) | |
inner_palette = displayio.Palette(1) | |
inner_palette[0] = 0x0000FF | |
inner_sprite = displayio.TileGrid(inner_bitmap, | |
pixel_shader=inner_palette, x=1, y=1) | |
splash.append(inner_sprite) | |
# Draw a label | |
text_group1 = displayio.Group(max_size=10, scale=1, x=20, y=40) | |
text1 = "wildestpixel" | |
text_area1 = label.Label(terminalio.FONT, text=text1, color=0xFF0000) | |
text_group1.append(text_area1) # Subgroup for text scaling | |
# Draw a label | |
text_group2 = displayio.Group(max_size=10, scale=1, x=20, y=60) | |
text2 = "CircuitPython" | |
text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFFFFFF) | |
text_group2.append(text_area2) # Subgroup for text scaling | |
# Draw a label | |
text_group3 = displayio.Group(max_size=10, scale=1, x=20, y=100) | |
text3 = adafruit_st7789.__name__ | |
text_area3 = label.Label(terminalio.FONT, text=text3, color=0x0000000) | |
text_group3.append(text_area3) # Subgroup for text scaling | |
# Draw a label | |
text_group4 = displayio.Group(max_size=10, scale=2, x=20, y=120) | |
text4 = adafruit_st7789.__version__ | |
text_area4 = label.Label(terminalio.FONT, text=text4, color=0x000000) | |
text_group4.append(text_area4) # Subgroup for text scaling | |
splash.append(text_group1) | |
splash.append(text_group2) | |
splash.append(text_group3) | |
splash.append(text_group4) | |
while True: | |
time.sleep(5.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment