How Can I build a custom Lib w/o a Platformio.ini File?

I want to abstract out a couple of functional components so that I can share them across multiple projects using either ESP-32 or 8266 boards (so, I don’t want a platformio.ini file). I already have these components abstracted out in two separate, board-specific projects, but the components don’t depend on board architecture, so I want to put their code in a common lib.

I see other libs in the repo (PlatformIO Registry) that don’t have a platformio.ini file, but when I try it, I don’t get very far. The first issue is dependencies – I need Arduino.h. Again, looking at other libs, they #include “Arduiino.h”, but I don’t see where they are installing that lib.

What am I missing? Again, for clarity, I have this:

ProjA (ESP-32)
/lib/componentX
/lib/componentY

ProjB (ESP-8266)
/lib/componentX
/lib/componentY

componentX and componentY are architecture-agnostic, but, having them in two places means that they can easily get out of sync. They do, however, use the arduino-style of loop() and setup(), and I need other things from Arduino.h (like String, etc).

I want to put them into a lib (LibA) that I can include in ProjA and ProjB, and each component includes “Arduinio.h”. Do I have to D/L and install Arduino.h for the new lib? I don’t see that in other projects. This one, for instance, has no platformio.in file, and it includes Arduino.h, There are others as well.

Thanks in advance!

Expanding on this: would it work if I created a regular project and just didn’t commit the platformio file? Of course, that would only allow me to build for a single board, but maybe it would allow me to checkin and pull the lib from the registry.

Some time back, I wrote a mini eBook on creating libraries for Arduino, then convrting them to be used with the Arduino IDE or any other AVR IDE, then converting them to be used as libraries in PlatfomIO. You can download the PDF at https://github.com/NormanDunbar/WritingLibraries/releases/download/v1.0.0/WritingLibraries.pdf and hopefully, it will help.

All sources etc are on github. Links in the PDF.

Cheers,
Norm.

Cheers,
Norm.

Thanks, Norm.

So, IIUC, the trick is to use the Arduino IDE (which, obviously, has no need for the platformio file), and then publish to the platformio registry. Brilliant! I will certainly give that a try! If it works (and I’m sure it will), I’ll tag your post as the correct reply.

PS: thanks for the pdf reference, and thanks for putting that together.

1 Like

You can publish Arduino styles/structured libraries and PlatformIO will install them happily. Or you can use the PlatformIO structure to the same effect.

Have fun writing your library. I’ll be here if you have questions. At least regarding AVR microcontrollers.

Cheers,
Norm.

Just confirmed the solution by posting and then installing a custom lib from github – Thanks Norm!

1 Like

Let me know if therevwas anything in the pdf that you thought needed better explaining, was incoreect, etc. I’ll get it fixed if necessary.

Cheers,
Norm.

FWIW, in this case, I followed your procedure, with some slight variation:

  1. I created a new folder (let’s call it “myLib”) in the lib folder of my PlatformIo (Pio) project. MyLib had several subfolders, containing different functional elements of the library.
  2. I #included myLib into my project source, much as you described in your pdf. This allowed me to debug the lib in situ. I should note that I had separate #includes for each of the subfolders, as I did not have a “myLib.h” in the MyLib root.
  3. When I was happy with the lib, I moved it into a new folder, which was mapped to a Git repo (also MyLib), and checked in the code.
  4. I created a tagged release in GitHub and added MyLib to my Pio project as a lib-dep in the Pio ini file.
  5. Pio downloaded the lib, and it worked perfectly.

Thanks again!

1 Like