Integration of API modules classes etc. Best Practice

What is the best practice when it comes to integrating external libraries to a project. For instance, I work on an Arduino project, to use the on board microphone I have to include a class that I can either refer in a git submodule or just copy it from the sketch examples and past it in my repo. The class can't run without an other class from an other API related to Arduino, which I can do the exact same, submodule or copy past.

-The problem I have with submoduling with git is that it clones complete repository to just refer one or two files.

-While if I copy past, I lose track of what came from where.

I am inclined to use the copy-past option with a document tracking the API and classes I use, but I fail to find any 'best practice' about that subject and maybe don't use the right words to find such thing?

If anyone can enlighten me that would be great.

See the depends option in Redirecting.

Copy-paste is impossible to maintain, and submodules are not cloned by default and not included when you download the ZIP file from GitHub.

1 Like

Thanks Pieter for the quick reply.
Is it possible to not use the Arduino IDE or web app?
I ask that because the Arduino core mbed seems not to install using arduino-cli. Any mbed core I've tried to install that way all returned an error missing a header file containing the name of the repo.

I use symlinks from git folder to libraries folder in sketchbook

1 Like

I'm still trying to work it out with symlink folling the installation steps in ArduinoCore-mbed, I've been stuck for hours at removing api from mbed/cores/arduino and replace it to ArduinoCore-API/api.
Do i just rm -r the one from mbed? I am not sure about updating the one from ArduinoCore next. Is it something like?:
ln -v mbed/cores/arduino/api ArduinoCore-API/api

why do you do that? Arduino API is copied and customized for specific cores

As I said, I'm trying to not use the Arduino IDE. This is the API used on my board.
I don't want to just program sketches to send to my Arduino, I want to learn to run program that can interact and use my Arduino. The Arduino IDE seems to be limited to sketches, I may be wrong.
I understand that sometime people use Arduino for prototyping, then create their own board, that is why I want to learn how not to be dependent on Arduino IDE.
For instance when I use vs code instead, it calls a class in mbed for nano that the Arduino IDE can read, but not VS code.

For me it just works when I run

arduino-cli core install arduino:mbed_nano

A “sketch” is just a C++ source file with function prototype hoisting and an invisible #include <Arduino.h> at the top.

You don't have to use the IDE, but if you're going to be using the Arduino Cores, it's much easier to use the arduino-cli or PlatformIO. You can of course install the entire toolchain from scratch, define all build rules yourself, etc. but unless you have very specific requirements, that's a waste of time.


1 Like

Thanks for the reply I will try that cli install. I see that I'm not the only one trying this. I just found that I am not the only one in lack of documentation for that. I guess Arduino wants to keep users closer to their monthly plans, which is ok.

When I try to open a cpp of a sketch in VS code IDE, it can't read the class from mbed for nano that it include, for instance PDM.h.
I guess that by installing arduino-cli core install arduino:mbed_nano, as in python and installing library, c++ in VS code will be able to read the PDM.h file fron mbed_nano.
EDIT: Well I just tried the cli command and it says that it is already install, So I guess that is not the way make VS code read the mbed class. I will try what it is said on that other post.

Why do you expect VS Code find that file?
By default, VS Code is set up for native C++ development. If you want to develop for a microcontroller, you need to set up an entire cross-compilation toolchain, install the necessary libraries and support files, point your build system to these files, and then point your IDE to them as well.

This is just a highly advanced topic, there's little documentation because most people never try this, and it is expected that the ones that do already know what they're doing. There's no magic involved in how the Arduino IDE builds your code, it just handles all the messy toolchain configuration for you. The source code is available, you can see exactly how the entire build process works.

I don't believe this has anything to do with “monthly plans” (last time I checked the Arduino IDE and tools were still free and open-source). It's just a matter of spending developer and documentation time where it matters: APIs and features that people actually use. Documenting exactly how to build code for the dozens of different Arduino platforms is a waste of time if 99.999% of Arduino users are never going to need or use it.

1 Like

Thank you very much. I'm sorry, I didn't meant to sound accusative. I thought this is what the core was aiming to do by showing an alternative to Arduino IDE installation.
I see that you have learned about it, people in similar topics other than the one I stated have try to find this too. I understand it is not the usual hobbyists path, which I am not, I have a budget for prototyping and look for the right device, which is what I was advertised for by Arduino.

Don't worry, I'm not affiliated with Arduino :slight_smile:

If this is for educational purposes, I'd look into cross-compilation with CMake. It's the de facto standard build system for C++, and is supported by pretty much all IDEs. You'll need to install the manufacturers board support files, hardware abstraction layers, linker scripts, etc. Setting all of this up is not trivial, but an interesting learning experience.
If this is a commercial project, you might be better off just using the manufacturer's tools, or using something like ARM mbed. These will offer more customization options than Arduino, but there will still be some level of “magic” involved in the build process. The advantage is that you can get support more easily.

1 Like

You should know that differences between MCU's and PC's change what code works best and in some cases, at all.

With AVR's the Instruction Pointer always points to flash, with PC's it points to RAM. Work-arounds will tend to make less efficient algorithms for instance.

With AVR's you get small RAM with a much larger flash to hold run hex and constant data. Plan your heap before you code and don't change it. You can make a buffer for class objects and manage that instead of using dynamic allocation (aka heap shotgunning) built into C++ approach with Container Classes used in PC API's.

It's a bit like SD storage. If you access it with hard-drive code you can wear the SD out in less than a day. Use should fit the hardware.

Alternative to the Arduino IDE is the free Studio at the Microchip site, runs on Winblows so maybe they have compatible VS already.

1 Like

Thanks for the replies and advices guys, it was really helpful.
It led me to find platformIO extention for VS code, it handle all the necessary libraries, the debug and compilation. It seems to be very well done so far.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.