Board Settings in *.ino file

I often change boards in the IDE between UNO and ATtiny85, but when loading an existing file, the board and related settings always reflect what I had loaded previously, rather than the actual board settings for that file.

It would be wonderful if the board settings for a project could be saved in the *.ino file, and loaded automatically when the file is opened.

As things are currently, I'll write a sketch for the ATtiny85, save it then write one for the UNO and save it. When I re-open the ATtiny85 *.ino file, it defaults back to the UNO and I'm constantly forgetting to set the board and oscillator settings back to the ATtiny85 to suit the current project. I plan on buying a Mega or two shortly, which will make it even more of a problem, (minor as it is).

Would this be a hard thing to incorporate into the *.ino file?

Well, it's pretty clear by the degree of support that I'm the only one who thinks this would be a good feature to incorporate into the IDE, so it's probably best to just forget that I posted this suggestion.

I did it again this morning, and tried to 'upload using programmer' to an ATtiny85, wondered why it wouldn't upload, then realised that when I selected ATtiny, the board setting had defaulted back to the ATtiny45 because I'd uploaded to a UNO just beforehand.

I'll learn to live with it. :)

I have similar problems. My workaround at the moment is to add a comment at the start of the .ino.

I use ESP8266, Uno, Etherten, Maple and others, so have started putting things like:

/* * #! Board is generic ESP * DW, 20151031 */

(the '#!' is based on Linux shell scripts using '#! /bin/bash')

I posted to this Suggestions topic and have had no response either.

Dave

davew: I have similar problems. My workaround at the moment is to add a comment at the start of the .ino. I use ESP8266, Uno, Etherten, Maple and others, so have started putting things like: /* * #! Board is generic ESP * DW, 20151031 */ (the '#!' is based on Linux shell scripts using '#! /bin/bash') I posted to this Suggestions topic and have had no response either. Dave

Yeah, I saw your thread Dave. Like with this thread, it's a good way to test the water. Since no one except you responded to this thread, it's confirmation to me that the board information shouldn't be added to the *.ino file, if no one else wants it. I'm happy enough to live with the problem.

Already, with the ATtiny85, I'm getting used to carefully checking that ATtiny85 is selected, along with the 8MHz internal oscillator that I like to use, so it's not tripping me up as much. At the moment, I'm writing two 'sketches' that communicate serially with each other - one for the UNO and one for the ATtiny85, so am swapping between the two very regularly. It would be good if the correct board/chip and settings were automatically loaded when each respective sketch was opened.

I remember this topic from before: https://github.com/arduino/Arduino/issues/3228 And here is another approach, a little different: https://github.com/arduino/Arduino/issues/1482 I suspect coding something like that would be difficult. If it is easy, somebody could take this one step further by actually coding the changes and submitting a pull request in github and that may get incorporated faster than a suggestion.

dmjlambert: I remember this topic from before: https://github.com/arduino/Arduino/issues/3228 And here is another approach, a little different: https://github.com/arduino/Arduino/issues/1482

Right. Thanks for those links. So I'm not so alone after all. :D

I suspect coding something like that would be difficult. If it is easy, somebody could take this one step further by actually coding the changes and submitting a pull request in github and that may get incorporated faster than a suggestion.

It definitely wouldn't be easy. I guess it would mean having an 'invisible' section of the *.ino file format, that couldn't be seen by the user, to hold the board/chip info. It would certainly mean a major change to the file format, but it would still be nice. :)

And I'm not capable of doing it, since it would also mean changes to the IDE to support it.

If we have more than one sketch open, we have them in different instances of the IDE window, so that shouldn't be a drama. Each instance could save it's menu settings to the currently open *.ino file.

Yet another reason I've for the most part abandoned the Arduino IDE and write code in Eclipse with the Arduino plugin where the board selection is part of the project settings.

Even the com port is part of the project settings, so when I have two codes on two UNOs I can load to one, unplug it, and load to the other without having to remember to go change the com port.

Delta_G: Even the com port is part of the project settings, so when I have two codes on two UNOs I can load to one, unplug it, and load to the other without having to remember to go change the com port.

I'd forgotten to mention the port selection aspect of this. It's the other thing I keep forgetting to do, and am reminded when I try to upload. These are only minor annoyances when juggling multiple projects, but it would be nice if the board, port and any other settings were loaded with each project, or configurable default settings for new projects like with the MPLAB IDE for PIC chips.

it would be nice if the board, port and any other settings were loaded with each project

For the record: I disagree, and think that it is an important feature of Arduino that the same sketch can easily be run on different boards with different CPUs/etc. I often want a sketch to run on the board I currently have plugged in, and NOT the last board I compiled it for.

One of my major annoyances with "Atmel Studio" is that a "project" is so tightly bound to a particular cpu and board. (eg Optiboot compiles easily for nearly a dozen different CPUs via its makefile with little end-user knowledge required. But it would take a dozen different AS projects to set up the same ease-of-use for AS users.)

