4

I am doing some work for both Arduino Mini Pro and for a NodeMCU style ESP8266 board. Within the Arduino IDE I tell it what board I am compiling for and downloading to.

How do I access which board in my scripts?

Some sections are for one or the other exclusively. Right now I'm using a #define at top of the script, but changing this to switch between boards not the best. For example, version control keeps on thinking I'm in a new branch when I'm not.

cc young
  • 165
  • 2
  • 9

1 Answers1

6

There are a number of macros defined to help you with this:

  • __AVR__ for any board with AVR architecture.
  • ARDUINO_AVR_PRO for the Arduino Pro or Pro Mini selection in the Tools > Board menu.
  • ESP8266 for any ESP8266 board.
  • ARDUINO_ESP8266_NODEMCU for the NodeMCU 0.9 (ESP-12 Module) or NodeMCU 1.0 (ESP-12E Module) selections in the Tools > Board menu.

This allows you to do things like this:

#if defined(__AVR__)
// AVR specific code here
#elif defined(ESP8266)
// ESP8266 specific code here
#endif
per1234
  • 4,278
  • 2
  • 24
  • 43