Author Topic: Arduino: variant.cpp JSON etc. HELP  (Read 1773 times)

0 Members and 1 Guest are viewing this topic.

Offline JesterTopic starter

  • Frequent Contributor
  • **
  • Posts: 859
  • Country: ca
Arduino: variant.cpp JSON etc. HELP
« on: April 08, 2021, 01:44:15 pm »
    Hi,

    Context:
    • I'm an engineer not a programmer
    • I'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 use
    • Wrote some Arduino code for the boards and it works great
    • To accomplish above I tweaked the original MKR ZERO variant files to use the extra pins and reassign some pins to other uses

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/
I'm at step 8

My questions

  • 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 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
[/list]
« Last Edit: April 08, 2021, 01:47:05 pm by Jester »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: Arduino: variant.cpp JSON etc. HELP
« Reply #1 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.)
 
The following users thanked this post: Jester

Offline JesterTopic starter

  • Frequent Contributor
  • **
  • Posts: 859
  • Country: ca
Re: Arduino: variant.cpp JSON etc. HELP
« Reply #2 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.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: Arduino: variant.cpp JSON etc. HELP
« Reply #3 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 ?
 

Offline JesterTopic starter

  • Frequent Contributor
  • **
  • Posts: 859
  • Country: ca
Re: Arduino: variant.cpp JSON etc. HELP
« Reply #4 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”
« Last Edit: April 11, 2021, 03:28:18 pm by Jester »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: Arduino: variant.cpp JSON etc. HELP
« Reply #5 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

There's even a 3rd party add-in:  https://github.com/tykefcz/IniIno
 
The following users thanked this post: Jester


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf