Detecting Due, Yun etc.

There are two ways to find an identifier (define) that is always defined to specify the board being used.

  1. In the IDE, turn on verbose output during compilation (File | Preference}, select the board your interested in, and using a basic sketch hit the compile button (not the upload). You can do this even if you don't have the board. You can then look at the avr-g++ command line for text that starts like this -DARDUINO_???? This is the define you can use in you code to conditionally execute code for that particular board.

or option

  1. Open up the boards.txt file for your arduino installation (../arduino-1.5.6-r2/hardware/avr/boards.txt or ../arduino-1.5.6-r2/hardware/sam/boards.txt) and search for the definition of the board you are interested in. For the YUN it looks like this:
##############################################################

yun.name=Arduino Yún
yun.upload.via_ssh=true

yun.vid.0=0x2341
yun.pid.0=0x0041
yun.vid.1=0x2341
yun.pid.1=0x8041
yun.upload.tool=avrdude
yun.upload.protocol=avr109
yun.upload.maximum_size=28672
yun.upload.maximum_data_size=2560
yun.upload.speed=57600
yun.upload.disable_flushing=true
yun.upload.use_1200bps_touch=true
yun.upload.wait_for_upload_port=true

yun.bootloader.tool=avrdude
yun.bootloader.low_fuses=0xff
yun.bootloader.high_fuses=0xd8
yun.bootloader.extended_fuses=0xfb
yun.bootloader.file=caterina/Caterina-Yun.hex
yun.bootloader.unlock_bits=0x3F
yun.bootloader.lock_bits=0x2F

yun.build.mcu=atmega32u4
yun.build.f_cpu=16000000L
yun.build.vid=0x2341
yun.build.pid=0x8041
yun.build.usb_product="Arduino Yun"
yun.build.board=AVR_YUN
yun.build.core=arduino
yun.build.variant=yun
yun.build.extra_flags={build.usb_flags}

In this file you look for the ???.build.board= line and append the value to ARDUINO_

So for the YUN, you would use #if defined(ARDUINO_AVR_YUN) and for the DUE you would use #if defined(ARDUINO_SAM_DUE)