Posted on

by

in

Common PlatformIO Errors

Introduction

This page will list some of the most common PlatformIO errors that I have encountered while using PlatformIO IDE. PlatformIO is an extension in Visual Studio Code that will allow you to program your microcontroller board.

Please specify upload_port for environment or use global --upload-port option

I encountered the below error while uploading programs from Visual Studio Code to one of my microcontroller boards.

Problem:

Looking for upload port...
Error: Please specify `upload_port` for environment or use global `--upload-port` option.
For some development platforms it can be a USB flash drive (i.e. /media/<user>/<device name>)
*** [upload] Explicit exit, status 1
=============================================== [FAILED] Took 2.03 seconds ===============================================The terminal process "C:\Users\DONSKY\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--target', 'monitor', '--environment', 'esp32dev'" terminated with exit code: 1.

Solution:

I used a different USB Type A cable when uploading my program. It turns out that this cable is only a ‘Charge Only’ cable. Some USB cable data pins are not connected but only the power pins. You would see that your microcontroller board would power up however you would encounter the error above. Make sure that you are using a USB cable that does support data exchange.

PermissionError: [WinError 5] Access is denied

I encountered PermissionError while trying to upload or build a project

Problem

> Executing task: C:\Users\DONSKY\.platformio\penv\Scripts\platformio.exe run --target cleanall --environment esp32dev <

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------Removed .pio\build\esp32dev\.sconsign39.dblite
Removed .pio\build\esp32dev\partitions.bin
Removed .pio\build\esp32dev\src\main.cpp.o
PermissionError: [WinError 5] Access is denied: 'D:\\git\\platformio-projects\\esp32-projects\\esp32-send-ldr-data-websockets\\.pio\\libdeps\\esp32dev\\ESP Async WebServer\\.git\\objects\\04\\8cd02469ae0907bde6f6e847c17899131c9593':
  File "C:\users\donsky\.platformio\penv\lib\site-packages\platformio\builder\main.py", line 155:
    env.PioClean(is_clean_all)
  File "C:\Users\DONSKY\.platformio\packages\tool-scons\scons-local-4.3.0\SCons\Util.py", line 742:
    return self.method(*nargs, **kwargs)
  File "C:\users\donsky\.platformio\penv\lib\site-packages\platformio\builder\tools\piotarget.py", line 64:
    _clean_dir(libdeps_dir)
  File "C:\users\donsky\.platformio\penv\lib\site-packages\platformio\builder\tools\piotarget.py", line 49:
    os.remove(dst)

Solution

It turns out that for some unknown reason my library dependencies got corrupted. The quick fix is to delete the .pio file in your project. This should enforce a manual rebuild of your dependencies again.

Project Tasks are all grayed out or disabled

Problem

All my project tasks (e.g. Build, Upload, Monitor, etc.) are all disabled or grayed out.

PlatformIO Tasks are disbled

Solution

As per this thread in the PlatformIO, we need to update our PlatformIO Extension. After updating, it is now enabled. Yay!

If you don’t know how to manually update your PlatformIO extension then please look here.

PlatformIO Extension After Update

[upload] UnboundLocalError : local variable ‘port’ referenced before assignment

Problem

While uploading my sketch to my microcontroller, I encountered the following issue.

[upload] UnboundLocalError : local variable 'port' referenced before assignment

Solution

My USB cable is not connected correctly to my laptop or workstation. I tried to re-insert and the error was fixed.

A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header

Problem

I encountered the following issue while uploading my sketch to my ESP8266/ESP32 Microcontroller.

Looking for upload port...
Auto-detected: COM3
Uploading .pio\build\esp32dev\firmware.bin
esptool.py v3.1
Serial port COM3
Connecting........_____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
*** [upload] Error 2

Solution

Click the Boot button in your ESP8266/ESP32 Microcontroller.

Brownout detector was triggered

Problem

The below errors are displayed in my Serial Monitor while trying to run my program in my ESP8266/ESP32 Microcontroller board.

Brownout detector was triggered

ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8

Solution

Several factors can cause this issue.

  • A bug in your program causes a memory buffer overflow so to solve it try to comment out each line of your program and upload the sketch.
  • Try to switch the USB to a different USB port and reinsert it properly and then re-upload your sketch again.
  • Power your Microcontroller with a separate power supply. Maybe the current supplied by the USB is not enough for all components in your circuit.
  • If your project is using Wifi functionality then it could be that your microcontroller cannot connect to your Wifi. Try to wait for some time or try reconnecting the USB cable and check the Serial monitor again.

fatal error: SPI.h: No such file or directory

Problem

While building the project you encounter this error.

Solution

Add the following line in your platform.ini configuration file.

lib_deps=
    SPI

fatal error: ESP8266WiFi.h: No such file or directory

Problem

While building the project you encounter this error.

Solution

Add the following line in your platform.ini configuration file.

lib_deps=
    Wifi

Wrap up

I will keep updating this page for common PlatformIO IDE errors that I have encountered so that it would help you somehow whenever you encounter any errors.

Happy Exploring!

Related Posts:

Looking for more projects then head on to my youtube channel.

DonskyTech Youtube Channel
DonskyTech Youtube Channel
If you like my post then please consider sharing this. Thanks!

One response to “Common PlatformIO Errors”

  1. How to upload FileSystem Image in PlatformIO IDE? –

    […] If you encounter an error during uploading like “Timed out waiting for packet header” then please take a look at the solution in A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header. […]

Leave a Reply

Your email address will not be published.