Help Needed: Interfacing ST7302 LCD Display with Raspberry Pi Zero 2 W

June 13, 2024, 20:37

.electrified

Hello everyone, I'm currently working on a project where I need to interface an ST7302 LCD display with my Raspberry Pi Zero 2 W, and I'm running into some issues. I’ve tried following various guides and repositories, but haven’t been successful in getting the display to work properly. Project Setup: Display Model: ST7302 LCD Microcontroller: Raspberry Pi Zero 2 W Connection Type: SPI Connections: > GND - GND > VCC - 3.3V > SCL (SPI Clock) - GPIO 11 (SPI0 SCLK) > SDA (SPI Data In) - GPIO 10 (SPI0 MOSI) > RES (Reset) - GPIO 25 > DC (Data/Command) - GPIO 24 > CS (Chip Select) - GPIO 8 (SPI0 CE0) Problems Encountered: Initialisation Issues: The display does not seem to initialise properly. I suspect the initialisation sequence might be incorrect. Noise on Display: When running the code, the display shows noise for a few seconds and then goes blank. No Clear Output: Attempts to display patterns or text have been unsuccessful, resulting in either no output or random pixels.
import spidev
import RPi.GPIO as GPIO
import time

GPIO.setwarnings(False)
DC_PIN = 24
RESET_PIN = 25
CS_PIN = 8

spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 500000
spi.mode = 0b00

GPIO.setmode(GPIO.BCM)
GPIO.setup(DC_PIN, GPIO.OUT)
GPIO.setup(RESET_PIN, GPIO.OUT)
GPIO.setup(CS_PIN, GPIO.OUT)

def reset():
    GPIO.output(RESET_PIN, GPIO.HIGH)
    time.sleep(0.1)
    GPIO.output(RESET_PIN, GPIO.LOW)
    time.sleep(0.1)
    GPIO.output(RESET_PIN, GPIO.HIGH)
    time.sleep(0.1)

def write_command(command):
    GPIO.output(DC_PIN, GPIO.LOW)
    GPIO.output(CS_PIN, GPIO.LOW)
    spi.xfer([command])
    GPIO.output(CS_PIN, GPIO.HIGH)

def write_data(data):
    GPIO.output(DC_PIN, GPIO.HIGH)
    GPIO.output(CS_PIN, GPIO.LOW)
    spi.xfer([data])
    GPIO.output(CS_PIN, GPIO.HIGH)

reset()
write_command(0x01)  # Software reset
time.sleep(0.12)

write_command(0x11)  # Sleep out
time.sleep(0.12)

write_command(0x3A)  # Set color mode
write_data(0x05)  # 16-bit color

write_command(0x29)  # Display on

def clear_display():
    write_command(0x2C)  # Memory Write
    for i in range(250  122):
        write_data(0x00)

clear_display()

try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    GPIO.cleanup()
    spi.close()
What I've Tried: Double-checked all connections. Verified GPIO pin numbers and corresponding functions. Attempted different SPI settings and initialisation sequences. Questions:* Is there anything obviously wrong with my code or connections? Can anyone provide a correct initialization sequence for the ST7302 display? Are there specific SPI settings that I should use for this display? Any help or suggestions would be greatly appreciated. Thank you!

.electrified

I think I should just buy a new display lol

astrydax

yeah i've been having the same issue for awhile. There's not much help for this topic to be found in this server unfortunately. You Shouldn't need a new display though. I would dig around this repo and see where that gets you. I'm not an expert myself. https://github.com/zhcong/ST7302-for-micropython