Sunspot Home

Testing the ST7735 128x160 colour TFT display on Raspberry Pi

- more notes for backup and a bad memory - -
These notes will be upgraded at random times
This first hack is WORKING but not yet tidy, , , ,

Objective - use the display as a general purpose display on a Raspberry Pi

I had previously used this on an Arduino here
There are many similar boards


Many thanks to ttps://jakew.me/2018/01/19/st7735-pi/

I record below the key lines from this site in case it goes down

The Jake Walker board -
Screen    Raspberry Pi
GND    Any Ground
VCC    Any 5v Power
SCL    BCM 11
SDA    BCM 10
RES    BCM 25
DC      BCM 24
CS      BCM 8

on my board CS is called A0
LED+ and LED- are on 5 volts but VCC is 3.3 volts
BCM11 etc is called GPIO11 etc in my PI pin-out diagram
The SD card is ignored

sudo apt update
sudo apt install build-essential python3-dev python3-smbus python3-pip python3-imaging python3-numpy git
Next you’ll need to install the Raspberry Pi GPIO and Adafruit GPIO libraries for Python:

sudo python3 -m pip install RPi.GPIO
sudo python3 -m pip install Adafruit_GPIO
Afterwards you can clone the repository and install the library:

git clone https://github.com/cskau/Python_ST7735
cd Python_ST7735
sudo python3 setup.py install
Then you can try out some of the examples in the Python_ST7735/examples folder


A simple text display
On first running the program delays a bit and the screen flashes white
I intend to read data where it says sleep and keep looping with fresh data to avoid the white flash.

# python /home/pi/Python_ST7735-master/examples/fixed_text_minimal.py
# portrait mode top left is x,y -> 0,0 x is horizontal across the 120 width dimension

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

import ST7735 as TFT
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.SPI as SPI
from time import sleep

WIDTH = 128
HEIGHT = 160
SPEED_HZ = 4000000

# Raspberry Pi configuration.
DC = 24
RST = 25
SPI_PORT = 0
SPI_DEVICE = 0

# Create TFT LCD display class.
disp = TFT.ST7735(
    DC,
    rst=RST,
    spi=SPI.SpiDev(
        SPI_PORT,
        SPI_DEVICE,
        max_speed_hz=SPEED_HZ))
       
######################################################
MESSAGE = "Hello!"

# Initialize display.
disp.begin()

#disp.clear
# first fill the whole screen blue
img = Image.new('RGB', (WIDTH, HEIGHT), color=(255, 0, 0))

draw = ImageDraw.Draw(img)

font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 16)

# top left corner is 0,0 for this portrait mode. fill is text colour
# (x,y)
draw.text((10, 10), MESSAGE, font=font, fill=(0, 255, 255))
   
disp.display(img)

sleep (2)

draw.text((10, 60), "2 sec later", font=font, fill=(255, 255, 255))

disp.display(img)

sleep (2)
draw.text((10, 100), "2 more", font=font, fill=(255, 255, 255))
disp.display(img)

sleep (2)
img = Image.new('RGB', (128, 60), color=(255, 255, 255))
draw = ImageDraw.Draw(img)

draw.text((10, 10), "NEW", font=font, fill=(0, 0, 0))

disp.display(img)

CONCLUSION

Runs OK. Colorful. No need to change the Linux kernel as some sites say.



Please email me if you want to swap notes

SUNSPOT HOME