Recognising the board before compiling/loading


Maybe this query is for Arduino board hardware developers.

If you select the incorrect board say Uno instead of Mega,
at the time of loading, the timeout error will be put out.

presumably this error could be avoided by the compiler/loader
at the very begining, even before it goes to compile/load, by
putting out an error message 'incorrect board selected",
comparing the hardware and the IDE selected board, through an oversight.

any insight to this?


It's not clear exactly what you're requesting.

It's certainly already possible to do this in your code:

#ifndef ARDUINO_AVR_MEGA2560
#error This sketch was written for the Mega 2560. If you are using a Mega 2560 then be sure to select it from the Tools > Board menu. If you don't have a Mega you can't use the sketch.

The ARDUINO_AVR_MEGA2560 macro is defined when that board is selected from the Tools > Board menu.

Or maybe you're suggesting that the Arduino IDE detect which board is connected to the currently selected port and then fail compilation if that does not match the Tools > Board selection. The problem with that is that, depending on the hardware, it may not be possible to detect the board (a Nano or Pro Mini for example) or a clone may have a different VID/PID from the official board yet be compatible with the official board definition.

There is currently a proposal to add automatic board selection when possible based on the VID/PID of the board on the currently selected port:

But it has been decided that should be an opt-in feature due to similar concerns.

thank you. if u understood my query.