How to know Arduino CPU Model

Sorry for my english...! :slight_smile:

If I write an Arduino sketch to be used on Arduino UNO/2009, or on Arduino Mega (ATMega1280), or on Arduino Mega 2560, is there a method to know which CPU is installed on the device?

Thank you!!!! :slight_smile:

is there a method to know which CPU is installed on the device?

At run time? Not really necessary, since you must define the board type when you are compiling/uploading the sketch. You make the necessary decisions at compile time, not run time.

Yes I know, but I can compile the same sketch to run on many devices with different type of CPU: ATMega168, ATMega328, ATMega1280, ATMega2560.

This sketch (that is the same for all boards) must send a message to the server (via Ethernet Shield) saying which model of CPU is running, so the server can define how many ports can use (depending on CPU Model), how many "configuration values" can handle (depending on the EEPROM Size), etc.

There are #define statements valued for each board type. Use something like:

String mess = "Who knows what CPU this is";
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ย  messย  = "This is a Mega";
#else
ย  mess = "This ain't a Mega...";
#endif

Then, at the appropriate time, send the string in mess. It will have been set at compile time, but that happens just before the code is uploaded, so it can't change.

It is what I was searching for.........thank u very much! :slight_smile: