Go Down

Topic: BOARD preprocessor directives from IDE (Read 4638 times) previous topic - next topic

craiglindley

I don't know whether this is the correct forum to ask about this but I've been searching the Internet and cannot find any reference to preprocessor directives that reflect the type of board connected to the IDE. This functionality would be very handy for myself and others.

So for example when I have an Arduino Uno connected (and selected in the IDE)  it would be great to have conditional code like:

#ifdef BOARD_UNO
... do this
#else
... do this
#endif


So my questions are:

Does this functionality exists currently?
How does one go about requesting this type of functionality be added?

Thanks

Visual Micro

If you switch on Preferences>Verbose and then re-compile, you will see the compile commands that Arduino is using.

Each compile command will contain a number of params, the ones that start -D are preprocessor constants that you can use. The selected board is one of them, the arduino version is another.
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

craiglindley

This is all that I see. Where is the selected board?

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101

pYro_65

#3
Oct 28, 2012, 04:06 pm Last Edit: Oct 28, 2012, 04:08 pm by pYro_65 Reason: 1
Here is something I use, original was from fat16lib's original DigitalPin library

Code: [Select]
// 168 and 328 Arduinos
#if defined(__AVR_ATmega168__) ||defined(__AVR_ATmega168P__) ||defined(__AVR_ATmega328P__)
 #define CHIPSET ATmega_168_168P_328P

// Mega 1280 & 2560
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
 #define CHIPSET ATmega_1280_2560

// Sanguino
#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
 #define CHIPSET ATmega_644_644P_1284P

#elif defined(__AVR_ATmega32U4__)

 // Teensy 2.0
 #ifdef CORE_TEENSY
   #define CHIPSET ATmega_32U4_A

 // Teensy
 #else
   #define CHIPSET ATmega_32U4_B
 #endif

 // Teensy++ 1.0 & 2.0
 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
   #define CHIPSET AT90USB_646_1286
#endif


Just replace the CHIPSET defines with your platform specific stuff.

Here is a link to a thread on detecting the Due.
http://arduino.cc/forum/index.php/topic,128520.0.html

Visual Micro

doh! Oh yeah, sorry I forgot the mcu setting isn't a -D

mcu=atmega328p
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

jgmdavies

I agree with craiglindley, this would be very useful.

Other people have talked about #defines like:

    BOARD_ARDUINO_MEGA
    BOARD_ARDUINO_DUE

Do they exist, or are there any plans to add them?  Can pYro_65's approach be used to uniquely identify a board product?

Jim

Go Up