Arduino library development - compiling examples

I’m currently (happily) using platformio and I’m trying it out also to develop arduino libraries.
The pio ci command plays perfectly with the examples folders, but I could not find a similar way to be able to pio run and upload a specific example to my board.

My current “poor man” options are:

  • link the file of the/one example into the src folder and execute pio run
  • switch back to the arduino IDE

Am I missing a more clever way?
thanks in advance

I’ve just added this info to the docs:

See “latest” version of docs: Redirecting...

Is it clear now?

Dear Ivan,
it works like a charm, thanks a bunch!

Hrm, I’m afraid I don’t quite follow. I’ve got a local git tree for, say, esp8266/Arduino. I want to work on my own application, with my own local changes to the arduino core. Espressif 8266 — PlatformIO v6.1 documentation seems sort of on the right path, but only let’s me work with a published branch, not my local code still in development. I’m not sure how the CI commands help?

I have to admit that I find having to use pio ci to build my library examples very frustrating for the following reasons:

  • I have not found a way to tell pio ci which env to build from a platformio.ini file, so I have to create a file per env.
  • It does not obey the lib_dir directive in the platformio.ini file, instead it always insists on downloading libs from the repository
  • It makes for long awkward command lines.

It seems you need to have the environment named the same as the board… i.e.

platform = atmelavr
framework = arduino
board = micro

… would be called when using the micro board type …

pio ci -c platformio.ini --lib="." --board="micro" examples/blinkingLeds/blinkingLeds.ino

In this instance, I told it to use the lib relative from the directory I was running from/working directory, so it didn’t install anything… which is how I would use it in say a TravisCI job, as a prior stage would do the git pull of the library into the working directory.

Thanks for the tip! I tend to have two envs: one for upload via USB and one for OTA upload. Both would be for the same board, so this wouldn’t help much…

Same here… saves full rebuild when I stuff up the code royaly or OTA goes flaky.

I’m starting to see what you mean… if you want the CI to only build certain boards, but need them customised (so you can’t just use the default configuration and the --boards="board_name" parameter… ) … then yeah, it looks like you’d need to use separate configuration files, else it will build all of the configured boards.

And it probably doesn’t read the [lib_dirs] parameter because it’s in the global [platformio] configuration block… but is that actually a problem? [lib_dirs] is the same as the --lib parameter … and since you’re refering to the downloads… may you mean the globallib_dir option? And yes, it also doesn’t seems to get read from the platformio.ini… but IS read from the environment variable… have a look at where warning related to the Button library says the file is located… I only had to install it once via the global library option (with the environment variable pointing to that alternate global library path also)… and all the ci builds keep pulling it from there, instead of downloading it each time.

[pfeerick@asus-h55d elapsedMillis]$ PLATFORMIO_GLOBALLIB_DIR="/tmp/pio-ci-libs" pio ci -c ../ci-boards --lib "." examples/blinkingLeds/blinkingLeds.ino --build-dir /tmp/pio-ci
The next files/directories have been created in /tmp/pio-ci
include - Put project header files here
lib - Put here project specific (private) libraries
src - Put project source files here
platformio.ini - Project Configuration File

Project has been successfully updated! Useful commands:
`pio run` - process/build project from the current directory
`pio run --target upload` or `pio run -t upload` - upload firmware to a target
`pio run --target clean` - clean project (remove compiled files)
`pio run --help` - additional information
Processing micro (platform: atmelavr; framework: arduino; board: micro)
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Atmel AVR 1.15.0 > Arduino Micro
HARDWARE: ATMEGA32U4 16MHz, 2.50KB RAM, 28KB Flash
PACKAGES: toolchain-atmelavr 1.50400.190710 (5.4.0), framework-arduinoavr 4.1.1
Converting blinkingLeds.ino
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 7 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Button> 1.0.0
|-- <elapsedMillis> 1.0.5
Compiling .pio/build/micro/src/blinkingLeds.ino.cpp.o
Compiling .pio/build/micro/libe61/Button_ID919/Button.cpp.o
Archiving .pio/build/micro/lib3de/libelapsedMillis.a
Archiving .pio/build/micro/libFrameworkArduinoVariant.a
Indexing .pio/build/micro/lib3de/libelapsedMillis.a
Indexing .pio/build/micro/libFrameworkArduinoVariant.a
In file included from /tmp/pio-ci-libs/Button_ID919/Button.cpp:7:0:
/tmp/pio-ci-libs/Button_ID919/Button.h: In constructor 'Button::Button(uint8_t)':
/tmp/pio-ci-libs/Button_ID919/Button.h:30:12: warning: 'Button::_ignore_until' will be initialized after [-Wreorder]
   uint32_t _ignore_until;