Is it possible for an Arduino program to discern what type of Arduino it's running on? The easiest way to implement this would be with a constant set at compile time and available to the program. Does this exist?
Thanks.
Is it possible for an Arduino program to discern what type of Arduino it's running on? The easiest way to implement this would be with a constant set at compile time and available to the program. Does this exist?
Thanks.
Oops, should have searched harder. Here is the answer to my question:
Here's a snippet of code that sets up a 'ArduinoType' with a value depending on whether it's running on a Leonardo or Mega2560.
const byte Leonardo = 1;
const byte Mega = 2;
#ifdef __AVR_ATmega1280__
const byte ArduinoType = Leonardo;
#elif __AVR_ATmega2560__
const byte ArduinoType = Mega;
#endif
EDIT: Wrong, fixed below
paulrd:
Here's a snippet of code that sets up a 'ArduinoType' with a value depending on whether it's running on a Leonardo or Mega2560.const byte Leonardo = 1;
const byte Mega = 2;
#ifdef AVR_ATmega1280
const byte ArduinoType = Leonardo;
#elif AVR_ATmega2560
const byte ArduinoType = Mega;
#endif
But a Leonardo doesn't use a ATmega1280 chip?
Can a device read it's own signature bytes? That would be convenient.
Sorry you're right, retrolefty. It should read:
const byte Leonardo = 1;
const byte Mega = 2;
#ifdef __AVR_ATmega32U4__
const byte ArduinoType = Leonardo;
#elif __AVR_ATmega2560__
const byte ArduinoType = Mega;
#endif
And obviously the Mega will have to be a Mega2560. But you get the idea.
paulrd:
Sorry you're right, retrolefty. It should read:const byte Leonardo = 1;
const byte Mega = 2;
#ifdef AVR_ATmega32U4
const byte ArduinoType = Leonardo;
#elif AVR_ATmega2560
const byte ArduinoType = Mega;
#endif
And obviously the Mega will have to be a Mega2560. But you get the idea.
Unless of course the mega board is the original mega 1280 board as I own. ![]()