Using the 2.8" TFT Touch Shield v2 with CircuitPython involves plugging the shield into your classic Arduino or Mega-shaped board. Then, you load the code and necessary libraries onto your board to run the example.
This page uses the Metro RP2040 for demonstrating CircuitPython usage. You can use the same concepts to get going with any classic Arduino or Mega-shaped board.
Plug the shield into your Arduino or Mega-shaped board. The GPIO pins are keyed and should only plug in one way.
CircuitPython Usage
To use with CircuitPython, you need to first install the necessary libraries, and their dependencies, into the lib folder on your CIRCUITPY drive. Then you need to update code.py with the example script.
Thankfully, we can do this in one go. In the example below, click the Download Project Bundle button below to download the necessary libraries and the code.py file in a zip file. Extract the contents of the zip file.
Connect the microcontroller to your computer via a known-good USB power+data cable. The board shows up as a thumb drive named CIRCUITPY. Copy the entire lib folder, the bitmap image files, and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folder and files:
- /adafruit_bus_device
- adafruit_ili9341.mpy
- adafruit_tsc2007.mpy
Once you have copied over the necessary folders and files, your CIRCUITPY drive should resemble the following:
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This test will initialize the display using displayio and display
a bitmap image. The image advances when the touch screen is touched.
Pinouts are for the 2.8" TFT Shield
"""
import os
import board
import displayio
import fourwire
import adafruit_ili9341
import adafruit_tsc2007
# Release any resources currently in use for the displays
displayio.release_displays()
# Use Hardware SPI
spi = board.SPI()
# Use Software SPI if you have a shield with pins 11-13 jumpered
# import busio
# spi = busio.SPI(board.D11, board.D13)
tft_cs = board.D10
tft_dc = board.D9
display_width = 320
display_height = 240
display_bus = fourwire.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = adafruit_ili9341.ILI9341(display_bus, width=display_width, height=display_height)
i2c = board.I2C()
irq_dio = None
tsc = adafruit_tsc2007.TSC2007(i2c, irq=irq_dio)
groups = []
images = []
for filename in os.listdir('/'):
if filename.lower().endswith('.bmp') and not filename.startswith('.'):
images.append("/"+filename)
print(images)
for i in range(len(images)):
splash = displayio.Group()
bitmap = displayio.OnDiskBitmap(images[i])
tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader)
splash.append(tile_grid)
groups.append(splash)
index = 0
touch_state = False
display.root_group = groups[index]
while True:
if tsc.touched and not touch_state:
point = tsc.touch
touch_state = True
if point["pressure"] < 200: # ignore touches with no 'pressure' as false
continue
print("Touchpoint: (%d, %d, %d)" % (point["x"], point["y"], point["pressure"]))
# left side of the screen
if point["y"] < 2000:
index = (index - 1) % len(images)
display.root_group = groups[index]
# right side of the screen
else:
index = (index + 1) % len(images)
display.root_group = groups[index]
if not tsc.touched and touch_state:
touch_state = False
Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
The code will open all of the bitmap files that are on the CIRCUITPY drive and add them to the images array. The first image will then be displayed on the TFT. In the loop, if you touch the screen you'll see the coordinates and pressure print to the serial console.
If you press on the left side of the screen, the display will show the previous bitmap in the array. If you press on the right side of the screen, the display will show the next bitmap in the array.
Page last edited January 22, 2025
Text editor powered by tinymce.