Platformio.ini for single project with libraries for multiple platforms

Hi everyone,

I have a project that needs to run in different MCUs (different platform and different boards) but all using the same Arduino framework. Right now, the two MCUs that I’m testing with are the Arduino Pro Mini 8Mhz and the Teensy LC. Aside from using the Arduino libraries, I also have custom libraries, some are specific to the TeensyLC and some are specific to Atmel AVR. These libraries deal mostly with interrupts and sleep functions.

How do I organize my libraries and the platformio.ini so that depending on the default_envs I choose, PlatformIO will select the correct libraries?

My platformio.ini:


[platformio]

default_envs = pro8MHzatmega328

;default_envs = teensylc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;                              ENVIRONMENTS PARAMETERS                                 ;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;Libraries and parameters shared accross environements                                 ;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[libraries]

elapsedmillis = elapsedMillis

softwareserial = SoftwareSerial

servo = Servo

[env]

framework = arduino

lib_deps =

  ${libraries.elapsedmillis}

  ${libraries.softwareserial}

  ${libraries.servo}

  ZigbeeProcessorXBee

monitor_filters = time, send_on_enter

monitor_flags = --echo

monitor_speed = 57600

[env:teensylc]

platform = teensy

board = teensylc

lib_extra_dirs =

  ${PROJECT_DIR}\extra\teensy

lib_deps =

  ${env.lib_deps}

  ZP_Teensy

[env:pro8MHzatmega328]

platform = atmelavr

board = pro8MHzatmega328

monitor_port = COM5

upload_port = COM5

upload_flags = -e

lib_extra_dirs =

  ${PROJECT_DIR}\extra\atmel

lib_deps =

  ${env.lib_deps}

  ZP_Atmel

Thanks!

1 Like

There is a nice example:

Manual