How am I supposed to develop a multi-platform library for Arduino?

Hi

currently working on an Arduino project with a gateway and a node where I had to put some shared code into shared h/cpp files (a library).

How am I supposed to develop this library in PlatformIO? If I create a new Arduino project, firstly it asks me about the board (this library is supposed to work on multiple MCUs like atmega328p and ESP8266) and also it creates a main.cpp with the setup and loop thingy.

If I just add the folder with the shared h and cpp files to the workspace, Visual Studio Code tells me to mess with the include paths and that it is unable to include Arduino.h and stuff.

Thanks for advice.

Conditional compiles.

A subversion repository for a benchmark I wrote is https://svn.riouxsvn.com/blindally-pub/bench2/ . You don’t have to download it, as you can just walk through it with a web browser and see the code.

Create your project for the first board you want to support. Then add additional environments for your other boards. Just as an example, having these two environments in my platformio.ini would allow me to compile my code for a STM8 or/and an ESP8266 based board… meaning the code would need conditional compile flags for any board/platform specific various. If I hit the main build option (cropped out) it will build/upload/etc all environments, or you can open the particular one you want to build/upload/monitor/etc.

image

1 Like