EEVblog Electronics Community Forum

Computing => Programming => Topic started by: Jester on April 08, 2021, 01:44:15 pm

Title: Arduino: variant.cpp JSON etc. HELP
Post by: Jester on April 08, 2021, 01:44:15 pm
The problem
As 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/ (https://www.instructables.com/Arduino-IDE-Creating-Custom-Boards/)
I'm at step 8

My questions


Thanks in advance
[/list]
Title: Re: Arduino: variant.cpp JSON etc. HELP
Post by: westfw on April 09, 2021, 04:52:27 am
Quote
Assuming 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 easy enough to put on github or other site.

Quote
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?
The 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 at https://github.com/Optiboot/optiboot/blob/master/optiboot/release.sh which 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))

Quote
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?
I 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.)
Title: Re: Arduino: variant.cpp JSON etc. HELP
Post by: Jester on April 09, 2021, 08:53:32 pm
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|preferences

Thanks for your help.
Title: Re: Arduino: variant.cpp JSON etc. HELP
Post by: westfw on April 10, 2021, 02:58:58 am
Quote
I was able to test locally by adding file://C:/Users/*****/Documents/Arduino/package_myBoard_index.json
I was wondering if that would work!Where did you end up putting the .zip files for the board itself with a local .json ?
Title: Re: Arduino: variant.cpp JSON etc. HELP
Post by: Jester on April 11, 2021, 03:21:54 pm
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”
Title: Re: Arduino: variant.cpp JSON etc. HELP
Post by: westfw on April 11, 2021, 09:26:39 pm
Quote
I’m now wondering if their is a way to specify in your c code to use a particular “Board”
No, there isn't  It's an often-discussed  feature request.

https://forum.arduino.cc/index.php?topic=355940.0 (https://forum.arduino.cc/index.php?topic=355940.0There's)

There's even a 3rd party add-in:  https://github.com/tykefcz/IniIno (https://github.com/tykefcz/IniIno)