I recently decided to order an arduino nano and a tft display from AliExpress. When I looked up online it took me some time to find a clear guide how to connect the display to the arduino, either the display had different pins or it was a slightly different model, but with some trial and error, I managed to get it to work.
- 1x Arduino Nano
- 1x AdaFruit 1.3" 240x240 ST7789 display
- 6x jumper wires or whatever else you can use to connect
Connect the display pins to arduino like so:
- GND to GND
- VCC to 3V3
- SCL to D13
- SDA to D11
- RES to D7
- DC to D9
- BLK to GND if you for some reason want to turn off the backlight, I left it as is
Go to Tools->Manage Libraries
and search for gfx install the AdaFruit graphics library and then search for ST7789 and install the display library.
#include <Adafruit_GFX.h> // graphics library
#include <Adafruit_ST7789.h> // library for this display
#include <SPI.h>
#define TFT_CS 10 // if your display has CS pin
#define TFT_RST 8 // reset pin
#define TFT_DC 9 // data pin
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup() {
tft.init(240, 240, SPI_MODE2);
tft.setRotation(2); // rotates the screen
tft.fillScreen(ST77XX_BLACK); // fills the screen with black colour
tft.setCursor(10, 10); // starts to write text at y10 x10
tft.setTextColor(ST77XX_WHITE); // text colour to white you can use hex codes like 0xDAB420 too
tft.setTextSize(3); // sets font size
tft.setTextWrap(true);
tft.print("HELLO WORLD!");
}
void loop() {
}
And that's basically it! You've successfully connected a ST7789 display to an arduino nano!
Hello, yeah I am not sure about the CS pin as my display didn't have one, I believe I used it because it was expected by the library, I recommend you read the documentation for it as I really can't give you a definitive answer whether what I am doing is correct 😅
Could be that I have made a mistake in the diagram, it's been quite a while since I have made this so I can't really be sure.
![image](https://private-user-images.githubusercontent.com/11300364/312398165-fe74168b-a88c-41cd-810f-5f3d2d06d400.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjI1NDE3NDksIm5iZiI6MTcyMjU0MTQ0OSwicGF0aCI6Ii8xMTMwMDM2NC8zMTIzOTgxNjUtZmU3NDE2OGItYTg4Yy00MWNkLTgxMGYtNWYzZDJkMDZkNDAwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MDElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODAxVDE5NDQwOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI2M2FlYzVlZDVjNGVhZGY5NjdhNDI5MGUyYzU1ZDU1Yzg4MzljZGNmNDBmMWZmOWE0MzBkYzc0ODRmYTE0Y2YmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.-uUtrnY0Ql6h0HNa5YqNm7PO2NDKBbWXeoO_PORLeo8)
I suggest you try changing it in the code and see if it works.