How to get or search the Arduino hardware name?

I found the codes like

#if defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000)

or
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_AVR_UNO_WIFI_REV2)
I wonder how to get these hardware names cause I want to write a library myself. I tried google about "Arduino hardware names" or "Arduino hardware codename" but none of them could lead to the answer.
Any ideas?

Maybe you get a bit further with this:

https://forum.arduino.cc/index.php?topic=454617.0

Go to the installation directory for your device. Mine is in ~/.arduino15
Then do: grep -r ARDUINO_SAMD_MKR1000 *
Repeat substituting your other search strings.

boolrules:
Go to the installation directory for your device. Mine is in ~/.arduino15
Then do: grep -r ARDUINO_SAMD_MKR1000 *
Repeat substituting your other search strings.

You might get lucky and find the macros used in some code but you won't find their definitions that way. The reason is that these macros are automatically generated in platform.txt like this:

-DARDUINO_{build.board}

where build.board is defined in boards.txt:

mkr1000.build.board=SAMD_MKR1000

Once you understand how that is done, it's easy to determine the board identifier macro for any board.

Whoops. I meant to cut off "ARDUINO_". Thanks.

pert:
Once you understand how that is done, it's easy to determine the board identifier macro for any board.

Presumably there is a list somewhere from which the identifiers get put into the boards.txt file? Why isn't that list readily available - at least for the official Arduino products.

...R

If you simply want to find the name for a specific board, turn on verbose mode, select the board you want, and do a compile, then look at the compile output. ALL compiler command lines will contain an argument -DARDUINO_board_name_here which creates the #define you can use in your #ifdef directives.

Regards,
Ray L.

RayLivingston:
If you simply want to find the name for a specific board,

I have the impression the OP is looking for a list of all the names so he can write a library around them.

...R

Robin2:
Presumably there is a list somewhere from which the identifiers get put into the boards.txt file? Why isn't that list readily available - at least for the official Arduino products.

...R

There is no list. There is no need for a list simply to put the identifiers into the boards.txt file. That would just result in extra maintenance effort with no benefit. For that purpose, boards.txt is the list.

Providing a list for the sake of documentation does make sense. I'm not sure where the best place for that would be. Previously, I'd put it on the Arduino Playground but I'm not sure I want to make the effort to add content to the Playground since it feels like a dying project due to plans to make it read-only in 1.5 weeks. Well, I'll put it on my "to-do" list and maybe get to it once work slows down for me after Christmas, assuming I still have edit privileges at that time.

pert:
There is no list. There is no need for a list simply to put the identifiers into the boards.txt file. That would just result in extra maintenance effort with no benefit. For that purpose, boards.txt is the list.

I can sort-of see that.

But if it was my "system" I think I would like to have a simple list that everyone could refer to. Using boards.text as the list is a bit like using the bible (rather than a dictionary) for a list of words in the english language :slight_smile:

...R

For the sake of making the boards.txt file, there is just no need to have something to refer to. When a new board definition is created, the build.board property is defined and that's the only time that needs to be done. This isn't something that needs to be repeated.

These macros are not often used because it's rare that code needs to know which board is being compiled for. It's more common that the architecture or microcontroller needs to be identified and there are better macros for that purpose. In the rare case when the Arduino developers need to use them (the SDU and SAMD_BootloaderUpdater libraries are the only place I've ever seen that), it will only take them a minute to look them up in boards.txt.

For Arduino users who are not already familiar with how these macros are produced, that is documented well in the Arduino Hardware Specification:

However, many users don't know about that reference and may not find it easily unless they get lucky with just the right search terms.

pert:
For Arduino users who are not already familiar with how these macros are produced, that is documented well in the Arduino Hardware Specification:
Arduino IDE 1.5 3rd party Hardware specification · arduino/Arduino Wiki · GitHub
However, many users don't know about that reference and may not find it easily unless they get lucky with just the right search terms.

I have saved a copy of that. It looks like it could be very useful. I can't remember how many times I would have liked to have an explanation of the boards.txt file but was not able to find it.

What other gems are there waiting to be discovered?

...R

Yeah, that's a really great document. There are a couple other things that still need to be added to it but it's already extremely useful. There is a lot of good information in the other pages of the arduino/Arduino GitHub wiki. This is the place where the more developer-focused documentation is published (vs. the user-focused documentation on arduino.cc).