Is there a way to set the board type and parameters in the sketch so it doesn't have to be changed manually every time?
I've been switching between boards a lot and it's a pain to have to go through a bunch of dropdowns each time. Seems like a few "#define" lines would really simplify things.
I see this topic has been brought up several times 7+ years ago. Wondering if there have been any updates since then. Thanks!
Can you please post a link to the 7 year old topic on this subject
You can test for the board type being compiled for and cause different libraries to be #included and potentially different code to be compiled. However, that still requires the correct target board to be selected in the IDE
The compiler has no way of knowing which board is the target unless the code or the IDE provide such information
The problem is, that not only your sketch needs to be recompiled when you change the board. All core and library files must be recompiled according to the newly selected board. This cannot be solved by a #define in your sketch.
With Eclipse / Sloeber, the board type and parameters are selected when the project is created (they can be changed later). Arduino IDE 1.x doesn't have that feature. Don't know about 2.x.
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.
If you switch to VS Code and platformio, the platformio.ini file holds your project configuration so when you change projects, those selections are already configured.
Yep. i understand that. I'm not completely sure how compiling works, but I envision the compiler reading down to where the board and other settings are indicated (by #define statements or similar), then continuing with those parameters. The same as if those settings had been changed manually. I know other platforms can do this. Seems odd that Arduino can't.
The problem is, that a #define in your sketch is only valid when compiling your sketch file. But the complete program consist of a lot of files that needs to be compiled and at the end linked together. And when compiling these files the compiler knows nothing about the define in your sketch.
So this has to be done by the IDE that starts all these compiler runs.
Where is this recorded?
I open a sketch that I worked on about 3 weeks ago, and the "IDE" did NOT work as advertised, it did not remember the board or the port...
I think this might be due to multiple instances open at the same time. I have not done any in-depth testing on this.
As I software developer by day; and Arduino enthusiast by night; may I make a suggestion:
Why not create a config directory (Similar to Visual Studio or JetBrains IDE's) where the settings are recoded?
I have not browsed through the latest Arduino IDE code, so I cannot comment on how easy this would be for the team to implemente.
I have forked it on GitHub so will try and go through the code to see how this can be added; as I do belief this would be a good "quality of life" enhancement.
Side Note: I did see your post on the CLI and will have a read through the documentation.
(where <username> is your Windows username) If looking for it with your file manager or command line, note that the AppData folder is hidden by default. On Windows "File Explorer", you can make it visible by opening the "View" menu, then checking the box next to "☐ Hidden items".
Linux
/home/<username>/.config/arduino-ide/
(where <username> is your Linux username) The .config folder may be hidden by default in your file manager and terminal.
(where <username> is your macOS username) The Library folder is hidden by default. You can make it visible by pressing the Command+Shift+. keyboard shortcut.
I believe it is in a database file.
Did you move the sketch to a different path on your hard drive since that time? The workspace data is keyed on the sketch path, so if you move the sketch then you break its association to that data.
If it is to be added, it must be done through the established sketch project file rather than creating a new equivalent redundantly for Arduino IDE.
The task is tracked here:
(the original proposal suggested it be implemented via content in the sketch code itself, which is not an acceptable approach, but the issue is used for tracking the feature request in general)