Cannot drive an ST7789 display from ESP8266 Dev Module

I am trying to drive a 1.54-inch TFT, 240*240 display from an ESP8266 Development Module using the attached sketch.


// ST_7789_240x240TFT_ESP8266_radar
// Floris Wouterlood 21 December 2019
// public domain
// sketch for NodeMCU ESP8266 
// display on a 1.3 inch 3.3V TFT_display with ST7789 controller
// 240 x 240 pixels in this confguration
//
// all x and y coordinates relative to center coordinates x=120 and y=120
// is your screen bigger than 240x240 -- change the center coordinates 

   #include <Arduino_DataBus.h>
   #include <Arduino_G.h>
   #include <Arduino_GFX.h>
   #include <Arduino_GFX_Library.h>
   #include <Arduino_TFT.h>
   #include <Arduino_TFT_18bit.h>
   #include <gfxfont.h>
   #include <Arduino_ST7789.h>                        // hardware-specific library for ST7789
   #include <SPI.h>

   #define TFT_DC    3                               // pin of your choice
   #define TFT_RST   8                               // pin of your choice
   #define TFT_MOSI  7                               // fixed pin
   #define TFT_SCLK  5                               // fixed pin

   Arduino_ST7789 tft = Arduino_ST7789(3, 8);

   // Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST);
  
   #define SCOPE   0x3206                             // scope glass color - CRT like luminescent 
  
// center coordinates
// for screens bigger than 240x240 - change these x-y coordinates

   float center_x = 120;                              // center x of radar scope on 240x240 TFT display
   float center_y = 120;                              // center y of radar scope on 240x240 TFT  display
   float edge_x = 0;
   float edge_y = 0;
   float edge_x_old = 0;                              // remember previous edge x coordinate 
   float edge_y_old = 0;                              // remember previous edge y coordinate 
   float edge_x_out = 0;
   float edge_y_out = 0;
   int j;                                             // for for-next loops
   float angle = 0;
   int radius = 90;                 
   int scope_x = 0;
   int scope_y = 0;


void setup(void) { 
 
   Serial.begin (115200);
   Serial.println ();                                 // cut out the gibberish
   Serial.println ();    
   Serial.println ("Hello! ST7789 TFT radar test");    // test Serial Monitor
   Serial.println ("on NodeMCU ESP8266");           

   // if the display has CS pin try with SPI_MODE0  ** My display has a CS pin
   
   // tft.init(240, 240, SPI_MODE2); // Init ST7789 display 240x240 pixel - rg

   tft.init(240, 240,MODE0); // Init ST7789 display 240x240 pixel
     
   tft.init (240, 240);                               // initialize a ST7789 chip, 240x240 pixels  
   tft.fillScreen (BLACK);
   tft.setCursor (10, 10);
   tft.setTextColor (YELLOW);
   tft.setTextSize (3);
   tft.println ("radar scope initializing");          // initialization message on the TFT display
   tft.println ("............");  
   delay (500);
   tft.fillScreen (BLACK);

// =========== construct the radar scope =====================================================
 
   edge_x = (center_x);
   edge_y = (center_y);
   scope_x = (center_x-119);scope_y = (center_y-119); 
   tft.drawRect (scope_x,scope_y,239,239,RED);        // rectangular scope outer contour
   scope_x = (center_x+90); scope_y = (center_y-100); // right upper screw
   screw();
   scope_x = (center_x-90); scope_y = (center_y-100); // left upper screw
   screw();
   scope_x = (center_x-90); scope_y = (center_y+100); // left lower screw
   screw();
   scope_x = (center_x+90); scope_y = (center_y+100); // right lower screw
   screw();

   angle=0;

// scope CRT
   tft.drawCircle (center_x,center_y, (radius+1), RED);
   tft.drawCircle (center_x,center_y, (radius+2), RED);
   tft.fillCircle (center_x,center_y, radius, SCOPE);   
   tft.fillCircle (center_x,center_y, radius, SCOPE);  
   tft.fillCircle (center_x,center_y,  2, GREEN);
   tft.drawCircle (center_x,center_y, 60, GREEN);
   tft.drawCircle (center_x,center_y, 90, GREEN);
   draw_scale();
}