westfw: For the record: I disagree, and think that it is an important feature of Arduino that the same sketch can easily be run on different boards with different CPUs/etc. I often want a sketch to run on the board I currently have plugged in, and NOT the last board I compiled it for.

Yes, but in that case the settings could be changed. The point is that usually, a sketch will be compiled for the same board each time.

Would love this feature too. Seems like a checkbox option on the Boards Manager dialog "Force selected board within project" could easily be added to lock a board to a project. I deal with a number of custom boards and it always a headache to see lots of errors and then realize the board is set wrong. Some projects will never work on any standard board.

You can solve this problem by using a batchfile to open .ino files using the IDE commandline options you can store the preferences.txt in the sketch folder, so ALL settings are per-sketch.

pgScorpio: You can solve this problem by using a batchfile to open .ino files using the IDE commandline options you can store the preferences.txt in the sketch folder, so ALL settings are per-sketch.

Not everyone is familiar with creating batch files and writing the IDE command line options. Nor should it be necessary to mess around that much to open *.ino files. Much better if it was incorporated into the IDE to begin with, don't you think?

Perhaps we should do away with the IDE altogether and just use a text editor to edit and command line options/batch files for everything else, including uploading with avrdude?

The idea of Arduino is to make things easier for beginners, not harder.

Syntax?

The problem with something simple... // BOARD = Arduino Uno ...is that the developer may inadvertently create an action when they really meant to just document.

Would "extending" the Doxygen syntax be a good idea? Does anyone use Doxygen to document their projects?

If the ino includes any settings, should those settings track the actual IDE settings? If I change the board is the sketch automatically updated?

Should the syntax include a tracking option?

[quote author=Coding Badly link=msg=2837341 date=1468291413] Syntax?

The problem with something simple... // BOARD = Arduino Uno ...is that the developer may inadvertently create an action when they really meant to just document.[/quote] True. I was sort of thinking of hidden directives in the *.ino file, or perhaps even board settings on a per sketch basis stored in or related to the recent sketches list. (I hadn't thought it out too in-depth.)

My Arduino simulator uses comments though, for simulator directives, and it works pretty well.

Would "extending" the Doxygen syntax be a good idea? Does anyone use Doxygen to document their projects?

I don't think that many people use Doxygen, especially not newcomers to Arduino.

If the ino includes any settings, should those settings track the actual IDE settings? If I change the board is the sketch automatically updated?

Yes, definitely. Although it was the title of this thread, it wouldn't necessarily need to be stored in the *.ino file, it just struck me that would be the most convenient.

Should the syntax include a tracking option?

Maybe, although that's not absolutely necessary, and might over-complicate things.

As you can tell, I didn't put a real lot of thought into this, but just felt it would be a nice feature, regardless of exactly how it was implemented. :)

OldSteve: Well, it's pretty clear by the degree of support that I'm the only one who thinks this would be a good feature to incorporate into the IDE, so it's probably best to just forget that I posted this suggestion.

No, you're not and no, it's not... I'm having the same question since I also have the very same issue. Trust me, we're not the only ones.

To me, it would be normal and logically if the board could be saved with the .ino file of a project since having different boards laying on your table is really not an exception.

I have different Arduino's, ESP8266 and ATTiny85 boards with which I'm working and each and every time I'm hitting the same stone (must be stupidity, I guess): forgot to change the board and bang... building is OK but uploading is, of course, not...

Hope this will change in the future.

Best,

Geert

Instead of using comments, I think using #pragma might be a better idea. The #pragma's would be picked up by the arduino-build tool and removed from the generated C++ sources. It is also technically backwards compatible since GCC will just ignore the unrecognized #pragmas.

Ideas I have:

#pragma arduino board "Arduino/Genuino Uno" // This selects the board in the sketch.
#pragma arduino board "Generic ESP8266" // You do meed to match the board title or identifier exactly though.
#pragma arduino upload programmer // Force uploading with programmer
#pragma arduino upload default // Default upload method.
#pragma arduino define SOME_VARIABLE // Passes -DSOME_VARIABLE to all calls of GCC
#pragma arduino import TFT // Pulls in a library without including its header file. There might be C++ header file collisions in some corner cases, and this alternative syntax can avoid that.
#pragma arduino config board.upload.arguments "-F" // This can even inject board.txt contents.

anyone have any luck with this ?

The #pragma idea is an excellent idea technix.

I try to use Atom PlatformIO when possible but I still use Arduino a lot. In PlatformIO all the settings are in an ini file, it's wonderful when you are working on multi-device setups. I would love to see this in the Arduino IDE as well!

I grepped the interweb for this topic and landed here.

Yes please. #pragma or something to set the board type!

I wonder where the "current settings" are stored; a tacky workaround could be to always launch Arduino.app from a command line script that read the .ino and munged the app prefs file.