Pin Management for ESP8266

I am trying to make my ESP8266 microprocessor draw and display graphics on an ILI9341 TFT display with a no touch screen.

I am using an Adafruit Graphics Demo sketch for this purpose.

This sketch compiles and uploads to the ESP8266 just fine. The sketch then writes text and calculated elapsed times onto the Serial Monitor. However the ILI9341 screen displays no graphics.

When I try to set the ESP8266 RST Pin LOW in the sketch, I get the following error message associated with the command, digitalWrite(TFT_RST,HIGH):

exit status 1
expected constructor, destructor, or type conversion before '(' token

I don't understand this message, and, consequently I don't know what to do to solve this problem.

The top portion of this sketch follows:

// ##############################################################################
// #
// #       Sketch:  ESP8266_ILI9341_Adafruit_demo_ESP8266_Pin_Mgmt_12_22_23
// #
// #    Interfacing ESP8266 NodeMCU V3 with ILI9341 No Touch TFT display (240x320 pixel).
// #
// #        Microprocessor:  LoLin NodeMCU V3
// #      Board Model Used:  Generic ESP8266 Module
// #               Display:  ILI9341 2.8 Inch TFT SPI 240x320 No Touch Screen
// #
// #                Pin Connections   
// #
// #       TFT SPI ILI9341 
// #            Pins      ESP8266      Wire
// #    #    Label          Pin        Color
// #    1     VCC  -------- VCC   Red
// #    2     GND  -------- GND   Black
// #    3     CS   -------- D2    Brown        
// #    4     RST  -------- D3    Red
// #    5     D/C  -------- D4    Orange
// #    6     MOSI -------- D7    Yellow
// #    7     SCK  -------- D5    Green   
// #    8     BL   -------- VCC   Blue
// #
// ##############################################################################

   #define ILI9341_DRIVER
 
   #include <Adafruit_GFX.h>        // include Adafruit graphics library
   #include <Adafruit_ILI9341.h>    // include Adafruit ILI9341 TFT library
 
   #define TFT_CS    2     // TFT CS  pin is connected to NodeMCU pin D2  
   #define TFT_RST   3     // TFT RST pin is connected to NodeMCU pin D3
   #define TFT_DC    4     // TFT DC  pin is connected to NodeMCU pin D4

    #define TFT_MOSI    7
    #define TFT_SCK     5
    
    #define TFT_MISO    6
   
   int delayTime = 500;

  Adafruit_ILI9341 tft = Adafruit_ILI9341 (TFT_CS, TFT_DC, TFT_RST);

   pinMode(TFT_RST,OUTPUT);

   //  Try to turn the RST Pin LOW and then HIGH

     digitalWrite(TFT_RST,LOW);

      delay(100);

      digitalWrite(TFT_RST,HIGH);
 
void setup() {

 
   Serial.begin (9600);
   Serial.println ("ILI9341 Test!"); 
 
   tft.begin();

What am I doing wrong?

This stuff --

   pinMode(TFT_RST,OUTPUT);

   //  Try to turn the RST Pin LOW and then HIGH
      digitalWrite(TFT_RST,LOW);
      delay(100);
      digitalWrite(TFT_RST,HIGH);

should be in setup() or loop().

Mr. Pancake: Merry Christmas! Thank you for your advice. The error message has gone away. The sketch uploads fine, but no graphics appears on the ILI9341 display.

I'll have to look further for a solution to this display problem.

The error message you're seeing is due to the fact that you're trying to use pinMode() and digitalWrite() outside of a function. These functions are used to control the GPIO pins on the ESP8266, and they need to be called within a function, such as setup() or loop().

Here's how you can modify your code:

#define ILI9341_DRIVER

#include <Adafruit_GFX.h>        // include Adafruit graphics library
#include <Adafruit_ILI9341.h>    // include Adafruit ILI9341 TFT library

#define TFT_CS    2     // TFT CS  pin is connected to NodeMCU pin D2  
#define TFT_RST   3     // TFT RST pin is connected to NodeMCU pin D3
#define TFT_DC    4     // TFT DC  pin is connected to NodeMCU pin D4

#define TFT_MOSI    7
#define TFT_SCK     5

#define TFT_MISO    6

int delayTime = 500;

Adafruit_ILI9341 tft = Adafruit_ILI9341 (TFT_CS, TFT_DC, TFT_RST);

void setup() {
   pinMode(TFT_RST,OUTPUT);

   //  Try to turn the RST Pin LOW and then HIGH
   digitalWrite(TFT_RST,LOW);
   delay(100);
   digitalWrite(TFT_RST,HIGH);

   Serial.begin (9600);
   Serial.println ("ILI9341 Test!"); 

   tft.begin();
}

void loop() {
   // Your code here
}

In this modified version, pinMode() and digitalWrite() are called within the setup() function, which is the correct place to initialize the GPIO pins. The tft.begin() function is also called within setup(), which is the correct place to initialize the TFT display.

Mr. apacalyspe: Thank you for amending my coding and for your kind explanation. I followed your instructions and the error message went away.

However using the Construct method with the Adafruit_GFX and Adafruit_ILI9341 libraries to program the ESP8266 still did not produce any graphics on my ILI9341 TFT Display. This sketch works using Bodmer's set of User Setup files but the Construct method does not work.

Do you have any suggestions?

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