PlatformIO Community

[SOLVED] Flash code into ESP8266


#1

Hi everyone,

I’m new with PlatformIO, I’ve started to used it just to try a better alternative to Arduino IDE.

I’ve been testing and working with a ESP8266 module some like this (https://www.ebay.com/itm/ESP8266-ESP-01S-Serial-WIFI-Wireless-Module-Adapter-Breakout-Send-Receive-AP-STA-/123085771963?hash=item1ca87bd4bb).

I’ve been flashing new code (scketchs from Arduino) using the Arduino IDE, and it was good… without problems (I’m using a FTDI module and an small and easy circuit to connect the ESP8266 to may PC).

Recently, I wanted to upload the code written into Platformio, but after to flash it nothing happens… I’ve tested with a very simple Blink code (using the BUILTIN led)… I only see this in the serial monitor (also setting differents velocities 9600, 115200, etc):

--- Miniterm on /dev/ttyUSB0  74880,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
␀␀␀

I only see a lot of " ␀ "…

Anyway if I flash the same code from Arduino IDE, it works.
Let me show the Arduino output:

Archiving built core (caching) in:
/tmp/arduino_cache_293123/core/core_esp8266_esp8266_generic_CpuFrequency_80,
ResetMethod_ck,
CrystalFreq_26,
FlashFreq_40,
FlashMode_qio,
FlashSize_512K0,
led_2,
LwIPVariant_v2mss536,
Debug_Disabled,
DebugLevel_None____,
FlashErase_none,
UploadSpeed_115200_0070b685019b66ed4c542f40904ccc4b.a
Sketch uses 246259 bytes (49%) of program storage space. Maximum is 499696 bytes.
Global variables use 32224 bytes (39%) of dynamic memory, leaving 49696 bytes for local variables. Maximum is 81920 bytes.
Uploading 250400 bytes from /tmp/arduino_build_479072/Blink.ino.bin to flash at 0x00000000

And it’s the output from platformio:

Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 8266 > Espressif Generic ESP8266 ESP-01 512k
SYSTEM: ESP8266 80MHz 80KB RAM (512KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(light)
Collected 26 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pioenvs/esp01/src/main.cpp.o
Archiving .pioenvs/esp01/libFrameworkArduinoVariant.a
Indexing .pioenvs/esp01/libFrameworkArduinoVariant.a
Compiling .pioenvs/esp01/FrameworkArduino/Esp-version.cpp.o
Compiling .pioenvs/esp01/FrameworkArduino/Esp.cpp.o
...
...
Compiling .pioenvs/esp01/FrameworkArduino/umm_malloc/umm_malloc.c.o
Archiving .pioenvs/esp01/libFrameworkArduino.a
Indexing .pioenvs/esp01/libFrameworkArduino.a
Linking .pioenvs/esp01/firmware.elf
Checking program size
text       data     bss     dec     hex filename
255636     3108   29992  288736   467e0 .pioenvs/esp01/firmware.elf
Building .pioenvs/esp01/firmware.bin
Configuring upload protocol...
Looking for upload port...
Auto-detected: /dev/ttyUSB0
Uploading .pioenvs/esp01/firmware.bin
Uploading 262896 bytes from .pioenvs/esp01/firmware.bin to flash at 0x00000000

I’ve used differents setups into “platformio.ini” but I always got the same result the code is flashed successfully but nothing happens.
For example the last configuration that I’ve tried was:

[env:esp01]
platform = espressif8266
board = esp01
framework = arduino
board_flash_mode = qio
; set frequency to 40MHz
board_f_flash = 40000000L
upload_resetmethod = ck
upload_speed = 115200

So, do you have any ideas about what I’m doing wrong? or what am I missing?

Thanks


#2

You need to show the exact code you’re running and tell us how it behaves when you flash the code via Arduino IDE and PlatformIO. Does the final “SUCCESS” message appear in PlatformIO when you flash?


#3

Well, basically the code works fine when I flash it via Arduino IDE and it doesn’t work when I flash it via PlatformIO.

The code is VERY simple, it’s:

#include <Arduino.h>

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(2000);
}

When I flash it via Arduino the built-in led blinks and when I flash via PlatformIO it does nothing (the led is off).

And if I see the Serial Monitor (on PlatformIO) I only see “␀” many times, and it seems that a new “␀” is added in each loop (instead of turn on and off the led), with Arduino in the Serial Monitor I see nothing.

About “SUCCESS” message, yes it’s shown at the end when PlatformIO ends to flash.


#4

That would make perfect sense if the LED_BUILTIN was set to the serial TX pin. Because then your sketch actually bit-bangs the Serial transmit line, because LED_BUILTIN is wrongly defined for your board. Can you try exchanging LED_BUILTIN for the direct number 2 or 1? Reference: https://github.com/esp8266/Arduino/issues/3165.


#5

I did a couple of test based on https://techtutorialsx.com/2017/04/02/esp8266-nodemcu-pin-mappings/ (I know NodeMCU is a bit different)… with the same result…
but really I didn’t test with 1 or 2 … I’m going to test and I’ll let you know what happen…


#6

Finally I’ve tested it, as you said the BUILTIN led is not mapped with the right value. I need to use #2 (it works perfect).
Just to know the builtin led (in my case) is mapped to #1.
Thanks!!