Question / Esp8266 with Wroom-02 and built in Led

Hello, I am ready with programming this board in IDE 2.8.x ... but how to program built in Led correctly . I start with this my sketch test for built in Led diode :

//Wemos-Wroom-02-CP2102-Led-builtin-en-1
void setup() 
{
  // Start of serial communication
  Serial.begin(9600);
  delay(1000);
  // Initialize the LED_BUILTIN pin as an output
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.println(" ");
  Serial.println("Wemos-Wroom-02-CP2102-Led-builtin-en-1");
  Serial.println("Built in Led : 2");
  Serial.println("Test of Wemos Wroom-02 module with USB CP2102 and battery 18650");
  Serial.println("Used board : LOLIN(WEMOS) D1 ESP-WROOM-02");
  Serial.println("Upload speed : 115200");
  Serial.println("Arduino IDE : 2.8.10");
  delay(2000);
}

// the loop function runs over and over again forever
void loop() 
  {
    // Turn the LED on (Note that LOW is the voltage level
    digitalWrite(LED_BUILTIN, LOW);
    
    // Wait for a second
    Serial.println("Led is On");
    delay(1000);
    
    // Turn the LED off by making the voltage HIGH
    digitalWrite(LED_BUILTIN, HIGH);
    
    // Wait for two seconds (to demonstrate the active low LED)
    Serial.println("Led is Off");
    delay(2000);
}

And what do you mean? Will Led built in blink or no?

But as I use #define LED_BUILTIN 16, my IDE will be in problem ...

The code that you posted blinks the built in LED on my ESP8266 board. My LED is on pin 2

If you want to know what pin the built in LED is on your board then print LED_BUILTIN

That may be subject to the setting which is defined by the core.

A simple solution to

is

const int led = 2; // and try a few options here. Keep in mind the LED is most likely active LOW

void setup() 
{
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() 
  {
    digitalWrite(led, LOW);
    Serial.println("Led is On");
    delay(1000);
    digitalWrite(led, HIGH);    
    Serial.println("Led is Off");
    delay(2000);
}

or you could cycle through the options programmatically until you find the correct one

On my Wemos Wroom-02 led did not blink . There is test sketch, where built in Led will blink and IDE will not angry on you :) ... :

//Wemos_Wroom_02_CP2102_Blinking_Led_1
#define testLED 16

void setup() 
{
  // Start of serial communication
  Serial.begin(9600);
  delay(1000);
  // Initialize the testLED pin as an output
  pinMode(testLED, OUTPUT);
  Serial.println(" ");
  Serial.println("Wemos_Wroom_02_CP2102_Blinking_Led_1");
  Serial.println("Test blinking Led : GPIO 16");
  Serial.println("Test of Wemos Wroom-02 module with USB CP2102 and battery 18650");
  Serial.println("Used board : LOLIN(WEMOS) D1 ESP-WROOM-02");
  Serial.println("Upload speed : 115200");
  Serial.println("Arduino IDE : 2.8.10");
  delay(2000);
}

// the loop function runs over and over again forever
void loop() 
  {
    // Turn the LED on (Note that LOW is the voltage level
    digitalWrite(testLED, LOW);
    
    // Wait for a second
    Serial.println("Led is On");
    delay(1000);
    
    // Turn the LED off by making the voltage HIGH
    digitalWrite(testLED, HIGH);
    
    // Wait for two seconds (to demonstrate the active low LED)
    Serial.println("Led is Off");
    delay(2000);
}

First of all it's not the IDE, but the compiler that complains.

2nd, that is almost the same as my sketch, but using a macro rather than a constant variable.

Start with the built-in example.

Also, take a screenshot of the selected board.

That is the point.

Normally LED_BUILTIN would be defined or declared by the core as the pin number of an LED on the board, hence BUILTIN. If there is any doubt as to which pin that refers to then printing the value of LED_BUILTIN will tell you

When using the generic esp8266 module it can simply be defined as an option, and any of the pins can be selected

If a specific board is selected, sometimes the option isn't specified, for the nodeMCU v1.0 ESP 12E module there is the choice of 2 options, being either 2 or 16.

So the core has provided for possibles.

The ESP8266 core is no longer maintained, but pretty much any board can be used.

@pavelou The IDE is one thing, the board package is another. I was getting a bit confused by your statements, probably due to translation. Anyway, the compiler complains if things get re-defined, but that is all though.

#define LED_BUILTIN 16

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Throws this out to the output window

C:\Users\deva_\AppData\Local\Temp\arduino_modified_sketch_631659\sketch_aug08a.ino:1: warning: "LED_BUILTIN" redefined
    1 | #define LED_BUILTIN 16
      | 
<command-line>: note: this is the location of the previous definition
. Variables and constants in RAM (global, static), used 28008 / 80192 bytes (34%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ DATA     1496     initialized variables
╠══ RODATA   920      constants       
╚══ BSS      25592    zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 59143 / 65536 bytes (90%)
║   SEGMENT  BYTES    DESCRIPTION
╠══ ICACHE   32768    reserved space for flash instruction cache
╚══ IRAM     26375    code in IRAM    
. Code in flash (default, ICACHE_FLASH_ATTR), used 231540 / 1048576 bytes (22%)
║   SEGMENT  BYTES    DESCRIPTION
╚══ IROM     231540   code in flash   
Sketch uses 260331 bytes (24%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28008 bytes (34%) of dynamic memory, leaving 53912 bytes for local variables. Maximum is 81920 bytes.

warning: "LED_BUILTIN" redefined It is just a warning, and the last re-definition is what is being used in the code in the end. The sketch compiles and adding it as the first line of the original sketch will work (as well as of course setting it from the IDE if possible)

Esp8266 and Wemos with Wroom-02 shortly sumarised :

First of all it's not the IDE, but the compiler that complains ...

  • Compiler is a part of IDE (include OS etc.)
    . . . . .

When using the generic esp8266 module it can simply be defined as an option, and any of the pins can be selected
If a specific board is selected, sometimes the option isn't specified, for the nodeMCU v1.0 ESP 12E module there is the choice of 2 options, being either 2 or 16.
So the core has provided for possibles.
. . . . . .
warning: "LED_BUILTIN" redefined It is just a warning, and the last re-definition is what is being used in the code in the end. The sketch compiles and adding it as the first line of the original sketch will work (as well as of course setting it from the IDE if possible)
. . . . . . .

Yes, there is the problem with built in LED cleared for me, thank you to all.

Pavel Ou

The compiler is part of the boards package core, it is independent of which IDE you use, in particular when using 3rd party boards. (some of the 'built in' boards packages like AVR boards are IDE specific , though once installed, the newest package is available in the older IDE) Once installed the same boards packages are available (In fact exclusively) in both IDE 1.8.x & 2.x.x

When installing the new IDE versions, and installing boards packages, the latest version of a package will be installed by default, but if you install an older IDE version, (side by side with the newest version) those same packages are available.

With more boards packages automatically being available in the newer IDE and the newer IDE prompting for updates automatically by default, this can be confusing, but the compiler, compiles code for a specific board.