Pages: [1]   Go Down
Author Topic: BOARD preprocessor directives from IDE  (Read 4422 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Full Member
***
Karma: 11
Posts: 168
IDE for Microsoft Visual Studio and Atmel Studio 6.1, optional USB Debugger
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 74
Posts: 2226
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is something I use, original was from fat16lib's original DigitalPin library

Code:
// 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
« Last Edit: October 28, 2012, 10:08:39 am by pYro_65 » Logged


Offline Offline
Full Member
***
Karma: 11
Posts: 168
IDE for Microsoft Visual Studio and Atmel Studio 6.1, optional USB Debugger
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

mcu=atmega328p
Logged

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

Brighton, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: