Skip to content

Instantly share code, notes, and snippets.

@MazeW
Last active October 17, 2024 19:08
Show Gist options
  • Save MazeW/80cbdd4476d27a4e29491c8038855849 to your computer and use it in GitHub Desktop.
Save MazeW/80cbdd4476d27a4e29491c8038855849 to your computer and use it in GitHub Desktop.
Connecting an IPS TFT display (ST7789) to an arduino nano and testing image output.

Guide on connecting a ST7789 display to an Arduino Nano.

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.

What you'll need for this:

  • 1x Arduino Nano
  • 1x AdaFruit 1.3" 240x240 ST7789 display
  • 6x jumper wires or whatever else you can use to connect

Connecting display to the arduino

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

alt text

Testing the display

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!

@T20000
Copy link

T20000 commented Feb 11, 2024

Make sure your GFX library contains ''Adafruit_BusIO_Register.h""

@T20000
Copy link

T20000 commented Feb 11, 2024

Also works fine with a 2.0 inch TFT OLED. Thanks for the code !!

@Herman-RFguy
Copy link

I have one question.
The connection diagram uses D7 = pin10 for reset
In the software you define TFT_CS also to pin 10.
That looks faulty to me.
Can you give some explanation? for that?
Thanks.

@Herman-RFguy
Copy link

The define statement TFT_RST 8 ( =D5) is also conflicting with the resetline in the wiring data where D7 is used.
It is confusing.
I am currently struggling connecting a 7789 240*320 tft to my nano.
your answer is very much appreciated.

@MazeW
Copy link
Author

MazeW commented Mar 13, 2024

I have one question. The connection diagram uses D7 = pin10 for reset In the software you define TFT_CS also to pin 10. That looks faulty to me. Can you give some explanation? for that? Thanks.

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 😅

The define statement TFT_RST 8 ( =D5) is also conflicting with the resetline in the wiring data where D7 is used. It is confusing. I am currently struggling connecting a 7789 240*320 tft to my nano. your answer is very much appreciated.

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.
I suggest you try changing it in the code and see if it works.
image

@Herman-RFguy
Copy link

Thank you for answering my questions.
I will investigate it and come back with the results later.

@Herman-RFguy
Copy link

Hi,
It works!
I messed up D numbers with pin numbers.
After that one issue remained.
The clockspeed is very high and the resistive devider i made had too large rise and fall times.
After inserting a level shifter MC14050 3.3V is made for all 5 lines.
Even than the clock pulsewith which is 80ns is too fast for this level shifter.
I have to reduce the SPI speed so the MC14050 can follow .
Not using the SPI speed works fine now

@MazeW
Copy link
Author

MazeW commented Mar 15, 2024

Hi, It works! I messed up D numbers with pin numbers. After that one issue remained. The clockspeed is very high and the resistive devider i made had too large rise and fall times. After inserting a level shifter MC14050 3.3V is made for all 5 lines. Even than the clock pulsewith which is 80ns is too fast for this level shifter. I have to reduce the SPI speed so the MC14050 can follow . Not using the SPI speed works fine now

Interesting, I wired it directly and it seemed to work fine. Also, it appears that I may have named the variables wrongly (CS and RST)

@HDCLovers
Copy link

Hi, It works! I messed up D numbers with pin numbers. After that one issue remained. The clockspeed is very high and the resistive devider i made had too large rise and fall times. After inserting a level shifter MC14050 3.3V is made for all 5 lines. Even than the clock pulsewith which is 80ns is too fast for this level shifter. I have to reduce the SPI speed so the MC14050 can follow . Not using the SPI speed works fine now

Interesting, I wired it directly and it seemed to work fine. Also, it appears that I may have named the variables wrongly (CS and RST)

The manufacturer stated that it works at 3.3V. Since there is no regulator present on the board, supplying 5V directly might work, but it could damage the display over time.

@Herman-RFguy
Copy link

Hi,
I use an ESP32 and TFT with ILI9341 driver now and abandoned the Arduino Nano.
It works perfect and superfast now!

@kdekaluga
Copy link

kdekaluga commented Aug 28, 2024

There are a couple of very important notes about this guide.

First, for both Arduino Uno and Nano the display reset wire must go to the D8 pin, not D7! It still may work with D7 sometimes but very very very unstable (since D7 is floating and we do need to reset the display).

Second, the display works with 3.3 Volts and Arduino outputs high logic level as 5 V, so you need some kind of a level shifter. The easiest one is just 4 resistors connected in series with the each wire (SCL, SDA, RES, D/C). For me 220 Ohm works fine. If you are curious why it works - the display driver IC has diodes connected to the each input pin which conduct excessive positive voltage to the driver power line (+3.3 V). The higher resistor you use, the lower current will flow through it, but a too high value may result in transmission speed reduction.

And the last one - probably you need to use SPI_MODE3 instead of SPI_MODE2 since ST7789 datasheet stays it samples the data pin at the rising edge of the clock signal. It still works with SPI_MODE2 (since Arduino delays the clock signal a few nanoseconds relative to the data one and it's enough for ST7789), but for me with both CPOL and CPHA (== SPI_MODE3) it works more stable.

@lucasvonherder
Copy link

Hi, great instructions. Unfortunately It does not work for me. I followed it to the letter but my screen stays black. After a lot of trying to fix it I saw some image on the screen but with a los of noise (grey stripes). I am using the same display and a nano clone. I also tried with different displays and arduinos but no luck, same issue. Any idea?

@MazeW
Copy link
Author

MazeW commented Sep 21, 2024 via email

@lucasvonherder
Copy link

I tried most of it but not changing from D7 to D8 because I stupidly directly fixed everything with hard wires.
I think I will switch to ESP32 aswell since also the Wifi connection will be helpfull in the end :)
Thanks for answering!

@JackIsGoofingOff
Copy link

I am using an Arduino Nano ESP32, is the wiring the same?

@MazeW
Copy link
Author

MazeW commented Oct 17, 2024

I am using an Arduino Nano ESP32, is the wiring the same?

Not quite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment