Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

There is a constant indicating the board being compiled ?

Open odilonafonso opened this issue 10 years ago • 10 comments

Basic Infos

Hardware

Hardware: ESP-12 NodeMCU or Wemos D1 Mini Core Version: 2.3

Description

There is some constant that I can use to identify the board being compiled?

For example, I use a same sketch to compile both a ESP-12e as one WEMOS Mini D1 or even an ESP-01. Today manually I have to do the following: (for example)

#define ESP-01
// #define ESP-12
// #define WEMOS

#if defined ESP-01
#define STATUS_LED 0
#endif

#if defined ESP-12
#define STATUS_LED 14
#endif

#if defined WEMOS
#define STATUS_LED 5
#endif

But it would be interesting to use a constant that already indicate the board being used. Suppose the build process when identifying the chosen board in the Arduino IDE, replicate this choice by setting a constant.

Settings in IDE

Module: ESP-12 NodeMCU or Wemos D1 Mini Flash Size: 4MB/1MB CPU Frequency: 80Mhz Flash Mode: dio Flash Frequency: ?40Mhz? Upload Using: OTA / SERIAL Reset Method: nodemcu

Sketch

Not relevant

odilonafonso avatar Sep 03 '16 16:09 odilonafonso

Yes board types are available as they were for Arduinos.

pieman64 avatar Sep 03 '16 16:09 pieman64

I don't think there is a difference between a 1 and 12 within the IDE even though they have very different pin quantities. We cheat for ESP12's and use NodeMCU so for you it would be something like this:

  #ifdef  ARDUINO_ESP8266_WEMOS_D1MINI  // WeMos mini and D1 R2
    #define STATUS_LED 5
  #elif ARDUINO_ESP8266_ESP01           // Generic ESP's use for 01's
    #define STATUS_LED 0    
  #elif ARDUINO_ESP8266_NODEMCU               // Wio Link and NodeMCU 1.0 (also 0.9), use for ESP12
    #define STATUS_LED 14       
  #endif 

pieman64 avatar Sep 03 '16 16:09 pieman64

Hi @pieman64. Grateful for your help. Please, where did you find this information? These constants? Who set these constants?

odilonafonso avatar Sep 03 '16 17:09 odilonafonso

@odilonafonso for me they are contained in:

C:\Users\maja\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\boards.txt

pieman64 avatar Sep 03 '16 18:09 pieman64

This constants are not defined for me. I will give a look on my boards.txt. Thanks !

odilonafonso avatar Sep 03 '16 21:09 odilonafonso

I have this in my boards.txt:

nodemcuv2.build.board=ESP8266_NODEMCU

but the constant is not defined....

boards.txt

odilonafonso avatar Sep 03 '16 21:09 odilonafonso

@odilonafonso It's defined as ARDUINO_ESP8266_NODEMCU then.

All the different boards follow the same scheme: ARDUINO_{build.board}, not just {build.board}, that's why it becomes ARDUINO_ESP8266_NODEMCU in your case.

WereCatf avatar Sep 04 '16 00:09 WereCatf

Ahhhhhhh !!! Now works !! Thanks @WereCatf . Thanks also to you, @pieman64. I had not understood right.

odilonafonso avatar Sep 04 '16 02:09 odilonafonso

hello. how could I extract or the other parameters for example: name, CpuFrequency, mcu, flash_mode, flash_freq?

enlinea777 avatar Aug 17 '18 16:08 enlinea777

any news? for last question: I need info for FALSH memory...

JJiri avatar Sep 16 '18 16:09 JJiri