Building Arduino examples: Best practices?

I’m fairly new to platformio and I’m struggling to find a way to easily build examples that come with Arduino libraries. For example, if I use lib_deps = Romi32U4 in a project, I get the Pololu Romi32U4 library, which comes with several examples, e.g.:

/lib_deps/romi/Romi32U4/examples/Encoders/Encoders.ino

I would like to be able to easily edit and run that example.

From the platform ci reference page (pio ci — PlatformIO latest documentation), I have gotten to the point where I can use quite a bit of copy/paste to the cli and execute,

pio ci --lib /Users/greg/Documents/projects/myromiproject/.pio/libdeps/romi/Romi32U4 -c platformio.ini -O "targets=upload" /Users/greg/Documents/projects/myromiproject/.pio/libdeps/romi/Romi32U4/examples/Encoders/Encoders.cpp

That appears to build the code, but it doesn’t upload it to my device.

So, a couple of questions:

Can someone walk me through how to do this? You cannot oversimplify this for me – the more detail the better.

Is there a way to specify options/targets in an .ini file or similar to shorten the long command line entry? Surely, there is a more efficient way to do this.

By the way, here is my platformio.ini file:

[env:romi]
platform = atmelavr 
board = a-star32u4
framework = arduino

lib_deps =
    Romi32U4

I’ve been frustrated by this a bit too. What I’ve done is create a new platformio project and platformio.ini file for the example, which is cumbersome and time consuming. I suppose it could be automated a bit with a shell script.

I don’t have a clean solution for you, but I want you to know you aren’t alone. :slight_smile:

1 Like