void loop (){

 for (j=0;j<360;j++) {
   angle = (j*0.01745331);                            // angle is expressed in radians - 1 degree = 0,01745331 radians
   edge_coord ();                                     // calculate beam
   sweep_beam ();
   tft.fillCircle (center_x,center_y,2,GREEN);        // restore centerpoint
   yield();                                           // resest ESP8266 timer and prevents WDT-necessary for NodeMCU

 } 
}

// =============== SUBROUTINES ===============================================================

// calculate beam radial end coordinates and remember previous end coordinates
   void edge_coord (){
   edge_x_old = edge_x;
   edge_y_old = edge_y;
   edge_x = (center_x+(radius*cos(angle)));
   edge_y = (center_y+(radius*sin(angle))); 
   }

// erase old beam and draw new beam  
   void sweep_beam (){
   // overdraw previous beam with scope color    
      tft.drawLine (center_x,center_y,edge_x_old,edge_y_old,SCOPE); 
   // draw new beam position with scope color
      tft.drawLine (center_x,center_y,edge_x,edge_y,GREEN);
   }

// draw screw subroutine
   void screw (){
   tft.drawCircle (scope_x,scope_y, 6,RED);
   tft.drawLine   ((scope_x-11),scope_y,(scope_x+11),(scope_y),RED);   
   tft.drawLine   (scope_x,(scope_y-11),scope_x,(scope_y+11),RED); 
   }

// draw scale marker line segments subroutine
   void draw_scale (){
   j = 0;
   do {
       angle = (j*0.01745331);                        // angle expressed in radians - 1 degree = 0,01745331 radians
       edge_x = (center_x+(radius*cos(angle)));
       edge_y = (center_y+(radius*sin(angle))); 
       edge_x_out = (center_x+((radius+8)*cos(angle)));
       edge_y_out = (center_y+((radius+8)*sin(angle))); 
       tft.drawLine (edge_x,edge_y, edge_x_out, edge_y_out,RED); 
       j = j+10; 
       } while (j<360); 
       }

I get no image on the display. I get the attached error message when I try to upload this sketch.

                                            Error Message

The error message I receive at the bottom of the screen is:

image

The pin wiring and connection diagram used for this sketch is:

I feel as though I have missed loading some Arduino library to make this sketch work, but I am not a guru solving this type of problem.

try replace the above line ^^ with the text below:

Arduino_HWSPI *bus = new Arduino_HWSPI(TFT_DC, -1 /*no chip select*/, TFT_SCLK, TFT_MOSI);
Arduino_ST7789 *gfx = new Arduino_ST7789(bus,  TFT_RST, 2 /* rotation */, true /* IPS */, 240, 240, 0, 80);

if this doesnt work, i recommend using tft_espi. its so much simpler, and has all the commands adafruit has +more. decent tutorial here: tutorial

Hi Grenken,

I adapted some time ago the radarscope sketch to the ESP32WROOM32-240*240 TFT ST7789 display. -- succes, Photoncatcher

here is the sketch (check the wires)

type or paste code here

// WROOM_ST_7789_240x240TFT_ESP32D_radar_nn
// Floris Wouterlood 21 December 2019
// public domain
// sketch for ESP-WROOM-32D
// upload to board type DOIT ESP32 DEVKIT V1
// display on a 1.3 inch 3.3V TFT_display with ST7789 controller
// 240 x 240 pixels in this confguration
//
// all x and y coordinates relative to center coordinates x=120 and y=120
// is your screen bigger than 240x240 -- change the center coordinates
// pin layout:
// GND ---- GND
// VCC ---- 3.3V
// SCL ---- D18
// SDA ---- D23
// RES ---- D4
// DC ----- D2
// BLK -- not connected

#include <Arduino_ST7789.h> // hardware-specific library for ST7789
#include <SPI.h>

#define TFT_DC 2 // pin of your choice
#define TFT_RST 4 // pin of your choice
#define TFT_MOSI 23 // fixed pin
#define TFT_SCLK 18 // fixed pin

Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST);

#define SCOPE 0x3206 // scope glass color - CRT like luminescent

// center coordinates
// for screens bigger than 240x240 - change these x-y coordinates

float center_x = 120; // center x of radar scope on 240x320 TFT display
float center_y = 120; // center y of radar scope on 240x320 TFT display
float edge_x = 0;
float edge_y = 0;
float edge_x_old = 0; // remember previous edge x coordinate
float edge_y_old = 0; // remember previous edge y coordinate
float edge_x_out = 0;
float edge_y_out = 0;
int j; // for for-next loops
float angle = 0;
int radius = 90;
int scope_x = 0;
int scope_y = 0;

void setup(void) {

Serial.begin (9600);
Serial.println (); // cut out the gibberish
Serial.println ();
Serial.println ("Hello! ST7789 TFT radar test"); // test Serial Monitor
Serial.println ("on NodeMCU ESP8266");

tft.init (240, 240); // initialize a ST7789 chip, 240x240 pixels
tft.fillScreen (BLACK);
tft.setCursor (10, 10);
tft.setTextColor (YELLOW);
tft.setTextSize (3);
tft.println ("radar scope initializing"); // initialization message on the TFT display
tft.println ("............");
delay (500);
tft.fillScreen (BLACK);

// =========== construct the radar scope =====================================================

edge_x = (center_x);
edge_y = (center_y);
scope_x = (center_x-119);scope_y = (center_y-119);
tft.drawRect (scope_x,scope_y,239,239,RED); // rectangular scope outer contour
scope_x = (center_x+90); scope_y = (center_y-100); // right upper screw
screw();
scope_x = (center_x-90); scope_y = (center_y-100); // left upper screw
screw();
scope_x = (center_x-90); scope_y = (center_y+100); // left lower screw
screw();
scope_x = (center_x+90); scope_y = (center_y+100); // right lower screw
screw();

angle=0;

// scope CRT
tft.drawCircle (center_x,center_y, (radius+1), RED);
tft.drawCircle (center_x,center_y, (radius+2), RED);
tft.fillCircle (center_x,center_y, radius, SCOPE);
tft.fillCircle (center_x,center_y, radius, SCOPE);
tft.fillCircle (center_x,center_y, 2, GREEN);
tft.drawCircle (center_x,center_y, 60, GREEN);
tft.drawCircle (center_x,center_y, 90, GREEN);
draw_scale();
}

void loop (){

for (j=0;j<360;j++) {
angle = (j*0.01745331); // angle is expressed in radians - 1 degree = 0,01745331 radians
edge_coord (); // calculate beam
sweep_beam ();
tft.fillCircle (center_x,center_y,2,GREEN); // restore centerpoint
yield(); // resest ESP8266 timer and prevents WDT-necessary for NodeMCU

}
}

// =============== SUBROUTINES ===============================================================

// calculate beam radial end coordinates and remember previous end coordinates
void edge_coord (){
edge_x_old = edge_x;
edge_y_old = edge_y;
edge_x = (center_x+(radiuscos(angle)));
edge_y = (center_y+(radius
sin(angle)));
}

// erase old beam and draw new beam
void sweep_beam (){
// overdraw previous beam with scope color
tft.drawLine (center_x,center_y,edge_x_old,edge_y_old,SCOPE);
// draw new beam position with scope color
tft.drawLine (center_x,center_y,edge_x,edge_y,GREEN);
}

// draw screw subroutine
void screw (){
tft.drawCircle (scope_x,scope_y, 6,RED);
tft.drawLine ((scope_x-11),scope_y,(scope_x+11),(scope_y),RED);
tft.drawLine (scope_x,(scope_y-11),scope_x,(scope_y+11),RED);
}

