You will, of course, have to write one for each board that you expect your end-user could have, and you will possibly need to update this list as new models appear. The latter is much tidier, even if you only need _BOARD_TYPE once, as it removes the cumbersome #ifdef chunk from your functions. If you need to refer to the board type more than once in the sketch, use the following format: //.BEFORE setup(), or otherwise in the global namespace. A simple example: //.within your code, perhaps during setup(). It is simply a matter of adding some conditional statements to send the PC the correct information. 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_ Select the target board from the Tools > Board menu and any other custom Tools menus (e.g. Instructions for burning the bootloader: Connect an ISP programmer to the ICSP header on your Arduino board. #elif defined(_AVR_Atmega32U4_) // Yun 16Mhz, Micro, Leonardo, Esplora You are now ready to burn the bootloader using your Arduino as ISP programmer. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |