Arduino core for ESP32 Wiki content

Get board name in your code

Issue #1507

Sometimes you write your application for different ESP32 boards and have to assign e.g. GPIO’s different depending on the board your app is compiled for and running on.

The easiest way is the use the #define ARDUINO_BOARD which is created by the toolchain from the board name in the boards .json file.

So in your platformio.ini file you might have defined the different boards like

[env: esp32dev]

The boards names are defined in [YOUR_PATH_TO_PLATFORMIO].platformio\platforms\espressif32\boards. Open the .json file for your boards and look for “name”: “Adafruit ESP32 Feather”
For the esp32dev board you find in esp32dev.json the name Espressif ESP32 Dev Module
for the featheresp32 you find in featheresp32.json the name Adafruit ESP32 Feather

So in your code you might use this like:

String thisBoard= ARDUINO_BOARD;
if (thisBoard.compareTo("Espressif ESP32 Dev Module") == 0) {
  Serial.println("Compiled for Espressif ESP32 Dev Module");
  relayPort = 0;
} else if (thisBoard.compareTo("Adafruit ESP32 Feather") == 0) {
  Serial.println("Compiled for Adafruit ESP32 Feather");
  relayPort = 16;
} else {
  Serial.println("Compiled for another board");
  relayPort = 5;