PlatformIO Community

Simple Arduino ESP8266/NodeMCU Example not working from PIO but works from Arduino IDE

I just got a couple of NodeMCU Boards (ESP8266MOD) and while trying to test it doesn’t work from PIO. Upload complete with success but code never executes.

Sample code being tested is as simple as bellow:

#include <Arduino.h>

void setup() {
  pinMode(LED_BUILTIN_AUX, OUTPUT);     
  pinMode(D6, OUTPUT);     
}

void loop() {
  digitalWrite(D6, HIGH);
  delay(80);
  digitalWrite(D6, LOW);

  digitalWrite(LED_BUILTIN_AUX, LOW);  
  delay(80);
  digitalWrite(LED_BUILTIN_AUX, HIGH); // BUILTIN_AUX turnoff with HIGH level

  delay(4000);
}

esptool output from arduino is:

Executable segment sizes:
IROM : 228672 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 26752 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs…)
DATA : 1248 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 688 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 24880 ) - zeroed variables (global, static) in RAM/HEAP
Sketch uses 257360 bytes (24%) of program storage space. Maximum is 1044464 bytes.
Global variables use 26816 bytes (32%) of dynamic memory, leaving 55104 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting…
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 40:f5:20:28:5d:2f
Uploading stub…
Running stub…
Stub running…
Changing baud rate to 460800
Changed.
Configuring flash size…
Auto-detected Flash size: 4MB
Compressed 261520 bytes to 193142…
Wrote 261520 bytes (193142 compressed) at 0x00000000 in 4.3 seconds (effective 484.1 kbit/s)…
Hash of data verified.

Leaving…
Hard resetting via RTS pin…

Output from PIO Upload is:

Executing task in folder HelloWorld ESP01: platformio run --target upload --environment nodemcu <

Processing nodemcu (platform: espressif8266; board: nodemcuv2; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/nodemcuv2.html
PLATFORM: Espressif 8266 (2.6.2) > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:

  • framework-arduinoespressif8266 3.20704.0 (2.7.4)
  • tool-esptool 1.413.0 (4.13)
  • tool-esptoolpy 1.20800.0 (2.8.0)
  • tool-mklittlefs 1.203.200522 (2.3)
  • tool-mkspiffs 1.200.0 (2.0)
  • toolchain-xtensa 2.40802.200502 (4.8.2)
    LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 29 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    Compiling .pio/build/nodemcu/src/main.cpp.o
    Generating LD script .pio/build/nodemcu/ld/local.eagle.app.v6.common.ld
    Archiving .pio/build/nodemcu/libFrameworkArduinoVariant.a
    Indexing .pio/build/nodemcu/libFrameworkArduinoVariant.a
    Compiling .pio/build/nodemcu/FrameworkArduino/Crypto.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/Esp-frag.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/Esp-version.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/Esp.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/FS.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/FSnoop.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/FunctionalInterrupt.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/HardwareSerial.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/IPAddress.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/MD5Builder.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/Print.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/Schedule.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/StackThunk.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/Stream.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/StreamString.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/Tone.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/TypeConversion.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/Updater.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/WMath.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/WString.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/abi.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/base64.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/cbuf.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/cont.S.o
    Compiling .pio/build/nodemcu/FrameworkArduino/cont_util.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_app_entry_noextra4k.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_eboot_command.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_features.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_flash_quirks.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_flash_utils.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_i2s.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_main.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_noniso.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_phy.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_postmortem.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_si2c.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_sigma_delta.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_spi_utils.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_timer.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_waveform.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_wiring.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_wiring_analog.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_wiring_digital.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_wiring_pulse.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_wiring_pwm.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/core_esp8266_wiring_shift.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/crc32.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/debug.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/flash_hal.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/gdb_hooks.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/heap.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/libb64/cdecode.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/libb64/cencode.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/libc_replacements.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/sntp-lwip2.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/spiffs/spiffs_cache.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/spiffs/spiffs_check.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/spiffs/spiffs_gc.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/spiffs/spiffs_hydrogen.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/spiffs/spiffs_nucleus.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/spiffs_api.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/sqrt32.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/time.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/uart.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/umm_malloc/umm_info.c.o
    Compiling .pio/build/nodemcu/FrameworkArduino/umm_malloc/umm_integrity.c.o
    Compiling .pio/build/nodemcu/FrameworkArduino/umm_malloc/umm_local.c.o
    Compiling .pio/build/nodemcu/FrameworkArduino/umm_malloc/umm_malloc.cpp.o
    Compiling .pio/build/nodemcu/FrameworkArduino/umm_malloc/umm_poison.c.o
    Archiving .pio/build/nodemcu/libFrameworkArduino.a
    Indexing .pio/build/nodemcu/libFrameworkArduino.a
    Linking .pio/build/nodemcu/firmware.elf
    Retrieving maximum program size .pio/build/nodemcu/firmware.elf
    Checking size .pio/build/nodemcu/firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [=== ] 32.7% (used 26776 bytes from 81920 bytes)
    Flash: [== ] 24.6% (used 256684 bytes from 1044464 bytes)
    Building .pio/build/nodemcu/firmware.bin
    Creating BIN file “.pio/build/nodemcu/firmware.bin” using “/home/lamaral/.platformio/packages/framework-arduinoespressif8266/bootloaders/eboot/eboot.elf” and “.pio/build/nodemcu/firmware.elf”
    Configuring upload protocol…
    AVAILABLE: espota, esptool
    CURRENT: upload_protocol = esptool
    Looking for upload port…
    Use manually specified: /dev/ttyNodeMCU
    Uploading .pio/build/nodemcu/firmware.bin
    esptool.py v2.8
    Serial port /dev/ttyNodeMCU
    Connecting…
    Chip is ESP8266EX
    Features: WiFi
    Crystal is 26MHz
    MAC: 40:f5:20:28:5d:2f
    Uploading stub…
    Running stub…
    Stub running…
    Changing baud rate to 460800
    Changed.
    Configuring flash size…
    Auto-detected Flash size: 4MB
    Compressed 260832 bytes to 192745…

Writing at 0x00000000… (8 %)
Writing at 0x00004000… (16 %)
Writing at 0x00008000… (25 %)
Writing at 0x0000c000… (33 %)
Writing at 0x00010000… (41 %)
Writing at 0x00014000… (50 %)
Writing at 0x00018000… (58 %)
Writing at 0x0001c000… (66 %)
Writing at 0x00020000… (75 %)
Writing at 0x00024000… (83 %)
Writing at 0x00028000… (91 %)
Writing at 0x0002c000… (100 %)
Wrote 260832 bytes (192745 compressed) at 0x00000000 in 4.3 seconds (effective 485.5 kbit/s)…
Hash of data verified.

Leaving…
Hard resetting via RTS pin…
======================================================== [SUCCESS] Took 15.39 seconds ========================================================

Terminal will be reused by tasks, press any key to close it.

  • I notice size is different on PIO but could not figure out what is the difference.

I’ve already expended many hours researching with no luck so far.

Okay. I am kind of embarrassed now.
I have the habit of keeping all applications running for long time on my computers. That was not different with the VSCode/PIO on this VBox machine.
After I shutdown and restart VSCode it looks to be working now. - I am not sure why I didn’t try it before, but I hope that my mistake might help someone else on the future.

:blush: