I believe the non-AVR list is much shorter. The list of possible options is given in the linked question, but only for AVR boards. To get the nice name (for the leonardo "Arduino Leonardo") in the define Board.Īn internal *.h file exists which is created by the IDE, and holds in it the type of board that has been selected. The draw back of this is that you will need to change platform.txt files with each release.Īdd -DBOARD=\"$\" Simply modify the platform.txt files you are using as described nelow.
Note this is a windows mod something similar must exist on linux. If you want to know additionaly to the board also the CPU model, search for the file avr_cpunames.h You can even put this code into a new header file and #include it into your project. These boards must be installed separately: #elif defined(ARDUINO_AVR_BT) // Bluetooth #define BOARD "Teensy 3.2" // and Teensy 3.1 (obsolete)
Thanks to the help of Charlie Hanson and jantje I found the universal solution!īecause it is a pity that every Arduino programmer has to go through the same pain to figure out how to get the board name, I will offer my code to the public so everybody can just copy and paste it.
Is there any way to get in my C code exactly the string that the user has selecetd in the menu of the Arduino compiler? So this code gives the same result (BOARD = 0x04 = Micro) for Yun 16MHz, Micro, Leonardo y Esplora. Static const unsigned long FLASH_SIZE = 32000 Static const unsigned long EEPROM_SIZE = 1000 Static const unsigned long SRAM_SIZE = 2500 Static const uint16_t CPU = _AVR_Atmega32U4_ #elif defined(_AVR_Atmega32U4_) // Yun 16Mhz, Micro, Leonardo, Esplora Here a snippet from the code: static const uint8_t BOARD_MICRO= 0x04 Therefore I need the board that has been selected when the sketch has been compiled:īut it does not give correct results (apart from the fact that several boards are missing). On the PC runs my C# application which receives this data and displays it. This means that the user connects the PC via USB cable to the Arduino/Teensy board in which runs my sketch and my sketch tells the PC via Serial which board is connected. I want to display on the PC which board is currently connected. I want to write a sketch that can be compiled on different Arduino boards.