Using existing Arduino framework for custom board

Good morning everyone, and thanks in advance for any help or advice that I could receive.
I am currently in need of setting up two different development environments on my PC, one for a custom board with a SAM3X8E and another one for a custom board with an AtMega2560.
Currently, I am using Visual Studio with the Visual Micro extension, and changing the Arduino IDE path everytime I need to compile a new release for the different boards.
However, I would like to utilize PlatformIO on Visual Studio Code as my main IDE for the AtMega2560 firmwares.
For the AtMega board, I needed to create a new “pins_arduino.h” file for assigning different functions to the microcontroller pins, and also created a few libraries which are specific for my application.
Is there a way to “point” PlatformIO to my current development environment, so that I only need to perform the classic build operations?

Thanks again!

Best Regards


Yes. Both the Atmel-SAM and Atmel AVR platform, to which your SAM3X8E and AtMega2560 belong respectively, have support for a special platformio.ini instruction with which you can re-point the variant folder: board_build.variants_dir. Take e.g. the variants folder of the standard Arduino AVR core, in there are all the subfolders for each board (mega, standard, etc.). Which variant folder it takes is determined in the standard case by the board’s JSON manifest, which has a build.variant value

However, as the documentation tells you, every one of these fields can be overriden in the platformio.ini.

So, let’s say you have a folder my_custom_variants somewhere on your computer (for simplicity sake we say it’s in the project directory), which contains the folder my_custom_mega folder which contains the pins_arduino.h. Then the platformio.ini

platform = atmelavr
board = megaatmega2560
framework = arduino
; set where the folder with all the board variants is
board_build.variants_dir = my_custom_variants 
; change which exact variant to use
board_build.variant = my_custom_mega 

will use that custom folder while still using PlatformIO’s standard Arduino core package (in this case C:\Users\<user>\.platformio\packages\framework-arduino-avr).

This exact method has been discussed in the forum multiple times, see e.g. Programm SAMD21 directly and How use a same chip but with different environment? with the example projects

1 Like

Hi Max,

Thanks for the prompt and very clear reply.
Unfortunately, due to my lack of looking deep enough, I did not find the discussions you cited.
Thanks for responding to me anyways!

Best Regards


Part of it is PlatformIO’s problem for not mentioning board_build.variants_dir in the documentation (Add documentation for board_build.variants_dir option · Issue #462 · platformio/platform-ststm32 · GitHub), I hope this is fixed soon.