The development and debugging of Arduino, ESP32, ESP8266 or STM32 projects is a little different between PlatformIO and the Arduino IDE that we know very well. In this article lists the main problems that can be encountered as well as (a few) solutions to remedy them. Compilation errors, problem with installing libraries, unable to upload, empty PIO menu …
You know of any other issues with PIO, please tell me about other issues (and possibly the solution) in the comments. You will certainly make people happy!
Compilation errors after migrating a project from the Arduino IDE to PlatformIO
Compiling the C++ code is slightly different from that performed by the Arduino IDE.
When migrating code from the Arduino IDE to a PlatformIO project, you may encounter compilation problems that you did not have before.
The function exists in the code but generates an error during the build
If you are migrating the source code of the MQ-2 project
you will get this error message on the first compilation
Building in release mode
Compiling .pio/build/uno/src/main.cpp.o
src/main.cpp: In function 'int MQGetGasPercentage(float, int)':
src/main.cpp:131:49: error: 'MQGetPercentage' was not declared in this scope
return MQGetPercentage(rs_ro_ratio,LPGCurve);
^
src/main.cpp:133:48: error: 'MQGetPercentage' was not declared in this scope
return MQGetPercentage(rs_ro_ratio,COCurve);
^
src/main.cpp:135:51: error: 'MQGetPercentage' was not declared in this scope
return MQGetPercentage(rs_ro_ratio,SmokeCurve);
^
*** [.pio/build/uno/src/main.cpp.o] Error 1
============================== [FAILED] Took 1.16 seconds ==============================
You might think there was an error in the code but in fact it is not. The compiler finds an error because the MQGetPercentage method is called in the code before it is declared.
Two solutions in this case
- to declare the method at the start of the program. Here for example, it will suffice to add at the start of the program
int MQGetPercentage(float rs_ro_ratio, float *pcurve)
- to move the method to the start of the program so that they are found by the compiler
Fatal error… No such file or directory, a library is missing
If you get this error while compiling the Arduino project
fatal error: xxx.h: No such file or directory
Is that a library is not installed
Building in release mode
Compiling .pio/build/d1_mini_lite/src/main.cpp.o
Compiling .pio/build/d1_mini_lite/lib887/ESP8266WiFi/ESP8266WiFiAP.cpp.o
src/main.cpp:4:17: fatal error: DHT.h: No such file or directory
*************************************************************
* Looking for DHT.h dependency? Check our library registry!
*
* CLI > platformio lib search "header:DHT.h"
* Web > https://platformio.org/lib/search?query=header:DHT.h
*
*************************************************************
To correct this problem, you must manually declare the libraries in the platformio.ini file of the project.
Everything is explained in detail in this tutorial
platformio-ide upload not found, cannot compile or upload (VSCode)
The platformio-ide upload not found error occurs when launching a build (compilation) or an upload while the PlatformIO plugin is still being started on VSCode. The error must also occur on other editors.
It is not really a mistake. You just have to wait for the complete start of the PIO plugin before you can compile and / or upload the Arduino code.
The boot process goes like this
The extensions are activated (Activating extensions …)
The PlatformIO plugin for VSCode is launched and automatically checks if there is an update (Checking PlatformIO Core installation …)
Finally, the IntelliSense index which allows auto-completion is rebuilt, this is the longest operation. Obviously, the duration of the operation will depend on the power of your computer.
Problem with installing a library
PlatformIO is responsible for installing the libraries indicated by the lib_deps option in the platformio.ini configuration file of the project
If you get this error message
[API] ConnectionError: HTTPSConnectionPool(host='api.registry.platformio.org', port=443): Max retries exceeded with url...
where this one
platformio (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
PIO cannot connect to the servers and install the library (s).
This is probably due to an error linked to a PlatformIO Core library which cannot (re) initialize the connection.
Solution There is not much to do in this case. The best is to simply restart the computer!
What to do in case of compilation failure?
Unlike the Arduino IDE, PlatformIO offers an option that allows you to delete the temporary files created during the compilation of the binary file.
If you are having trouble uploading or if you encounter compilation errors (and your source code does not return an error), simply delete the PlatformIO working folder using the Clean option.
All builds and temporary files are deleted with the click of a mouse!
Unable to upload
PlatformIO is unable to connect to the development board to upload the binary file.
Looking for upload port...
Auto-detected: /dev/cu.usbserial-1420
Uploading .pio/build/esp12e/firmware.bin
esptool.py v2.8
Serial port /dev/cu.usbserial-1420
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header
*** [upload] Error 2
============================= [FAILED] Took 27.38 seconds ===================
Here is a list of the most common causes and some possible solutions.
Possible cause | Solution to be tested |
The development board is not connected | ✓ Check that the connector (micro-USB for example) on the development board is not defective. It happens (rarely) that it can be unsoldered.
✓ If other development boards are plugged into the computer, disconnect all boards. ✓ Change USB port |
The module is not in booltload mode | ✓ Do a reset
✓ Disconnect / reconnect / restart the upload ✓ Ditto by changing the USB cable ✓ Same for another USB port ✓ Clear flash memory ✓ Check if the board is detected in the devices ✓ Test with another module … if it still does not after several attempts, consider replacing the module |
Cannot upload to an ESP01
Each time you want to upload a project to the ESP01, it is necessary to put it in Flash Mode (or Boot Load mode).
For that, it is necessary to carry out this assembly (or an equivalent) which can quickly become tedious.
More details by reading this article.
I advise you instead to opt for a programmer dedicated to the ESP01 module. The module combines a 3V3 power supply and a UART converter (serial port) <-> USB for communication.
Problem with serial monitor
You are having communication issues or you are unable to upload your Arduino project.
Here is a list of the main causes and some possible remedies.
Possible cause | Solution to be tested |
The development board is not connected
ESP01 is not in Flash Mode
|
✓ Check that the connector (micro-USB for example) on the development board is not defective. It happens (rarely) that it can be unsoldered.
✓ If other development boards are plugged into the computer, disconnect all boards. ✓ Change USB port |
|
|
The serial port returns incomprehensible characters | ✓ By default PlatformIO connects at 9600 baud. Probably the speed specified in the program is different.
✓ Find the Serial.begin (speed) command to find the speed ✓ Add the option serial_speed = speed in the platformio.ini file and upload again |
rl␀l�r␂$␒�n␌␌␌�␌l�␌b|��␂␇␒�r␒bl␌b␄�nn␂lnn␒b␌b␜p�$b␎lrlp�n� |
Bad Serial Monitor display = bad speed
By default, the serial port is configured at 9600 baud on the official extension. Jun Han added a parameter to set the speed. To use a different speed, open the
If you are using the PlatformIO CLI, open the Terminal and run the following command
pio device monitor -b 115200
You can also specify the speed in the plaformio.ini file using the monitor_speed option.
PlatformIO toolbar is empty
If the Project Tasks menu of the PlatformIO toolbar is empty
Is that you did not open the project in the workspace of Visual Studio Code correctly. We often get this error when opening a folder containing several projects.
To build the Project Tasks list, PIO looks for a platformio.ini file at the root of the folder. If it doesn’t find one, the toolbar remains empty even when opening a subfolder.
Two solutions:
- Open each project individually
- Create a fake platformio.ini file at the root of the folder to make PIO believe it’s a project. Then, each time you open a project, the task list is updated to reflect the configuration.
Updates
11/19/2020 Platformio-ide upload not found error
17/09/2020 Publication of the article
- Develop IoT projects with PlatformIO. Problems and solutions
- Platformio.ini, tips and useful settings. data_dir, monitor_speed, upload_port …
- Migrate a project from the Arduino IDE to PlatformIO. ESP32, ESP8266 or other
- ESP8266. Upload the data folder (SPIFFS or LittleFS) from PlatformIO
- Convert Arduino code into ESP Easy Mega plugin for ESP8266 / ESP32