I'm trying to learn ESP32 with ili9431

I used the Adafruit, no more compile errors.

Now the sketch does not wait for GPIO 0, to trigger low to initiate the On Demand connection.

This is the sketch:

#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
//#include <TFT_eSPI.h>
#include <WiFiManager.h>  // https://github.com/tzapu/WiFiManager


// Pin definitions
#define TFT_CS   10
#define TFT_DC   9
#define TFT_RST  8
#define TRIGGER_PIN 0

// Use hardware SPI
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
//TFT_eSPI tft = TFT_eSPI();       // Invoke custom library
  int x=10;
  int y=20;

#define TFT_GREY 0x5AEB
int timeout = 120;  // seconds to run for




void setup() {
  Serial.begin(115200);
   WiFi.mode(WIFI_STA);  // explicitly set mode, esp defaults to STA+AP

  Serial.begin(115200);
  delay(2000);  // wait for Serial
  Serial.println("\n Starting");
  pinMode(TRIGGER_PIN, INPUT_PULLUP);

  Serial.println("starting Display ili9341 ");

  
  
  tft.begin();


  // Set display rotation (optional, 1 is landscape for some displays)
  tft.setRotation(2); 
  
  // Set background color
  tft.fillScreen(ILI9341_YELLOW);

  

  // Set text size
  tft.setTextSize(3); // Size 1 is 6x8 pixels, Size 2 is 12x16, etc.

  // Set text color
  tft.setTextColor(ILI9341_BLACK);
tft.print("Press the Connect button");
 // is configuration portal requested?

  if (digitalRead(TRIGGER_PIN) == LOW) {
    WiFiManager wm;

    //reset settings - for testing
    wm.resetSettings();
  
    // set configportal timeout
    wm.setConfigPortalTimeout(timeout);
  
    if (!wm.startConfigPortal("OnDemandAP")) {
      Serial.println("failed to connect and hit timeout");
      delay(3000);
      //reset and try again, or maybe put it to deep sleep
      ESP.restart();
      delay(5000);
    }
  }
      //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");

      // Set background color
  tft.fillScreen(ILI9341_RED);

  

  // Set text size
  tft.setTextSize(3); // Size 1 is 6x8 pixels, Size 2 is 12x16, etc.

  // Set text color
  tft.setTextColor(ILI9341_WHITE);
  tft.print("WIFI connected");
  delay(10000);

}

void loop() {
  for (int y=20; y <= 300; y=y+20){
  
  
    // Set cursor position (X, Y)
  tft.setCursor(x, y);
  
   // Print the message
  tft.print("Hello world");
 

  delay(1000);
  tft.fillScreen(ILI9341_YELLOW);
  //y=y+20;
  }
}

I forgot to mention, the display works, scroll top bottom “Hello world”

@sonofcy

Like always, can you help please?

Help what? Show me ALL source code including any h files and the verbose error log.

The sketch is above. The sketch compiles and uploads.

Just that is not doing as it is supposed to do. It is supposed to stop waiting for GPIO 0 to go low, after start the WIFI on Demand and once connected to go to the display “Hello world”

Nothing in your code tells it to wait for that input to go LOW. It simply checks if it is LOW. If so, it configures the WiFi. Otherwise it just moves on display text on the screen.

Put a debug statement immediately after the following to see if the trigger pin is being manipulated by the ESP32 immediately following the boot process.
This behaviour is ESP board dependent.

If your debug message is shown then try increasing the delay at the beginning of setup.
If the debug message is not shown but the Wifi managers starts anyway, then you have to check its documentation to see if your configuration could trigger an auto start of the Wifi manager. I don't use Wifi manager so I can't help with it.

Anyway, show what appears on the serial console during a start up.

That's great, that's the hard part.

The code for the WiFiMgr you copied from the Examples, correct?

Yes,

Read the code, that is not what that code does. Your sketch is probably working just fine.

Following up on @6v6gt 's post 28, goto the randomnerdstutorial site and study the esp32 pinout docs.

