ESP32 Arduino builds and uploads but does not work

Hi there,

I justed started with PIO and tested it with an ESP32 borad. Compiling und uploading seems to work. At least this is what PIO tells me:

 Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
  -------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 1.11.1 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: toolchain-xtensa32 2.50200.80 (5.2.0), tool-mkspiffs 2.230.0 (2.30), framework-arduinoespressif32 2.10004.191002 (1.0.4), tool-esptoolpy 1.20600.0 (2.6.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 29 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SPI> 1.0
|-- <TFT_eSPI> 1.4.21
|   |-- <SPIFFS> 1.0
|   |   |-- <FS> 1.0
|   |-- <SPI> 1.0
|   |-- <FS> 1.0
Building in release mode
Retrieving maximum program size .pio/build/esp32dev/firmware.elf
Checking size .pio/build/esp32dev/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   4.8% (used 15804 bytes from 327680 bytes)
Flash: [==        ]  20.4% (used 266839 bytes from 1310720 bytes)
Configuring upload protocol...
AVAILABLE: esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: /dev/cu.SLAB_USBtoUART
Uploading .pio/build/esp32dev/firmware.bin
esptool.py v2.6
 Serial port /dev/cu.SLAB_USBtoUART
Connecting........_
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 24:6f:28:af:e9:68
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 15872 bytes to 10319...
Wrote 15872 bytes (10319 compressed) at 0x00001000 in 0.3 seconds (effective 503.0 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 128...
Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.0 seconds (effective 2671.9 kbit/s)...
 Hash of data verified.
Compressed 8192 bytes to 47...
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 9169.6 kbit/s)...
Hash of data verified.
 Compressed 266960 bytes to 138333...
Wrote 266960 bytes (138333 compressed) at 0x00010000 in 3.4 seconds (effective 626.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
============================================================ [SUCCESS] Took 12.21 seconds ============================================================

When I test the same code with the Arduino IDE everything works as expetected. Any Idea?

Thanks a lot …

Crucial information missing without which we can’t help:

  • what is your platformio.ini
  • what is the code you’re running
  • what hardware are you using
  • what is the execution result when flashed via Arduino IDE and PIO

Asking us why it “does not work” without any code or symptoms given is a shot in the dark, really.

You are right, sorry …

I tried different things and ended up with the following platform.ini:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino

; Build flags for TTGO ESP32 Board with display
build_flags =
  -Os
  -DUSER_SETUP_LOADED=1
  -DST7789_DRIVER=1
  -DTFT_WIDTH=135
  -DTFT_HEIGHT=240
  -DCGRAM_OFFSET=1
  -DTFT_MOSI=19
  -DTFT_SCLK=18
  -DTFT_CS=5
  -DTFT_DC=16
  -DTFT_BL=1
  -DTFT_BACKLIGHT_ON=1
  -DLOAD_GLCD=1
  -DLOAD-FONT2=1
  -DLOAD-FONT2=1 
  -DLOAD-FONT4=1 
  -DLOAD-FONT6=1 
  -DLOAD-FONT7=1 
  -DLOAD-FONT8=1 
  -DLOAD-GFXFF=1 
  -DSPI_FREQUENCY=27000000

I am using an TTGO esp32 Board with the TFT-eSPI library. The code itself works fine with the Arduino IDE. It is just an example from the library.

I think the problem is due to the SPI pin configuration. In Arduino I can simple chosse the right header file, but with PIO I should set some preprocessor makros with build flags. That’s way the different build_flags in the .platform.ini file.

How did you modify what file for the Arduino IDE library?

I followed the instructions from the vendor github page. It means I simple commeted/uncommeted two lines in the User_Setup_Select.h file in the tft_eSPI library folder. Everything else keeps at it is …

uncommneted:
#include <User_Setups/Setup25_TTGO_T_Display.h> // Setup file for ESP32 and TTGO T-Display ST7789V SPI bus TFT

and commented:
//#include <User_Setup.h> // Default setup is root library folder

Why these pins? The file you referenced states

So the backlight pin is wrong and no reset pin is given. So you may have just gotten a black screen. Also, you write

When it the file states #define LOAD_FONT2, no hyphen. And SMOOTH_FONT and SPI_READ_FREQUENCY was forgotten, and SPI_FREQUENCY has a lower value.

Can you this platformio.ini which accurately reproduces the macros:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino

; Build flags for TTGO ESP32 Board with display
build_flags =
  -Os
  -DUSER_SETUP_LOADED=1
  -DST7789_DRIVER
  -DTFT_WIDTH=135
  -DTFT_HEIGHT=240
  -DCGRAM_OFFSET
  -DTFT_MOSI=19
  -DTFT_SCLK=18
  -DTFT_CS=5
  -DTFT_DC=16
  -DTFT_RST=23
  -DTFT_BL=4
  -DTFT_BACKLIGHT_ON=1
  -DLOAD_GLCD
  -DLOAD_FONT2
  -DLOAD_FONT4
  -DLOAD_FONT6 
  -DLOAD_FONT7 
  -DLOAD_FONT8 
  -DLOAD_GFXFF
  -DSMOOTH_FONT
  -DSPI_FREQUENCY=40000000   
  -DSPI_READ_FREQUENCY=6000000 

Thanks a lot. I works perfectly. I guess I was just to eager to get it running and didn’t take the time to recheck what I did. But thanks again.

I’m using the blink test with my ESP32 and getting the same issue. It says success but nothing is responding.

Processing adafruit_feather_esp32s3_tft (platform: espressif32; board: adafruit_feather_esp32s3_tft; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/adafruit_feather_esp32s3_tft.html
PLATFORM: Espressif 32 (6.2.0) > Adafruit Feather ESP32-S3 TFT
HARDWARE: ESP32S3 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-builtin, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)   
PACKAGES:
 - framework-arduinoespressif32 @ 3.20008.0 (2.0.8)
 - tool-esptoolpy @ 1.40501.0 (4.5.1)
 - tool-mkfatfs @ 2.0.1
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - tool-mkspiffs @ 2.230.0 (2.30)
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
 - toolchain-xtensa-esp32s3 @ 8.4.0+2021r2-patch5
Warning! An extra UF2 bootloader image is already added!
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 33 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\adafruit_feather_esp32s3_tft\src\main.cpp.o
Linking .pio\build\adafruit_feather_esp32s3_tft\firmware.elf
Retrieving maximum program size .pio\build\adafruit_feather_esp32s3_tft\firmware.elf
Checking size .pio\build\adafruit_feather_esp32s3_tft\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   9.6% (used 31364 bytes from 327680 bytes)
Flash: [==        ]  19.0% (used 274601 bytes from 1441792 bytes)
Building .pio\build\adafruit_feather_esp32s3_tft\firmware.bin
esptool.py v4.5.1
Creating esp32s3 image...
Merged 2 ELF sections
Successfully created esp32s3 image.
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-builtin, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: COM9
Forcing reset using 1200bps open/close on port COM9
Waiting for the new upload port...
Uploading .pio\build\adafruit_feather_esp32s3_tft\firmware.bin
esptool.py v4.5.1
Serial port COM9
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: f4:12:fa:59:a9:e0
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x002d0000 to 0x002fdfff...
Flash will be erased from 0x00010000 to 0x00053fff...
Compressed 22656 bytes to 14254...
Writing at 0x00000000... (100 %)
Wrote 22656 bytes (14254 compressed) at 0x00000000 in 0.5 seconds (effective 390.4 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 136...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (136 compressed) at 0x00008000 in 0.1 seconds (effective 410.3 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 567.1 kbit/s)...
Hash of data verified.
Compressed 185328 bytes to 119268...
Writing at 0x002d0000... (12 %)
Writing at 0x002d7894... (25 %)
Writing at 0x002de62b... (37 %)
Writing at 0x002e5223... (50 %)
Writing at 0x002eadb8... (62 %)
Writing at 0x002f07bf... (75 %)
Writing at 0x002f5829... (87 %)
Writing at 0x002fb81e... (100 %)
Wrote 185328 bytes (119268 compressed) at 0x002d0000 in 2.5 seconds (effective 584.4 kbit/s)...
Hash of data verified.
Compressed 274960 bytes to 156620...
Writing at 0x00010000... (10 %)
Writing at 0x0001c4e1... (20 %)
Writing at 0x000246cd... (30 %)
Writing at 0x00029ce5... (40 %)
Writing at 0x0002f03f... (50 %)
Writing at 0x000342ae... (60 %)
Writing at 0x0003a5f9... (70 %)
Writing at 0x00044c95... (80 %)
Writing at 0x0004a2d9... (90 %)
Writing at 0x0004fe0f... (100 %)
Wrote 274960 bytes (156620 compressed) at 0x00010000 in 3.3 seconds (effective 657.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
========================================================================================= [SUCCESS] Took 22.14 seconds ========================================================================================= *  Terminal will be reused by tasks, press any key to close it. 

Main.cpp:

#include <Arduino.h>

int led = LED_BUILTIN;

void setup() {
  // Some boards work best if we also make a serial connection
  Serial.begin(115200);

  // set LED to be an output pin
  pinMode(led, OUTPUT);
}

void loop() {
  // Say hi!
  Serial.println("Hello!");
  
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                // wait for a half second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                // wait for a half second
}

platformio.ini:

[env:adafruit_feather_esp32s3_tft]
platform = espressif32
board = adafruit_feather_esp32s3_tft
framework = arduino
monitor_speed = 115200
monitor_rts = 0
monitor_dtr = 0

What was the solution to this?