In this guide we will learn how to use ST7735 TFT displays with Raspberry Pi Pico or any other CircuitPython compatible development board.
What you need
- Raspberry Pi Pico or compatible board with CircuitPython installed
- Any TFT display that supports ST7735 (s,r) driver
- Jumper wires
- USB cable to connect to the power source
You can use any Raspberry Pi Pico board and ST7735 TFT display. For this guide we are using original Raspberry Pi Pico and ST7735S TFT display from Waveshare.
If you are using a Waveshare ST7735S for pico, you can simply attach Pico board using the attached headers, otherwise connect the following
- Display DC to board.GP8
- Display RST to board.GP12
- Display MOSI to board.GP11
- Display SCK to board.GP10
- Display CS to board.GP9
Copy the following code in code.py file on your development board. Be sure to check out the inline comments for the explanation.
# We will use displayio as a main rendering library import board, time, terminalio, busio, displayio # This helps in label rendering from adafruit_display_text import label # CircuitPython ST7735 driver, make sure to use st7735r (not st7735) from adafruit_st7735r import ST7735R # Release any resources currently in use for the displays displayio.release_displays() # Define all pins BL = board.GP13 DC = board.GP8 RST = board.GP12 MOSI = board.GP11 SCK = board.GP10 CS = board.GP9 # Initialise SPI bus and display spi = busio.SPI(SCK, MOSI=MOSI) display_bus = displayio.FourWire(spi, command=DC, chip_select=CS, reset=RST) display = ST7735R(display_bus, width=160, height=128, rotation=270, bgr=True) # Make the display context splash = displayio.Group() display.show(splash) # Background color color_bitmap = displayio.Bitmap(160, 128, 1) color_palette = displayio.Palette(1) color_palette = 0x00FFFF # Cyan bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) splash.append(bg_sprite) # Draw a label text_group = displayio.Group(scale=2, x=11, y=64) text = "Monty Python!" text_area = label.Label(terminalio.FONT, text=text, color=0x000000) text_group.append(text_area) splash.append(text_group) time.sleep(1) # In the next step we will display 3 different images in a loop, # Remove text group before that for a clean transition splash.remove(text_group) # For this to work, you will need to make sure you have the BMP files downloaded and placed # inder img/ folder on your dev board while True: for n in range(3): # loop through 1.bmp, 2.bmp, 3.bmp indefinitely bitmap = displayio.OnDiskBitmap("img/" + str(n) + ".bmp") tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader) splash.append(tile_grid) # Increase the sleep if you wanna appreciate the bitmaps for a little longer time.sleep(1)
Execute code.py and you should see something like this
Download all files
Extract and copy all files including the img/ and lib/ folders to your development board.
That's it! hope you have learned something new today.
As always, if you have any questions or would like clarification on any of the steps, don't hesitate to leave a comment.