If you are copying working code and do not know how it works, you may want to step back and study a resource like the Arduino Cookbook.

The answer to your problem has already been provided.

@6v6gt

This the serial monitor:

load:0x3fff0030,len:4980

load:0x40078000,len:16612

load:0x40080400,len:3500

entry 0x400805b4


 Starting

starting Display ili8341 

ets Jul 29 2019 12:21:46


rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0xee

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

mode:DIO, clock div:1

Is that all. One of these messages should have appeared.

Did you add the debug line mentioned in post #28 ?

Also say what you are seeing that you believe that the wifi manager has actiually started.

@6v6gt

In the serial monitor it goes up Starting, Starting display and after plenty of HEX codes and again repeating.


@6v6gt

Code wise:

Serial.println("\n Starting");
  pinMode(TRIGGER_PIN, INPUT_PULLUP);

  Serial.println("starting Display ili9341 ");

and after it loops

The Task Watchdog Timer for Core 1 fired. It's not easy to get it to do that on Core 1. To debug, I'd rip out all the TFT stuff and try just the WiFi using the Serial Monitor for debug prints. Once that works, add the TFT back in.

This is the similar sketch, working, with OLED:

/**
 * OnDemandConfigPortal.ino
 * example of running the configPortal AP manually, independantly from the captiveportal
 * trigger pin will start a configPortal AP for 120 seconds then turn it off.
 * 
 */

#include <WiFiManager.h>  // https://github.com/tzapu/WiFiManager

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128     // OLED display width, in pixels
#define SCREEN_HEIGHT 32     // OLED display height, in pixels
#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
String Oledtext;
String y;
String x;

// select which pin will trigger the configuration portal when set to LOW
#define TRIGGER_PIN 0

int timeout = 120;  // seconds to run for

void setup() {

  WiFi.mode(WIFI_STA);  // explicitly set mode, esp defaults to STA+AP

  Serial.begin(115200);
  delay(2000);  // wait for Serial
  Serial.println("\n Starting");
  pinMode(TRIGGER_PIN, INPUT_PULLUP);

  Serial.println("starting OLED ");
  Serial.println("Waiting for Connect button");



  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
   // Show initial display buffer contents on the screen --

  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

// Here, waiting for the OnDemand display the message "Press connect button"
  x = "Push connect button";
  showoled (x);
}


void loop() {
  // is configuration portal requested?

  if (digitalRead(TRIGGER_PIN) == LOW) {
    WiFiManager wm;

    //reset settings - for testing
    wm.resetSettings();
  
    // set configportal timeout
    wm.setConfigPortalTimeout(timeout);
  
    if (!wm.startConfigPortal("OnDemandAP")) {
      Serial.println("failed to connect and hit timeout");
      delay(3000);
      //reset and try again, or maybe put it to deep sleep
      ESP.restart();
      delay(5000);
    }
  
    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");

    x = "Wifi connected";
    showoled(x);
  
delay(5000);
    Serial.print("Next thing to do");
    x = "Now we go on";
    showoled(x);

}
}
void showoled(String x) {
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print(x);
  display.display();
}

The logic of the working oled code in post #38 is different. Button GPIO0 (trigger_pin) is tested in the loop.

Does the repeating stream of hex codes (mentioned in post #35) that emerge on the serial console from the code in post #22 also happen when GPIO0 is not pressed?

The timing of the press of the button is important because its pin GPIO0 must be high at boot time .

Incidentally, code like this with a blocking for loop can cause continuous crashes:

Not with normal Arduino code running on a Dual Core ESP32. By default, no Core 1 tasks are subscribed to the Task Watchdog Timer (TWDT), not even the Idle Task. You can crash Core 1 using a blocking loop like that if you first disabled interrupts. Then the Interrupt Watchdog Timer (IWDT) will fire.

Check if any library is missing. I can see that you included some libraries at the beginning of your code. Make sure that those are properly installed in your device. If it is your first project with the ESP32, make sure that you have performed the board installation part properly.