ili9341_shield_simpletest.py
1 """ 2 This test will initialize the display using displayio and draw a solid green 3 background, a smaller purple rectangle, and some yellow text. 4 5 Pinouts are for the 2.8" TFT Shield 6 """ 7 import board 8 import terminalio 9 import displayio 10 from adafruit_display_text import label 11 import adafruit_ili9341 12 13 # Release any resources currently in use for the displays 14 displayio.release_displays() 15 16 # Use Hardware SPI 17 spi = board.SPI() 18 19 # Use Software SPI if you have a shield with pins 11-13 jumpered 20 # import busio 21 # spi = busio.SPI(board.D11, board.D13) 22 23 tft_cs = board.D10 24 tft_dc = board.D9 25 26 display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) 27 display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240) 28 29 # Make the display context 30 splash = displayio.Group(max_size=10) 31 display.show(splash) 32 33 # Draw a green background 34 color_bitmap = displayio.Bitmap(320, 240, 1) 35 color_palette = displayio.Palette(1) 36 color_palette[0] = 0x00FF00 # Bright Green 37 38 bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) 39 40 splash.append(bg_sprite) 41 42 # Draw a smaller inner rectangle 43 inner_bitmap = displayio.Bitmap(280, 200, 1) 44 inner_palette = displayio.Palette(1) 45 inner_palette[0] = 0xAA0088 # Purple 46 inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20) 47 splash.append(inner_sprite) 48 49 # Draw a label 50 text_group = displayio.Group(max_size=10, scale=3, x=57, y=120) 51 text = "Hello World!" 52 text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00) 53 text_group.append(text_area) # Subgroup for text scaling 54 splash.append(text_group) 55 56 while True: 57 pass