Page 1 of 1

Universal upload using #ifdef

PostPosted: Sun Nov 22, 2020 11:24 pm
by developer27
I am trying to find out if #ifdef can tell the difference between
esp8266 NodeMCU ( 30 pin breadboard version)
Wemos D1 Mini esp8266 (16 pin)

I want to make a way do something like the following,
but it sees both boards as an ESP8266

#ifdef ESP8266
const char * board = "esp8266 on breadboard";
#define DHTPIN D6
#elif WEMOS
const char * board = "D1 mini on window sill";
#define DHTPIN D4

In the above example both boards print out as:
"esp8266 on breadboard"

Is the board def determined by the board or by the Arduino IDE?
Is there a way to print out what the compiler says the board is?
Is there any way to differentiate between these or any other boards?
Is there any code that might do the following?

My goal is to make it auto configure to the specs of the board I am uploading to without manually changing the code each time.

If no other options work, Would I be able to use LED_BUILTIN as a method of determining which board it is during compile?

Re: Universal upload using #ifdef

PostPosted: Mon Nov 23, 2020 1:25 am
by JurajA
for selected board the xy.build.board property is used to set a compile-time variable ARDUINO_{build.board} to allow use of conditional code between #ifdefs. A build.board value is automatically generated if not defined. for example for UNO the variable defined at compile time will be ARDUINO_AVR_UNO.

https://arduino.github.io/arduino-cli/p ... #boardstxt