Hi, I made the mistake of buying a cheap ST7789-based display to hook up to an Itsybitsy M4 express. Problem is, this display doesn't have a CS pin. I've read a few potential solutions or snags such as:
- Hook it up without the CS pin, you just can't use it with any other SPI devices while it's hooked up
- Run it in SPI mode 3
- Doesn't run at 3.3V despite being advertised as 1.8-5.5V
But I can't find any documentation on SPI mode 3, and even if I do hook it up without the CS pin, I still have to assign one when setting the display up in circuitpython.
Has anyone else made one of these displays work with a circuitpython board? Or am I just SOL?
SPI display without CS pin usable?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- kmatch
- Posts: 16
- Joined: Sun Sep 03, 2017 12:17 am
Re: SPI display without CS pin usable?
Same topic, so following along this thread.
I saw a question from @Lil Soul on discord regarding interfacing a generic ST7789 1.3" TFT display to CircuitPython.
I had recently overcome a hurdle with the same display with Arduino and an ItsyBitsy M4 express, so I decided to try and port my project over to CircuitPython.
As for the background on Arduino, it required setting up the the SPI bus into SPI_MODE 3:
I decided to try it out and used the following setup:
Adafruit ItsyBitsy M4 Express
1.3" ST7789 TFT display
display connected to 3.3V Vcc, gnd and backlight set to Vcc
ItsyBitsy SCK - connected to display SCL
ItsyBitsy MO - connected to display SDA
ItsyBitsy 10 - connected to display DC
ItsyBitsy 9 - connected to display RES
Observations:
1. This exact hardware configuration works fine for Arduino, code is here: https://hackaday.io/project/170191/files
2. Backlight is definitely on.
I pulled an example from the Readme here: https://github.com/adafruit/Adafruit_Ci ... hon_ST7789
I modified the spi.configure to change the polarity and phase according to the SPI specifications for SPI Mode3. https://en.wikipedia.org/wiki/Serial_Pe ... de_numbers.
The key change to the SPI configuration is here:At the bottom of this file I include the CircuitPython code with this change to the SPI configuration.
The CircuitPython code below runs (as confirmed by the LED blinking and the serial console output), but nothing displays on the TFT. I tried a few different baudrates and all the combinations of polarity/phase, but with no success.
I suspect that the SPI setup somehow is not matching that from the Arduino code, but I'm not sure where to look to debug this problem. Your suggestions are appreciated! If you point me in the right direction, I can take a look and report back with any insights.
Regards,
Kevin
Here is the sample code that I modified to change the SPI configuration.
I saw a question from @Lil Soul on discord regarding interfacing a generic ST7789 1.3" TFT display to CircuitPython.
I had recently overcome a hurdle with the same display with Arduino and an ItsyBitsy M4 express, so I decided to try and port my project over to CircuitPython.
As for the background on Arduino, it required setting up the the SPI bus into SPI_MODE 3:
Code: Select all
// Important Note: This generic display required using "SPI_MODE3" ****
tft.init(240, 240, SPI_MODE3); // Init ST7789 240x240
Adafruit ItsyBitsy M4 Express
1.3" ST7789 TFT display
display connected to 3.3V Vcc, gnd and backlight set to Vcc
ItsyBitsy SCK - connected to display SCL
ItsyBitsy MO - connected to display SDA
ItsyBitsy 10 - connected to display DC
ItsyBitsy 9 - connected to display RES
Observations:
1. This exact hardware configuration works fine for Arduino, code is here: https://hackaday.io/project/170191/files
2. Backlight is definitely on.
I pulled an example from the Readme here: https://github.com/adafruit/Adafruit_Ci ... hon_ST7789
I modified the spi.configure to change the polarity and phase according to the SPI specifications for SPI Mode3. https://en.wikipedia.org/wiki/Serial_Pe ... de_numbers.
The key change to the SPI configuration is here:
Code: Select all
spi.configure(baudrate=24000000, polarity=1, phase=1, bits=8) # Configure SPI for 24MHz, Set polarity and phase for SPI_MODE3
The CircuitPython code below runs (as confirmed by the LED blinking and the serial console output), but nothing displays on the TFT. I tried a few different baudrates and all the combinations of polarity/phase, but with no success.
I suspect that the SPI setup somehow is not matching that from the Arduino code, but I'm not sure where to look to debug this problem. Your suggestions are appreciated! If you point me in the right direction, I can take a look and report back with any insights.
Regards,
Kevin
Here is the sample code that I modified to change the SPI configuration.
Code: Select all
"""
This test will initialize the display using displayio and draw a solid green
background, a smaller purple rectangle, and some yellow text.
"""
import board
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_st7789 import ST7789
import time
import digitalio
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
# Release any resources currently in use for the displays
displayio.release_displays()
led.value = True
time.sleep(1)
led.value = False
time.sleep(1)
led.value = True
time.sleep(1)
print("starting")
spi = board.SPI()
tft_cs = board.D5
tft_dc = board.D10
while not spi.try_lock():
pass
spi.configure(baudrate=24000000, polarity=1, phase=1, bits=8) # Configure SPI for 24MHz, Set polarity and phase for SPI_MODE3
spi.unlock()
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=board.D9
)
#display = ST7789(display_bus, width=240, height=240, rowstart=80, auto_refresh=True)
display = ST7789(display_bus, width=240, height=240, rowstart=80)
# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)
color_bitmap = displayio.Bitmap(240, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x00FF00 # Bright Green
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(200, 200, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0xAA0088 # Purple
inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
splash.append(inner_sprite)
# Draw a label
text_group = displayio.Group(max_size=10, scale=2, x=50, y=120)
text = "Hello World!"
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
text_group.append(text_area) # Subgroup for text scaling
splash.append(text_group)
while True:
led.value = False
time.sleep(1)
led.value = True
time.sleep(1)
print("looping")
pass
- tannewt
- Posts: 3075
- Joined: Thu Oct 06, 2016 8:48 pm
Re: SPI display without CS pin usable?
Hi kmatocha, I don't see you setting up the backlight in your code. Try getting that going first and then we can troubleshoot further if needed.
- kmatch
- Posts: 16
- Joined: Sun Sep 03, 2017 12:17 am
Re: SPI display without CS pin usable?
Thanks @tannewt. The backlight pin is tied to VCC and is definitely on, I see the glow. Are you suggesting that the CircuitPython library requires a backlight pin to be defined so that it will work?
FYI - I followed this code and didn't see any mention of the backlight pin definition: https://github.com/adafruit/Adafruit_Ci ... hon_ST7789
Thanks for your prompt support!
FYI - I followed this code and didn't see any mention of the backlight pin definition: https://github.com/adafruit/Adafruit_Ci ... hon_ST7789
Thanks for your prompt support!
- tannewt
- Posts: 3075
- Joined: Thu Oct 06, 2016 8:48 pm
Re: SPI display without CS pin usable?
Look like we limited FourWire to polarity 0 and phase 0. I've added them as kwargs to FourWire in this PR: https://github.com/adafruit/circuitpython/pull/2730 It can be used by using the "Absolute Latest" build once the PR is merged.
Thanks for finding the issue!
Thanks for finding the issue!
- kmatch
- Posts: 16
- Joined: Sun Sep 03, 2017 12:17 am
Re: SPI display without CS pin usable?
tannewt, thanks for the prompt support. Y’all are awesome.
- wildestpixel
- Posts: 73
- Joined: Wed Oct 23, 2019 1:14 am
Re: SPI display without CS pin usable?
... This may resurrect one of those screens i have .............
Please be positive and constructive with your questions and comments.