I’m new to PIO and this forum, but I have some experience with the Arduino IDE and VS Code.
I’ve been struggling to get library examples to work in VS Code with PIO, specifically the Heltec ESP32 LoRa V3 library. I need to get this working for a school project, so any assistance would be greatly appreciated.
platformio.ini:
Platform = espressif32
Board = heltec_wifi_lora_32_V3
Framework = arduino
lib_ldf_mode = deep+
I successfully ran the traditional Arduino Blink example on this board (compiled and uploaded directly from PIO in VS Code). Next, I installed the “Heltec ESP32 LoRa V3” library using the PIO Library Manager and copied the example code from the SimpleDemo.ino file in the library examples into main.cpp in the src folder of my project.
Issues Encountered:
Include Statements:
In the Arduino IDE, I didn’t need to manually include some files (e.g., #include "SSD1306Wire.h"), but in PIO, I encountered the following error:
fatal error: SSD1306Wire.h: No such file or directory
Adding these lines fixed this issue (and similar errors):
Missing File (images.h):
I’m still facing an issue with the images.h file included in the example:
fatal error: images.h: No such file or directory
This file is located in the example folder of the library (same folder as linked above), but I’m unsure how to correctly reference it in PIO.
Questions:
Differences to Arduino:
Why do I need to explicitly include "SSD1306Wire.h", <Wire.h>, etc., in PIO but not in the Arduino IDE?
Library Dependencies:
Does PIO automatically install all dependencies when a library is installed? (I read, that it does, but the described behavior shows otherwise…)
Include Paths:
Where does PIO save the library files? What is the correct syntax to include these files in the build so I can use them in my code?
Library Folder Usage:
How should I correctly include files like images.h from the example folder? Should I manually place them in the lib folder or reference them differently? When is it appropriate to use the lib folder in the project?
JSON config:
What role does library.json play?
I hope you can point out where my misunderstanding of the PIO concept is. I’m trying to understand why the approach that works in the Arduino IDE isn’t working the same way in PIO.
I’d greatly appreciate any guidance, tutorials, or other reading recommendations, as I’m finding the official documentation overwhelming.
That depends on the library’s manifest (library.json).
If there are dependencies declared, platformio will install them.
a) <project folder>/.pio/libdeps/<library-name>
b) #include <headerfilename.h>
In this case: #include <heltec_unofficial.h> as it is done in the example code
Should be fixed by #2 from above.
This file belongs to the project, not to the library. Therefore you have to copy the file to your projects src or include folder.
Dear Boris @sivar2311 , thank you so much for your help!
I fixed the #include <Arduino.h>, and
copied images.h to the include folder.
Now, everything is working! I think part of my confusion was that the .pio folder is usually hidden…
For my general understanding:
I’m used to integrating (example) files directly from the library to avoid redundancies. I tried: #include "../.pio/libdeps/heltec_wifi_lora_32_V3/Heltec_ESP32_LoRa_v3/examples/display demos/SimpleDemo/images.h
(instead of copying the images.h file to the include folder) and it works as well.
Is this considered bad coding style in PIO and should be avoided, or is it just fine? Am I missing something?
And one last question about PIO behavior:
In Arduino, there is a library and board manager. I think I’m now familiar with the basics of how PIO handles libraries, and I guess that the board selection in the PIO project menu is the equivalent of the Arduino Board Manager. In the Arduino IDE, I can see where the board library comes from and which version it is:
In contrast to the ArduinoIDE, the libraries are not installed globally but per project. You have to get used to this at first. This allows you to use different versions of the same library for different projects.
The libraries are downloaded from the respective source (e.g. PlatformIO Registry, GitHub etc.) into the .pio/libdeps/<environment>/<library-name> folder as required.
There are several causes that can delete this folder. The libraries are then downloaded again and your changes are gone.
The projects are designed to be reproducible. If you share a project, you usually do not share the .pio folder. The required libraries are handled by the platformio.ini. Here too, your changes are no longer included.
Furthermore, the “Example” folder is not part of the library source code. It contains example projects. The files are intended for you to use in your project and are therefore part of the project - not the library.
Click on the PIO icon / Libraries and select the Installed tab at the top.
You’ll see a list of your Projects and which libraries are installed to that project.
Remember, libraries are installed per project.
First, thank you once again for your previous help! I know I’ve been quiet over the past few weeks due to other commitments, but I’ve picked up the project again and have a few follow-up questions.
Your guidance has really helped me understand how PIO handles libraries, and I now feel confident using the Library Manager and specifying dependencies directly in the platformio.ini file. However, I’m still trying to fully understand how PIO manages boards compared to the Arduino IDE:
In Arduino IDE, the Board Manager and Library Manager are clearly separate. I found the equivalent for libraries in PIO, but I’m curious about boards. Specifically, does adding the following line in platformio.ini:
automatically include the necessary files and dependencies (like those found here), or do I need to manually include this as a separate “normal” library as well?
Lastly, I have a question regarding configuration options. In the Arduino IDE, we usually set parameters like port, upload speed, and other options through the “Tools” menu (see image below). How can I configure these in PIO? Is there an equivalent way to set these parameters within the platformio.ini file?
If you install the Espressif32 platform, all supported boards are installed with that Platform to your system.
Check the path C:\Users\<username>\.platformio\platforms\espressif32\boards
There you should see a heltec_wifi_lora_32_V3.json where you can find the basic settings for this board.
The ArduinoIDE creates all the settings for the board from the boards.txt file.
The settings for your boards starts in line 24677.
It’s a bit tricky and hard for me to explain how this works.