Develop IoT projects with PlatformIO. Problems and solutions

platformio troubleshooting solution
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email
Share on whatsapp

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

  • Recommended 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)
  • Not recommended 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

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!

Nettoyer le dossier de compilation de PIO

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 causeSolution to be tested
The development board is not connectedCheck 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 modeDo 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.

ESP-01 ESP8266 cablage wiring flashing mode_

 

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.

Attention, not all models include a selector allowing to put the ESP01 in Flash Mode.

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 causeSolution 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

Looking for upload port...
Auto-detected: /dev/cu.usbserial-1410
Uploading .pio/build/esp01_1m/firmware.bin
esptool.py v2.8
Serial port /dev/cu.usbserial-1410
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to ESP8266: Timed out waiting for packet header
*** [upload] Error 2
=========================== [FAILED] Took 13.47 seconds =========================
The serial port returns incomprehensible charactersBy 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 visual studio code vscode package

PlatformIO toolbar is empty

If the Project Tasks menu of the PlatformIO toolbar is empty

Le menu Project Task de PlatformIO est vide

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.

We add a platformio.ini file to the root of the projectsThe PIO menu is correctly constructed
add fake platformio ini file folder piofake platformio ini file menu correctly build

Updates

17/09/2020 Publication of the article

Click to rate this post!
[Total: 0 Average: 0]

Are you having a problem with this topic?

Maybe someone has already found the solution, visit the forum before asking your question
Ask your question

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email
Share on whatsapp

Did you like this project ? Don't miss any more projects by subscribing to our weekly newsletter!

We will be happy to hear your thoughts

      Leave a Reply

      DIY Projects