Arduino: variant.cpp JSON etc.   HELP - Page 1
Forum section: electronics / general

author: Jester
author_rank: Frequent Contributor
timestamp: April 08, 2021, 01:44:15 pm
content: Hi,Context:I'm an engineer not a programmerI'm okay with C language programming, less so with C++I have developed a few custom boards using a Cortex SAMD21G, so similar to Arduino MKR ZERO with more pins in useWrote some Arduino code for the boards and it works greatTo accomplish above I tweaked the original MKR ZERO variant files to use the extra pins and reassign some pins to other usesThe problemAs I switch from one project to the other I need to manage the various versions of variant.cpp and variant.h.My understanding is that the proper way to this is to create a custom Arduino board using a JSON file, that's where things get fuzzy.I did find this tutorial:https://www.instructables.com/Arduino-IDE-Creating-Custom-Boards/I'm at step 8My questionsAssuming I can figure out how to create a JSON file, is it necessary to post this with a URL? Can I not do this locally on my hard drive at least until I know that it works?It's not clear to me if the JSON file is simply a zipped text file with the 70 or so lines in the example or more than that?Am I better off just managing the various variant files, or is it worth completing the last couple of steps to actually create an Arduino custom board?Thanks in advance

author: westfw
author_rank: Super Contributor
timestamp: April 09, 2021, 04:52:27 am
content: QuoteIt's easy enough to put on github or other site.QuoteThe json file isn't even zipped. Just plain text. JSON is one of those "languages" for encoding a data structure as plain text.The file that the json points to is generally a zipped file containing the appropriate directory structure for the custom board.You might want to look athttps://github.com/Optiboot/optiboot/blob/master/optiboot/release.shwhich is a script I use to prepare the .json file and "release zip" for optiboot (it's been a while since I've used it; optiboot is now better served via one of the board packages that use it (MCUDude or SpenceKonde's))QuoteI dunno. The Arduino board manager is pretty neat, but I think you can still add hardware just by putting files in the (legacy) ~/sketchbook/hardware directory as well. (Possibly in some not-quite-legacy directory structure.)

author: Jester
author_rank: Frequent Contributor
timestamp: April 09, 2021, 08:53:32 pm
content: It's working.BTW: I was able to test locally by adding file://C:/Users/*****/Documents/Arduino/package_myBoard_index.json to Additional Boards Manager URLs: in File|preferencesThanks for your help.

author: westfw
author_rank: Super Contributor
timestamp: April 10, 2021, 02:58:58 am
content: QuoteI was wondering if that would work!Where did you end up putting the .zip files for the board itself with a local .json ?

author: Jester
author_rank: Frequent Contributor
timestamp: April 11, 2021, 03:21:54 pm
content: I think you can put the zip file as well as the JSON file anywhere, because the JSON file tells the IDE where to look for the zip file. The board manager then makes a copy of the required core files from your zip file and places them in a slightly different location than the other installed libraries. I can’t recall the exact folder now, but obviously you need to know if you want to tweak your custom variants as your project evolves.I’m now wondering if their is a way to specify in your c code (sketch < not sure why I dislike that term) to use a particular “Board”, for that code , because whenever I switch to another project I also have to select the appropriate “Board”

author: westfw
author_rank: Super Contributor
timestamp: April 11, 2021, 09:26:39 pm
content: QuoteNo, there isn't It's an often-discussed feature request.https://forum.arduino.cc/index.php?topic=355940.0There's even a 3rd party add-in:https://github.com/tykefcz/IniIno