// draw scale marker line segments subroutine
void draw_scale (){
j = 0;
do {
angle = (j0.01745331); // angle expressed in radians - 1 degree = 0,01745331 radians
edge_x = (center_x+(radius
cos(angle)));
edge_y = (center_y+(radius*sin(angle)));
edge_x_out = (center_x+((radius+8)*cos(angle)));
edge_y_out = (center_y+((radius+8)*sin(angle)));
tft.drawLine (edge_x,edge_y, edge_x_out, edge_y_out,RED);
j = j+10;
} while (j<360);
}

type or paste code here

#define TFT_DC 3 // pin of your choice
#define TFT_RST 8 // pin of your choice
#define TFT_MOSI 7 // fixed pin
#define TFT_SCLK 5 // fixed pin

Arduino_ST7789 tft = Arduino_ST7789(3, 8);

What if you use:

   const byte TFT_DC = D3;                               // pin of your choice
   const byte TFT_RST = D8;                              // pin of your choice
   const byte TFT_MOSI = D7;                               // fixed pin
   const byte TFT_SCLK = D5;                            // fixed pin

   Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST);

Thank your sketch photoncatcher. The main problem I have with this sketch is properly setting up the User_Setup_Select.h and User_Setup.h files interfacing tmy 30-pin ESP32 MCU with the ST7789 display. Can you help me with this?

Your pic/dwg shows a NodeMCU.

My apologies. Yes, I meant to say help with the two User_Setup files in order to interface an ESP8266 to an SY7789 display.

Here is my user_Setup_Select.h -- that is if you use Bodmer's TFT_eSPI library for the combination ES32 and ST7789 240*240

// ST7789 240 x 240 display with no chip select line
// this is setup numer 24 copied and renamed

#define ST7789_DRIVER     // Configure all registers

#define TFT_WIDTH  240
#define TFT_HEIGHT 240

//#define TFT_RGB_ORDER TFT_RGB  // Colour order Red-Green-Blue
//#define TFT_RGB_ORDER TFT_BGR  // Colour order Blue-Green-Red

//#define TFT_INVERSION_ON
//#define TFT_INVERSION_OFF

// DSTIKE stepup
//#define TFT_DC    23
//#define TFT_RST   32
//#define TFT_MOSI  26
//#define TFT_SCLK  27

// Generic ESP32 setup
#define TFT_MISO 19
#define TFT_MOSI 23
#define TFT_SCLK 18
#define TFT_CS    -1 // Not connected
#define TFT_DC    2
#define TFT_RST   4  // Connect reset to ensure display initialises

// For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation
//#define TFT_CS   -1      // Define as not used
//#define TFT_DC   PIN_D1  // Data Command control pin
//#define TFT_RST  PIN_D4  // TFT reset pin (could connect to NodeMCU RST, see next line)
//#define TFT_RST  -1    // TFT reset pin connect to NodeMCU RST, must also then add 10K pull down to TFT SCK


#define LOAD_GLCD   // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2  // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4  // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6  // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7  // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8  // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF  // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts

#define SMOOTH_FONT


// #define SPI_FREQUENCY  27000000
#define SPI_FREQUENCY  40000000

#define SPI_READ_FREQUENCY  20000000

#define SPI_TOUCH_FREQUENCY  2500000

// #define SUPPORT_TRANSACTIONS

photoncatcher: Thank you for the User Setup. I was unaware that one could create a complete User Setup in one Notepad document. I continue to learn how to use the User Setup file feature with the Bodmer TFT_eSPI library.
I am making some progress with my setup, but I have some comments and questions:

  1. The sketch you sent to me . . . is this sketch for the 30-pin, ESP32 Development Module? This
    is the ESP Module that I am using.
  2. I get my display screen to light up with some rendition of the radar screen, but it needs a lot of work. I will check the code that you sent to me once more, but I could have a faulty display.
  3. Floris used an ESP8266 module in her posting. I will assemble a User Setup Select file for the ESP8266 module and send it to you in a later posting for you to check out.

I intend to make this sketch work using the 30-pin, ESP32 module and then make it work using the ESP8266 module. I do appreciate your help with my efforts along this line of work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.