June 13, 2024, 20:37
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!