arduino-ide
arduino-ide copied to clipboard
Allow configuring board for IDE to select by default when sketch is opened
Enable the use of some meta-comment in the code so that the appropriate board is automatically selected for that code.
Additional context
Additional requests
- https://github.com/arduino/arduino-ide/issues/2438#issuecomment-2120033445
- https://github.com/arduino/arduino-ide/issues/2438#issuecomment-2120033459
- https://github.com/arduino/arduino-ide/issues/2438#issuecomment-2120033464
- https://github.com/arduino/arduino-ide/issues/2438#issuecomment-2120033760
- https://github.com/arduino/arduino-ide/issues/2438#issuecomment-2120033766
- https://github.com/arduino/arduino-ide/issues/2438#issuecomment-2282917817
- https://github.com/arduino/arduino-ide/issues/81
- https://github.com/arduino/arduino-ide/issues/1892
- https://github.com/arduino/arduino-ide/issues/1892#issuecomment-1457192512
- https://github.com/arduino/Arduino/issues/3228
- https://github.com/arduino/Arduino/issues/3459
- https://github.com/arduino/Arduino/issues/4950
- https://github.com/arduino/Arduino/issues/5121
- https://github.com/arduino/Arduino/issues/5232
- https://github.com/arduino/Arduino/issues/5308
- https://github.com/arduino/Arduino/issues/6294
- https://github.com/arduino/Arduino/issues/6490
- https://github.com/arduino/Arduino/issues/7324
- https://github.com/arduino/Arduino/issues/7327
- https://github.com/arduino/Arduino/issues/7337
- https://github.com/arduino/Arduino/issues/7339
- https://github.com/arduino/Arduino/issues/7746
- https://github.com/arduino/Arduino/issues/10175
- https://github.com/arduino/Arduino/issues/10462
- https://github.com/arduino/Arduino/issues/11304
- https://github.com/arduino/arduino-ide/issues/81
- https://github.com/arduino/Arduino/issues/11753
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/1
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/3
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/7
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/11
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/16
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/19
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/20
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/21
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/22
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/24
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/28
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/30
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/31
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/33
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/35
- https://forum.arduino.cc/t/board-settings-in-ino-file/343215/43
- https://forum.arduino.cc/t/setting-partition-for-a-project/699061
- https://forum.arduino.cc/t/store-board-info-in-ino-file-and-automatically-load/466878
- https://forum.arduino.cc/t/running-preload-script/506108
- https://forum.arduino.cc/t/save-board-selection-with-sketch/523805
- https://forum.arduino.cc/t/ide-parameters/557892
- https://forum.arduino.cc/t/associating-the-project-with-the-processor-important/670725
- https://forum.arduino.cc/t/feature-request-board-selection/941360
- https://forum.arduino.cc/t/defining-board-type-in-sketch/1203965/1
- https://forum.arduino.cc/t/defining-board-type-in-sketch/1203965/17
- https://forum.arduino.cc/t/saving-micro-controller-config-to-sketch/1300406
- https://forum.arduino.cc/t/can-i-just-swap-preferences-txt-to-switch-board-projects/1343878
Related
- https://github.com/arduino/arduino-cli/issues/2554
- https://github.com/arduino/arduino-ide/issues/2573
Wontfix, but Arduino Create will provide a similar feature
Um, what if we wish to use offline IDE and get this feature?
I'm sorry but you'll have to code it on your own or gather traction together with some other hacker so to raise the priority of this feature
Expanded on this idea in https://github.com/arduino/Arduino/issues/5308 I think it has greater use with esp 8266
It is pretty much a no-brainer and a must-have that the board type is included in the INO file and I am adding my name to this to gain traction. :-)
@ffissore can we reopen this? it seems like arduino create is an entirely different product, and one shouldn't have to switch paradigms to get such a rudimentary feature. Two years later and people still want it in the IDE.
Sorry you've missed the new @hachi but I no longer work for Arduino https://groups.google.com/a/arduino.cc/forum/#!msg/developers/YJLX6AZHem4/kpsLef7XBAAJ
If you need any one to give it a try creating this function, count me in! I'll see if I can create something. If you can give a few examples about how you'd like the syntax to be and where ether you'd like a preferences.txt file or add it to a header in the main .ino file, might give it a try.
@timkoers A few thoughts:
-
If there is a preferences file, then it doesn't "travel" with the INO file. Better to use, as originally suggested, "meta-comments" in the INO file. Yes, one can have multiple files in a folder, includes, data, etc... but many users find a single, simple, INO file posted on the web and copy it in. Yes, Arduino code is very portable, but it's best for the IDE to at least try to select the right one for the sketch when the author bothered to specify it. Keep in mind, the vast majority of INO files will not specify the chip. This is primary for those poor souls who are maintaining a large set of programs over a range of devices and are tired of switching. And also to help out new users who don't understand that a sketch might be for a specific device when the author is kind enough to hint that in the INO file.
-
In any case, the IDE should never assume an action. Upon opening the file, and parsing meta-comments, it should offer to make those changes for the user. The user can accept or reject the offer. If the user rejects the offer, no changes are made. The user may just be browsing the code.
-
Keeping a simple format in the INO file means it also works as documentation for the human. E.g.
// Tools / Board / Arduino Nanocan be read by the IDE and also by a human. -
As one menu change may affect the availability of others, they should be processed in order. e.g.
// Tools / Board / Node MCU 1.0 (ESP-12E Module)// Tools / Flash Size / 4M (1M SPIFFS) -
As humans hate to type, it might be good to have a menu option that records the current menu settings into the top of the .INO or updates the existing settings.
Things I'm less sure about:
-
When to trigger the parsing? File / open only? File / New, Edit / Paste? Upon any change to the file, but only if the current menu settings don't match the parsed meta-comments? I would lean towards the latter, but that does mean that will be parsed on every build. That isn't too much of a burden is it?
-
Which items should be included / excluded? Obviously, the File, Edit, Sketch, and Help menus should be excluded. Tools / Port and / Upload speed should probably be excluded. Perhaps just start with everything on the Tools menus and tune in later releases?
-
What to do if a board isn't available. Actually, that's pretty obvious, just error out. But the point is you have to look for that and interact with the user about it.
Sure! I'll work in my own branch for now and place a pull request once the feature is finished
@timkoers Just mentioning, compatibility with doxygen would be really nice (so that the generated documentation actually also mentions the sketchs' intended boards and etc.), it would be a good idea to even contact the doxygen developer if you aren't that familiar with doxygen yourself.
Sure! What I could do is use the doxygen syntax formatting so that doxygen is able to generate the data out of the box
Can someone reopen this issue and add the label in progress to this issue?
Just a little update, I managed to get it working! The syntax is as following:
/** Arduino IDE Board Tool details
* Board: Node32s
* Flash Frequency: 80MHz
* Upload Speed: 921600
*/
Love it!
Is it looking for the exact text "Arduino IDE Board Tool details"? If so, may I suggest something simpler and less likely to be incorrectly entered? E.g. "Settings" or "Tools Menu" or even "Arduino Tools Menu Settings". I'm trying to come up with things that are unlikely to be misspelled or typoed. E.g. You can look up and see the word "Arduino" in the ide so that's a good choice. And it is the "Tools Menu" so that's easy to remember. Probably "Arduino Tools Menu" is best. It tells you exactly where it's going to have effect.
Sure! It is a single line of code to edit :-) I'll add the header automatically when a new file is created and warn the user if there is a settings mismatch when loading the file.
Should I create a dialog that notifies the user that the settings have been loaded from the header?
Van: JamesNewton [email protected] verzonden: maandag 19 maart 2018 10:51 p.m. Aan: arduino/Arduino Cc: timkoers; Mention Onderwerp: Re: [arduino/Arduino] Autoselection of device (#1481)
Love it!
Is it looking for the exact text "Arduino IDE Board Tool details"? If so, may I suggest something simpler and less likely to be incorrectly entered? E.g. "Settings" or "Tools Menu" or even "Arduino Tools Menu Settings". I'm trying to come up with things that are unlikely to be misspelled or typoed. E.g. You can look up and see the word "Arduino" in the ide so that's a good choice. And it is the "Tools Menu" so that's easy to remember. Probably "Arduino Tools Menu" is best. It tells you exactly where it's going to have effect.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/arduino/arduino-ide/issues/2438, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AEELRavnKUyZJ_LKKjXnUrZ9JC2rNr3Lks5tgCh3gaJpZM4AwkHs.
@timkoers thanks for your effort! I took a look at https://github.com/timkoers/Arduino/tree/board-autoswitch and the method is totally convincing. My only concern is that it's totally tied to Java IDE, so if you compile the same sketch using plain arduino-builder it doesn't apply the in-sketch configuration.
It could also be a feature, so the plain builder only considers the fqbn provided explicitly.
No problems! I’ll try to convert the methods into the arduino-builder (that is the arduino-core right?). I’ll try to fix more issues like these, so it would be usefull if I can manage the issues of the Arduino repo too.
Tim
arduino-builder is here: https://github.com/arduino/arduino-builder
It would be nice if the Arduino Web Editor and the Arduino IDE could use the same system for this. I'd like to see the functionality of the two diverge the least amount possible. That could mean either implementing the system added to the IDE code in the web editor or vice versa. It's not clear what system the Arduino Web Editor uses to store the sketch metadata. Making the changes in arduino-builder rather than the IDE would facilitate that goal since that tool is also used by Arduino Web Editor.
It could also be a feature, so the plain builder only considers the fqbn provided explicitly.
I think if arduino-builder was made to use the sketch properties when no fqbn was specified but override those properties when one is specified then that would provide this feature and more.
Doing it in arduino-builder could lead to code duplication since the IDE must make the correct menu selections according to the sketch properties. The solution I see is for the IDE to run arduino-builder -dump-prefs on the sketch then make the correct menu selections according to arduino-builder's output.
You mean code duplication as in, the Arduino IDE reads and parses the settings and the arduino-builder reads and parses the settings?
I tried to execute the arduino-builder command, but it is not letting me. Is the output of the -dump-prefs command documented somewhere?
So to get confusion out of the way, I need to change the arduino-builder to do the things that I've programmed the IDE to do (read the header and select the right boards), and I need to reprogram the IDE to read the settings from the arduino-builder -dump-prefs command.
How would we handle the opening/reloading/closing of the file, should I execute the arduino-builder everytime?
Many thanks
You mean code duplication as in, the Arduino IDE reads and parses the settings and the arduino-builder reads and parses the settings?
Exactly. It seems silly to have that same code in two places and need to maintain it.
Is the output of the -dump-prefs command documented somewhere?
Well, somewhat: https://github.com/arduino/arduino-builder/blob/master/README.md#usage Or just run arduino-builder with no options for the same output.
So to get confusion out of the way, I need to change the arduino-builder to do the things that I've programmed the IDE to do (read the header and select the right boards), and I need to reprogram the IDE to read the settings from the arduino-builder -dump-prefs command.
How would we handle the opening/reloading/closing of the file, should I execute the arduino-builder everytime?
That was my suggestion. You should be aware that I don't really know what I'm talking about and have no official status in making decisions. So don't misinterpret what I say as coming from a member of the Arduino development team (such as facchinm).
The direction is to remove as much logic as possible from the Java IDE, making it more or less an interface to cli tools. This will make it easier to share the tools between all "unofficial" IDEs (like VSCode/Atom) so the resulting behaviour is the same across all platforms. In this vision, "Add build settings to .INO file" JMenuItem would call an "endpoint" provided by the builder that takes care adding the settings to the actual file. Of course there are problems there too, because the builder is only aware of files already written on disk. I don't have a real solution about this, but we can discuss freely, starting from @timkoers code. The feature appears to be much needed these days so I'll support every effort for fixing it in a sane way.
I took a look at the android-builder source code, I don't understand a single line of the Go language. I have no problems learning another programing language, but I don't think this is the right way (as I'll probably make the code very inefficient) @facchinm do you have more experience coding in Go?
I think it's important to see that this feature is an IDE, and NOT a compiler feature. It is NOT for CLI users, but for those who have little experience, to help them use the IDE and understand which board / settings the INO file is for, and for people who use the IDE all the time and so don't enjoy the nice features of CLI make files, scripting, etc...
Should I create a dialog that notifies the user that the settings have been loaded from the header?
More than that, I would strongly suggest adding a dialog that asks the user if they wish to have the settings loaded. Actually, it should first check to see if the settings need to be loaded (e.g. if the current settings are any different from those in the meta-comment) and then check to see if they can be loaded (e.g. if those options are available) and then ask the user if it should be loaded. Once the user agrees, having a confirmation dialog is probably unnecessary.
I am doing the last part in my code (check if they can be loaded) first, because it makes no sense to ask the user if the IDE should load settings and then notify that the settings are not found xD I haven't implemented the dialog yet, if you'd like to do it, please make an preference option that will allow the more advanced user to disable the IDE to ask if it should load the settings everytime
As I am working with several different Arduino boards (Pro Mini 3.3V and 5V, UNO, MEGA, Nano, and possibly Micro. This is a feature that would be GREATLY useful. It would make sure that when I open the sketch the board selected is aligned with the board being used. Currently I am working on a project that uses 1 Mega, 1 UNO, and several Nanos.
I made the code to integrate this into the IDE, I've created a pull request that they haven't accepted yet. Right now a merge conflict has occurred, due to them not merging my code 🤣 and changing part of the original code, that I haven't edited in my files.
Seems that branch needs a rebase.
I think I will do the following
- create arduino.json
- have the following contents
{
environments:[
"__all__": {
"config": {
"shared1": "valShared1"
}
, "define": { "DEBUG": 0 }
}
"my wet dream 1": {
"config": {
"var1": "val1", "var2": "val2", "var3": "val3", "var4": "val4"
}
, "define": { "BOARD_XXXXXXX": 1 }
},
"but this can also do": {
"config": {
"bar1": "bal1", "bar2": "bal2", "bar3": "bal3"
}
, "define": { "BOARD_YYYYYY": 1 }
}
]
}
- add a dropdown list (on the editor toolbar) with "my wet dream 1" and "but this can also do" and I can choose between the two
- add a editor for arduino.json (doing the same that atmel had done to Visual Studio)
THE DROPDOWN IS A MOCK (the rest is not)

adding a -env "my wet dream 1" to the command line of builder would make it do the right thing ... the gods helping..
PS: I added the 'define' section. These are #define XXXXX to be passed on to the. I use these #define BOARD_XXXXX_AAAAA or #define BOARD_YYYYYY to control a number of features that are not equivalent depending on which board I am running on.
PPS: to be fancy, it needs also needs a 'targets' section with the same contents as the 'define' section, but for special purposes (like targets: { debug Light': { ... }, 'full debug': { ... }, release: {} }__)
It would be real nice if arduino-builder would know how to define them for the command line of the compiler
Again... these are just my personal thoughts