Just like the "Add library..." menu item inserts the "#include " into top of sketch.
It would be awesome if, in the tools menu there was a menu selection to either add the current Micro controller config as comments, or have it add compiler directives (maybe new command, "#directive<>" or "#config<>", consisting of, "Board..., Port..." and all parameters below "Get Board Info") to top of sketch.
Then (if you add the functionalities to IDE), the IDE could auto configure before uploading based on the directives (if they exist-- That would make it backward compatible to Example, generic or old sketches ).
I have a variety of controllers to "play with".
It would be great to set (or save) the configuration in the sketch.
Where it can also remind me which controller I was using for that sketch.
At least add menu item to auto insert those params as comments. Especially ESP32 and 8266's that have a ton of params to copy manually... have the IDE do it for me...
I have ESP devices with builtin displays. So I grab an example, and tweak it for the device I'm using. So inserting the configuration as comments would help immensely. For me... thx
Great idea. Especially with all the configuration available on ESP32. I generally add it to a list of comments at the top of the file, but a preprocessor directive would make it much easier.
Hi @dsoethe1. Are you using Arduino IDE 2.x? I ask because Arduino IDE 2.x does record the board and port selection that was used with each individual sketch. It automatically selects that same board and port each time you open the sketch.
Some things to note:
Arduino IDE opens example sketches in a new sketch. So if you want to associate a board and port with the sketch for use later, you should use File > Save As... to save the example sketch, then open that saved sketch rather than using the File > Examples menu.
The board and port selection information is keyed on the sketch path. So if you move a sketch to a different location on your hard drive, Arduino IDE won't select the board and port the first time you open it afterwards.
Even though there is no need for such a feature when we consider a single copy of a sketch, it might be useful in cases where a sketch is shared. The Arduino IDE developers are tracking this feature request here:
This approach would be fragile because parsing a sketch for machine readable data is difficult and the user could easily damage the data format through a manual edit.
I think that unnecessarily using code for this purpose is a very bad idea. We should avoid any deviations between the Arduino programming language and C++ unless there is no better solution.
The proper way to do this is by putting the data in a dedicated file, separate from the sketch code file. In fact, Arduino has already established such a file:
There is if I have multiple sketches. One running on a Nano, another on an ESP8266, one on an RPi Pico and another on a Blackpill.
If all I have to go by is a .ino file, then I have to remember or document somewhere what processor it's for, and for an ESP32, how the memory and USB are configured.
Right now, I put that in a comment header in the sketch if I remember. It would be much cleaner if we could have a #directive that did it for us.
Probably too late for me though. I stopped with the Arduino IDE after 1.8 and now use platformio for most new projects.
There is no problem. Arduino IDE 2.x stores the information on a per-sketch basis. So when you open the Nano sketch, Nano is selected in the Tools > Board menu and when you open the ESP8266 sketch, the ESP8266 board and its custom board options are selected, and so on...
I was tinkering with Platform.io too. but i tried out again a few days ago and the Arduino extention isn't supported anymore. (probably because Arduino IDE 2.x basically mimics parts of platform now...) even though platform.io is more configurable.
I'm not sure what this means. I had a system crash and had to reinstall VSCode and platformio yesterday afternoon and everything's up to date. I think you may be confusing platformio and the VSCode Arduino extension.
I see. I was referring to the "auto configure" part of your request (which is also the feature requested at the link I shared in my previous comment):
As for a feature of just copying a summary of the menu settings to the clipboard to document the settings only for human consumption, Arduino will not allocate resources to adding this feature (because we would instead use those resources to implement the more impactful auto-configure feature), but it would be possible for you (or any other community member) to create an extension that adds the capability to Arduino IDE.
Arduino IDE 2.x extensions definitely have access to the board, custom board options, and port selection data via this extension (which is built-in to the Arduino IDE 2.x installation):
Unfortunately the Arduino IDE developers never got around to producing formal documentation about using that data, but you can see some examples of existing Arduino IDE 2.x extensions that use it here:
It also might be possible that extensions have access to data about menu settings directly from Arduino IDE. I don't have experience writing VS Code extensions so I can't say exactly what capabilities are available (though if you look at what has been done in the thousands of existing VS Code extensions, it is quite a lot!) but there is a lot of information available about writing extensions. If you are researching the subject, just keep in mind that the general VS Code extension framework is not specific to Arduino IDE, so don't "poison" your search by including "arduino" as a keyword. It is only the "vscode-arduino-api" extension's API that is Arduino IDE-specific.