Hi all, I’m trying to compile an example web radio sketch which was built using platformio - I usually use the Arduino IDE, so the Platformio is all new to me. I think I’ve installed/configured things correctly but every sketch I try and compile comes up with undefined reference to loop() and setup().
This is the sample code I’m trying:
#include <Arduino.h>
void setup() {
// Initialize serial communication at 9600 bits per second
Serial.begin(9600);
}
void loop() {
// Print "Hello, World!" to the serial monitor
Serial.println("Hello, World!");
// Wait for a second
delay(1000);
}
Please show the corresponding platformio.ini
so we get a clue which platform and settings are used.
Please make sure that there is just one single project folder in the current VS Code workspace. Otherwise check if the correct project and environment is selected in the Project Environment Switcher:
Hi, thanks for the quick reply. Here’s the platformio.ini file:
;[env:nodemcuv2]
;platform = espressif8266
;framework = arduino
;board = nodemcuv2
;monitor_speed = 115200
[env:esp32dev]
platform = espressif32
framework = arduino
board = esp32dev
monitor_speed = 115200
I commented out the first env settings - I didn’t know how to switch environments - until this message! I’ve switched the environment from the default to esp32dev - I still get the link errors. I also get nagged about converting the sketch into a cpp file - I don’t know if that’s a good idea or not.
Please check Convert Arduino file to C++ manually — PlatformIO latest documentation
*ino files are not valid C++. The ArduinoIDE does some background tricks to make them work.
PlatformIO is using “real” C / C++, so all C / C++ rules applies.
Sorry, I didn’t address the second suggestion - I’m not sure what you mean by " one single project folder in the current VS Code workspace" - there’s three examples in the examples folder - but they aren’t subfolders of .vscode.
Don’t use the examples directly. They are not PlatformIO Projects!
You have to create a project.
This should give you something like this (a project):
Then edit the “main.cpp”
A “project” is a folder that consist at least a “platformio.ini” in its root folder and some .c or .cpp (e.g. “main.cpp”) files in the subfolder “src” → /src/main.cpp
.
├── .pio
├── .vscode
├── include
├── lib
├── src
│ └── main.cpp
├── test
└── platformio.ini
This is a VS Code worskpace with just a single project open “HELLO_WORLD”
There are no other folders than this project open.
Thanks again. I think I’ve successfully created a project and added the source code into main.cpp. Now it won’t compile because of missing include file - although I’ve added a path to it in the include directories and it’s not being flagged in the source code as missing - I did see something about “wigglies being disabled” - I can’t believe that’s really an option!
Weirdly, it did compile once and upload - but nothing was visible in the terminal.
Maybe your installation got corrupted.
I suggest to “reinstall” your PlatformIO setup:
- Close VS-Code
- delete the
.platformio
folder
Windows: C:\Users\<username>\.platformio
Linux: ~/.platformio
- Restart VS-Code
- Wait until PlatformIO finished installing the missing files