User Manual

Next, we set the SPI object to the board's SPI with the easy shortcut function board.SPI() . By using this function, it
finds the SPI module and initializes using the default SPI parameters.
For the ST7789, because this is a nice zippy display, we'll change the baud rate to 24MHz. In order to do that, first we
enter a loop until we can lock the SPI bus for our exclusive use. After that we set it, and then unlock it again. Next we
set the Chip Select and Data/Command pins that will be used.
In the next two lines, we release the displays. This is important because if the Feather is reset, the display pins are not
automatically released and this makes them available for use again. We set the display bus to FourWire which makes
use of the SPI bus.
Finally, we initialize the driver with a width of 320 and a height of 240. Because we want the display to start in a
horizontal orientation, we tell it to start with a rotation of 90 degrees. If we stopped at this point and ran the code, we
would have a terminal that we could type at and have the screen update.
import board
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_st7789 import ST7789
spi = board.SPI()
while not spi.try_lock():
pass
spi.configure(baudrate=24000000) # Configure SPI for 24MHz
spi.unlock()
tft_cs = board.D5
tft_dc = board.D6
displayio.release_displays()
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)
display = ST7789(display_bus, width=320, height=240, rotation=90)
© Adafruit Industries https://learn.adafruit.com/2-0-inch-320-x-240-color-ips-tft-display Page 21 of 27