Confused with the library system

Hi, folks!

I couldn’ stand the ArduinoIDE anymore and moved on… However somehow I’m a newbie. I got problems with the library, I tried to understand it but still no clue.

In the project folder there are several sub folders:
.pio
lib
src

Now I wanted to use a lib called “Nextion”. Copied to the lib folder. The problem is, that within the lib uses for example a standard lib: SD.h. The compiler is not able to find the lib. However this is a “standard” lib from the Arduino. “lib\ITEADLIB_Arduino_Nextion-master\NexUpload.h:20:16: fatal error: SD.h: No such file or directory”

When I install the Nextion lib with Platform IO download, there is no problem.

When i uninstall it again, and simply copy the “manually downloaded” lib into the folder …platformio\lib it also doesn’t work.

What is the mistake, i tried to change lib_ldf_mode but that didn’t help me. I like to have all these special libs directly in the project folder.

Would be great if you could help me here.

Could you please show the exact subfolders structure of lib subfolder?

I recommend against copying libraries to the lib folder. Instead, declare them in platformio.ini:

lib_deps =
    Nextion

And don’t forget to clean out the lib folder and delete .pio before the next compile…

This would be difficult. I just copied the standard folders from ArduinoIDE. But yes, there are several subfolders. It would be great if independent from the amount of subfolders VisualCode searches for the files (.c, .h).

Yes, I see this is the better option. But on the other hand I sometimes modify these libraries only for one project. They should not be mixed with “standard libs”. Also when I want to get there years later it can lead to problems - If everything is packed together (libs with the projects) it is ensured that everything works fine…

However I do not understand how to get around this and have to put the Nextion lib with lib_deps into the project

actually you don’t need anything from the arduino framework except your code, I’d guess. in the platformio.ini you simply set the framework to arduino and include the Arduino.h header and then do those setup and loop functions from arduino.

I did exactly that, first I used the library which was installed automatically, then I needed to add some changes, I moved the library folder inside lib and removed it from lib_deps. It worked for me, that’s why I wanted to look at the folders structure.
If you’re on windows, you can issue the following command in the console: tree (path_to_project_goes_here) and copy/paste its output here.

Ah thank you for your hint. Now I just copied (as you did) the lib folder into the project lib folder. Now it works fine! I never tried this, to use the downloaded library from PlatformIO.
With the files provided from GitHub - itead/ITEADLIB_Arduino_Nextion I could get it running. I don’t know what the difference is, but now it works.
:nerd_face:

Jeah, I’ve done this. But the one lib doesn’t work. Thanks

What is so hard about taking a screenshot, or copying the output of a tree listing? :stuck_out_tongue:

Using an Arduino Mega 2560 as the selected board (as the Nextion config defaults require a Serial2 which the Uno doesn’t have, otherwise I would have used that in lieu of knowing what board you are compiling for) I was able to go to the ITEADLIB_Arduino_Nextion release page, download the zip, unzip it to the ‘\lib’ folder, and compile one of the examples. You can see the project layout here.

Now, note that the only tagged ‘release’ version is 0.7.0 (which is also the version that PIO is using) from 2015, but in the main repo it mentions 0.9.0, and there were changes in 2017. Because of changes to the library, the previously example program doesn’t work… First not finding SPI.h, and then when adding the #include for that to main.cpp, SD.h, and then finally SoftwareSerial.h… and then it compiled.

Note: if you use a core that doesn’t supply the SD library (i.e. when you use atmega2560 as the board target, you’re using the MegaCore board support package, which includes the SD.h library, whereas the megaatmega2560 Arduino provided board support package doesn’t, and you need to add the library)…

So in the end, I have …

#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
#include "Nextion.h"

… at the top of my main.cpp file, and the Nextion 0.9.0 from the github master branch compiled just fine … you can see that revision of the files here.

Or, if you want, you can see the setup with the megaatmega2560 board target, meaning I also need to supply the SD library as Arduino bundle it separately to the core, which also compiled just fine once the dependencies were satisfied.

Hopefully being able to see the three distinct versions will help it all make sense. At the end of the day, choice is yours… but be warned that the latest ‘release’ 0.7.0 of the Nextion library is different to the latest code in the master branch of the GitHub! :wink:

2 Likes

Thank you pfeerick! It is as you said, now I get it :grinning:

1 Like

As long I leave you less confused than before, my work is done! :wink:

Seriously though, I hope that helped, and softens the transition from the Arduino IDE to something… better? It’s all a matter of interpretation, but I think PIO + VSCode is better than the Arduino IDE. Now, the Arduino IDE Pro that’s in early development might shake things up a bit, but I think still PIO + VSCode still will easily beat it on flexibility and platform support.