I ported my Arduino project from the Arduino IDE to vscode+PlatformIO. My project is designed to run on ESP8266 and ESP32. In the code I use #ifdef tags to conditionally include the correct libraries as well as to compile the appropriate code snippet for a specific platform e.g.:
#ifdef ESP8266 #include <ESP8266WiFi.h> #include <WiFiClientSecure.h> #include <LittleFS.h> #define WIFIMCU "ESP8266" #endif #ifdef ESP32 #include <WiFi.h> #include <WiFiClientSecure.h> #define WIFIMCU "ESP32" #endif
Vscode seems to support the idea of one board per project when I imported the project into vscode+PlatformIO, I specified the ESP32 board as this is what I was currently working on.
In due course I found that one can add additional env: tags to the platformio.ini file so I did this:
[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 [env:esp8266dev] platform = espressif8266 board = esp12e framework = arduino monitor_speed = 115200
When I hit the compile button, the compiler will now link and compile the code for both boards. The problem is that when I hit upload, it then tries to upload both binaries. Due to the safeguards on the board (fuses etc) the upload obviously fails for the binary that does not match the hardware. I am currently working around this by commenting out the code block for the board that I am not working with.
Do I have to split my “project” into two separate folders, one for each board, or is it possible to configure platformio.ini so that the uploader will only attempt to upload the code for the board is currently plugged in, or at least provide a means for me to manually select which platform version I want to upload?