Using the 3.5" 320x480 Color TFT Touchscreen breakout with CircuitPython involves wiring up the TFT to your CircuitPython-compatible microcontroller and plugging in your EYESPI-compatible display via an EYESPI cable. Then, you load the code and necessary libraries onto your microcontroller.
Wiring
First, wire the EYESPI breakout to your CircuitPython-compatible microcontroller. The diagram below shows wiring up to a Feather RP2040. Then, connect the TFT via an EYESPI cable to the breakout.
- breakout Vin to Feather 3.3V (red wire)
- breakout Lite to Feather 3.3V (yellow wire)
-
breakout Gnd to Feather GND (black wire)
- breakout SCK to Feather SCK (grey wire)
-
breakout MISO to Feather MI (green wire)
-
breakout MOSI to Feather MO (blue wire)
- breakout TCS to Feather D9 (aqua wire)
- breakout DC to Feather D10 (orange wire)
- breakout SCL to Feather SCL (yellow wire)
- breakout SDA to Feather SDA (blue wire)
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 and the code.py file to your CIRCUITPY drive.
Your CIRCUITPY/lib folder should contain the following folders and files:
- /adafruit_bus_device
- /adafruit_register
- adafruit_ft5336.mpy
- adafruit_hx8357.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 """ Touch paint example for HX83570 + FT5336 TFT Breakout """ import board import displayio from adafruit_hx8357 import HX8357 import adafruit_ft5336 displayio.release_displays() spi = board.SPI() # for eyespi bff # tft_cs = board.TX # tft_dc = board.RX # else: tft_cs = board.D9 tft_dc = board.D10 display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) # display is rotated to align x, y with touch screen x, y display = HX8357(display_bus, width=320, height=480, rotation=90) i2c = board.I2C() # uses board.SCL and board.SDA touch = adafruit_ft5336.Adafruit_FT5336(i2c) pixel_size = 10 palette_width = 45 palette_height = 320 // 8 splash = displayio.Group() display.root_group = splash bitmap = displayio.Bitmap(320, 480, 8) color_palette = displayio.Palette(8) color_palette[0] = 0x000000 color_palette[1] = 0xFF0000 color_palette[2] = 0xFFFF00 color_palette[3] = 0x00FF00 color_palette[4] = 0x00FFFF color_palette[5] = 0x0000FF color_palette[6] = 0xFF00FF color_palette[7] = 0xFFFFFF tile_grid = displayio.TileGrid(bitmap, pixel_shader=color_palette) # tilegrid is flipped to align x, y with touch screen x, y tile_grid.flip_y = True tile_grid.flip_x = True splash.append(tile_grid) display.root_group = splash current_color = 7 for i in range(palette_width): for j in range(palette_height): bitmap[j + palette_height, i] = 1 bitmap[j + palette_height * 2, i] = 2 bitmap[j + palette_height * 3, i] = 3 bitmap[j + palette_height * 4, i] = 4 bitmap[j + palette_height * 5, i] = 5 bitmap[j + palette_height * 6, i] = 6 bitmap[j + palette_height * 7, i] = 0 while True: if touch.touched: try: for t in touch.points: x = t[0] y = t[1] print(x, y) if not 0 <= x < display.width or not 0 <= y < display.height: continue # Skip out of bounds touches if y < palette_width: current_color = bitmap[x, y] else: for i in range(pixel_size): for j in range(pixel_size): x_pixel = x - (pixel_size // 2) + i y_pixel = y - (pixel_size // 2) + j if ( 0 <= x_pixel < display.width and 0 <= y_pixel < display.height ): bitmap[x_pixel, y_pixel] = current_color except RuntimeError: pass
Once everything is copied over, on your display, you should the touch paint example begin to run. You can touch the different colors on the side of the TFT and doodle on the screen.
Text editor powered by tinymce.