Using ST7789 devices with Python on Rock 3c

I’m hoping to adapt the ST7789 python library to use these SPI displays on Rock devices. I’ve enabled spidev SPI using “rsetup”, and have attempted to adapt the code to use gpiod instead of RPi.GPIO, and while I can certainly get the backlight to work, I can’t display a visible image. I’ve also attempted to retrieve data from the display ram using ST7789_RAMRD however it returns only 0s. No errors, just nothing on the screen. I’m using the latest official debian build (36).

I’ve been hoping to use a Pimoroni Display Hat Mini on my Rock 3c or Zero (started with the 3C) and while the pinout appears to be basically the same (minus CS1, I’m assuming I can just use CS0) and the voltages should be similar (3.3v for IO), I can’t seem to get colour life from the display. I’ve tested it on raspberry pis and it is working using the unmodified library.

I’ve attached my adaptation of the adafruit library provided by Pimoroni, would appreciate if someone more knowledgeable might be able to point out where it is failing or give me some help?

gpiod_ST7789.zip (4.2 KB)

1 Like

So it works fine!

Ok the problem mostly wasn’t the code, it was the behavioural differences and a pinout difference between the Rock 3C and a Raspberry pi. The Pimoroni Display Hat Mini uses the SPI MISO pin as the data/command pin. On the Raspberry Pi you can obviously control the state of that pin (pin 21) even when SPI is enabled, but it appears on the Rock 3C, at least with my version, enabling SPI locks the user from changing the pin state, so the display didn’t know when it was receiving commands or data (always thought it was data), meaning that it wasn’t initializing correctly. The other issue was that the Pimoroni device wasn’t hooked up on CS0 (the schematic helped with this), it had to connect to CS1, also making the use of the header challenging.

When I hooked the display up with connectors rather than pushing it on to the header I was able to make it work by using another pin to notify of data or command (I used pin 27).

It should be possible for others to use this code for direct control of ST7789 displays with gpiod for controlling the pins. I’ve updated the attached code so should be good to go!

1 Like

Hi,
Could you please help me adapt your code to a ST7735 ?

Before implementing the python script, did you have to modify the overlays?
How did you enable SPI?
Wich PINS have you used at the end ? All of them.