Go Down

Topic: #if def() to indentify an Arduino Due (Read 1 time) previous topic - next topic

wadcock2

What's the #define to identity that the code inside the #if def(<var>) is for Due and not another Arduino board?

The Arduino pro mini and micro boards come in 3.3 volt and 5 volt versions.  The scaling factors for (say 2 volts) analog input  to the same digital value are different.  A 3.3 volt input would be 1024 on a 3.3 volt board and maybe 750 on a 5v board.  Are there #define to say if a board is 3.3 volt version or a 5v version.  The Due is 3.3v and has needs the scane scaling factor.

ard_newbie

On the DUE, the ADC is based on a 12-bit Analog-to-Digital Converter, hence scaling is between 0 and 4095, but you can choose a scaling on 10 bits only between 0 and 1023 (see sam3x datasheet chap. 43).


There is an #if defined for sam3x, try this :

Code: [Select]

void setup() {

  Serial.begin(250000);
 
#if defined(__AVR__)
 
  Serial.println(" NOT a SAM3X board");
 
#elif defined(__SAM3X8E__)
 
  Serial.println("SAM3X board");
 
#else

  Serial.println(" Don't konw !")
 
#endif
}

void loop() {}

david_prentice

Yes,   there are occasions when you want to know the target processor or even target board.   The IDE sends different macros to the compiler as part of the build process.   Use #if defined(MACRO) ...

However,   if you want to know what VCC is,   measure it.  e.g. set AVCC as reference and read the internal Bandgap reference.

David.

Go Up