Basic Graphics Test Wiring
Wiring up the display in SPI mode is pretty easy as there's not that many pins! This is using hardware SPI, but you can also use software SPI (any pins) later. Start by connecting the power pins
- 3-5V Vin or V+ connects to the microcontroller 5V pin
- Gnd or G connects to Arduino ground
- SCK or CK connects to SPI clock. On Arduino Uno/Duemilanove/328-based, that's Digital 13. On Mega, it's Digital 52 and on other boards it's ICSP-3 (See SPI Connections for more details)
- MISO or SO is not connected
- MOSI or SI connects to SPI MOSI. On Arduino Uno/Duemilanove/328-based, that's Digital 11. On Mega, it's Digital 51 and on other boards it's ICSP-4 (See SPI Connections for more details)
- TCS or TC connects to the SPI Chip Select pin. This uses Digital 10 but you can later change this to any pin.
- RST or RT connects to the Display Reset pin. This uses Digital 9 but you can later change this pin too.
- DC connects to our SPI data/command select pin. We'll be using Digital 8 but you can later change this pin too.
For the built-in level shifter, the board uses a CD74HC4050 chip, which has a typical propagation delay of ~10ns
Install Arduino Libraries
Adafruit has example code ready to go for use with these TFTs. It's written for Arduino, which should be portable to any microcontroller by adapting the C++ source.
Five libraries need to be installed using the Arduino Library Manager…this is the preferred and modern way. From the Arduino “Sketch” menu, select “Include Library” then “Manage Libraries…”
Type “7789” in the search field to quickly find the first library — Adafruit ST7735 and ST7789 Library:
Arduino should ask you about installing dependencies. Be sure to chose "Install all".
Repeat the search and install steps for the remaining libraries, looking for Adafruit Zero DMA, Adafruit SPIFlash, and SdFat - Adafruit Fork.
After restarting the Arduino software, you should see a new example folder called Adafruit ST7735 and ST7789 Library, and inside, an example called graphicstest_st7789.
Since this example is written for several displays, there is just one change needed in order to use it with the this display.
You just need to set the correct initialization sequence. In the graphicstest_st7789 source code, look for the lines as follows:
// Use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT: tft.init(240, 240); // Init ST7789 240x240 // OR use this initializer (uncomment) if using a 1.69" 280x240 TFT: //tft.init(240, 280); // Init ST7789 280x240 // OR use this initializer (uncomment) if using a 2.0" 320x240 TFT: //tft.init(240, 320); // Init ST7789 320x240 // OR use this initializer (uncomment) if using a 1.14" 240x135 TFT: //tft.init(135, 240); // Init ST7789 240x135 // OR use this initializer (uncomment) if using a 1.47" 172x320 TFT: //tft.init(172, 320); // Init ST7789 172x320 // OR use this initializer (uncomment) if using a 1.9" 170x320 TFT: //tft.init(170, 320); // Init ST7789 170x320
Comment out the first line, and uncomment the line that corresponds to this display, so it looks like:
// Use this initializer (uncomment) if using a 1.3" or 1.54" 240x240 TFT: //tft.init(240, 240); // Init ST7789 240x240 // OR use this initializer (uncomment) if using a 1.69" 280x240 TFT: //tft.init(240, 280); // Init ST7789 280x240 // OR use this initializer (uncomment) if using a 2.0" 320x240 TFT: //tft.init(240, 320); // Init ST7789 320x240 // OR use this initializer (uncomment) if using a 1.14" 240x135 TFT: //tft.init(135, 240); // Init ST7789 240x135 // OR use this initializer (uncomment) if using a 1.47" 172x320 TFT: tft.init(172, 320); // Init ST7789 172x320 // OR use this initializer (uncomment) if using a 1.9" 170x320 TFT: //tft.init(170, 320); // Init ST7789 170x320
Now upload the sketch to your Arduino. You may need to press the Reset button to reset the arduino and TFT. You should see a collection of graphical tests draw out on the TFT.
Changing Pins
Now that you have it working, there's a few things you can do to change around the pins.
If you're using Hardware SPI, the CLOCK and MOSI pins are 'fixed' and can't be changed. But you can change to software SPI, which is a bit slower, and that lets you pick any pins you like. Find these lines:
// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique // to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and // SCLK = pin 13. This is the fastest mode of operation and is required if // using the breakout board's microSD card. Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST); // OPTION 2 lets you interface the display using ANY TWO or THREE PINS, // tradeoff being that performance is not as fast as hardware SPI above. //#define TFT_MOSI 11 // Data out //#define TFT_SCLK 13 // Clock out //Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
Comment out option 1, and uncomment option 2. Then you can change the pin names that begin with TFT_ to whatever pins you'd like!
The 7789-based TFT displays have an auto-reset circuit on it, so you probably don't need to use the RST pin. You can change
#define TFT_RST 9
to
#define TFT_RST -1
so that pin isn't used either. Or connect it up for manual TFT resetting!
Text editor powered by tinymce.