Go Down

Topic: BOARD preprocessor directives from IDE (Read 7055 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
https://forum.arduino.cc/index.php?action=dlattach;topic=327736.0;attach=128670 New EEPROM library released

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

suessbacke

Hello,
i really agree with first message:
Switching things by source would be very usefull (at least for me :-).
i work with different types of Arduino at a time and its hard to change Board/Serial/Programmer
all times, when it must be  compiled and upload.

So i tried this to as a first step:

 /*source*/
 #define ARDUINO_AVR_NANO
 ..


Then i selected a Mega1280 Board and hope to see somthing like this

-DARDUINO_AVR_NANO

from the precompiler output , but he ignored this an gave me a...

C:\Program Files\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10603 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -IC:\Program Files\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files\Arduino\hardware\arduino\avr\variants\mega -IZ:\Kingston-DataTravelerG3-01\Projekt\Arduino\libraries\PCF8574 -IC:\Program Files\Arduino\hardware\arduino\avr\libraries\Wire -IC:\Program Files\Arduino\libraries\LiquidCrystal\src

so, this does not change anything :(.

Is there a way to do this all on a "IDE-legal"-way ? Or do i have to do it in some way by changing scripts (are there scripts ?) ?
I think about write a wrapper for avr-gcc and place a script there to parse code and switch things - but there will be a small problem with IDE-updates :-/.


i dont know where to start now. internet searching does not help..


--
(sorry about many many errors in writing - keep some of them and use them in your own postings ! I place them in publicdomain  :smiley-small: )

pYro_65

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
Not a board, but the chip used on it. Some boards have the same chip.

The newer IDE defines all the boards like this:
ARDUINO_SAMD_ZERO
ARDUINO_AVR_LEONARDO
ARDUINO_AVR_UNO
ARDUINO_SAM_DUE
ARDUINO_ESP8266_ESP01

There is also defines for boards that use a specific architecture.
ARDUINO_ARCH_SAM
ARDUINO_ARCH_SAMD
ARDUINO_ARCH_AVR
ARDUINO_ARCH_ESP8266
https://forum.arduino.cc/index.php?action=dlattach;topic=327736.0;attach=128670 New EEPROM library released

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy