Program ESP8266 with Arduino UNO and Arduino IDE - serial.print does not work

Hello,

I have made the following connections to power and program my ESP-01 using an Arduino UNO R3:
ESP-01 black.jpg
uno-esp01.png

I managed to get the Blink sketch example to work on the ESP-01, but i can't see anything on the Serial Monitor in Arduino IDE 1.8.10. I set the options to 'Both NL & CR' and 115200 baud rate. :confused:

// Blink the built-in LED for ESP-01 black model

#define ESP_LED 1 // GPIO_1

void setup()
{
  Serial.begin(115200); // Start the Serial communication
  pinMode(ESP_LED, OUTPUT);
  digitalWrite(ESP_LED, HIGH); // Off - confirmed for built-in LED
  //digitalWrite(ESP_LED, LOW); // On - confirmed!
  Serial.println("ESP-01 built-in LED set to OFF at start-up");
}

void loop()
{
  digitalWrite(ESP_LED, LOW); // On
  Serial.println("ESP-01 built-in LED set to ON for 0.5 seconds");
  delay(500);
  digitalWrite(ESP_LED, HIGH); // Off
  Serial.println("ESP-01 built-in LED set to OFF for 0.5 seconds");
  delay(500);
}

uno-esp01.png

ESP-01 black.jpg

Does a simple "Hello World" print work on the ESP ?

Have you tried waiting until the Serial link is ready before printing by using

while (!Serial);

after the Serial.begin()

and io 0?
does the led blink?
is ATmega in reset?
if it is esp-01S, don't wire CH-PD. and never wire RST.

UKHeliBob:
Does a simple "Hello World" print work on the ESP ?

Have you tried waiting until the Serial link is ready before printing by using

while (!Serial);

after the Serial.begin()

Still nothing displayed on the Serial Monitor.

Juraj:
and io 0?
does the led blink?
is ATmega in reset?
if it is esp-01S, don't wire CH-PD. and never wire RST.

I changed the GPIO LED pin to 0 and it does not blink. The blink LED is only attached to GPIO pin 1.

On the Arduino UNO R3, i have connected the RST pin to ground. This is something that i read in one tutorial that it is needed to bypass the Arduino UNO so that the program upload is sent to the ESP-01 instead.

The ESP-01 that i'm using is exactly like in the picture from my first post above. The black module is marked "AI-Cloud inside" and is closer to a "classic" (blue) ESP-01.
qPVMi7u.jpg

qPVMi7u.jpg

how is io 0 wired? for flashing/normal mode switching? it must be pulled HIGH over a resistor to not go into flashing mode, but start the sketch. (esp-01S has the pull-up on board, but the classic esp-01 doesn't)
does the led blink?
you don't need to wire the reset pin of the esp-01, the chip has internal pull-up on reset pin.

I tried different baud rates in Serial Monitor, starting from 9600 and at 74880, i got this:

11:47:21.512 -> ESP-01 built-in LED set to OFF for 0.5 seconds
11:47:22.289 -> ESP-01 built-in LED set to ON for 0.5 seconds
11:47:23.064 -> ESP-01 built-in LED set to OFF for 0.5 seconds
11:47:23.840 -> ESP-01 built-in LED set to ON for 0.5 seconds
11:47:24.586 -> ESP-01 built-in LED set to OFF for 0.5 seconds
11:47:25.367 -> ESP-01 built-in LED set to ON for 0.5 seconds
11:47:26.149 -> ESP-01 built-in LED set to OFF for 0.5 seconds
11:47:26.898 -> ESP-01 built-in LED set to ON for 0.5 seconds
11:47:27.676 -> ESP-01 built-in LED set to OFF for 0.5 seconds
11:47:28.450 -> ESP-01 built-in LED set to ON for 0.5 seconds
11:47:29.227 -> ESP-01 built-in LED set to OFF for 0.5 seconds
11:47:30.005 -> ESP-01 built-in LED set to ON for 0.5 seconds
11:47:30.754 -> ESP-01 built-in LED set to OFF for 0.5 seconds
11:47:31.535 -> ESP-01 built-in LED set to ON for 0.5 seconds
11:47:32.281 -> ESP-01 built-in LED set to OFF for 0.5 seconds

So, it works and i reset the ESP-01 by plugging its reset jumper wire to ground, but i have no idea why it does not display at the configured baud rate of 115200 in the sketch.

did you set a 40 MHz crystal in tools menu?

Juraj:
how is io 0 wired? for flashing/normal mode switching? it must be pulled HIGH over a resistor to not go into flashing mode, but start the sketch. (esp-01S has the pull-up on board, but the classic esp-01 doesn't)
does the led blink?
you don't need to wire the reset pin of the esp-01, the chip has internal pull-up on reset pin.

I have a jumper wire connecting GPIO 0 to ground when entering programming mode, and then i disconnect it, reset by connect the ESP-01 reset pin to ground and then run the sketch.

I changed the blinking delay from 0.5 to 1 second. But oddly, the LED on the ESP-01 seems to not respond accordingly, since it only blinks very briefly at a regular time interval with no change in staying on and off for longer times.

Juraj:
did you set a 40 MHz crystal in tools menu?

Yes.

Here are my settings for the ESP-01:

Juraj:
did you set a 40 MHz crystal in tools menu?

DryRun:
Yes.

then that is the problem with the buad rate mismatch and millis timing. esp-01 has a 26 MHz crystal

DryRun:
uno-esp01.png
I managed to get the Blink sketch example to work on the ESP-01,

I'm betting you didn't. I think you need to connect Tx>Rx and Rx<Tx.

Juraj:
then that is the problem with the buad rate mismatch and millis timing. esp-01 has a 26 MHz crystal

That fixed the baud rate display.
115200baud.png

But the ESP-01 built-in blue LED is still blinking at the same rate, even after i increased the delay from 500 to 1000 and then to 2000 ms.

Nick_Pyner:
I'm betting you didn't. I think you need to connect Tx>Rx and Rx<Tx.

I did. The RX and TX connections should not be interchanged in this case since the communication is not between the UNO and the ESP-01 but between the ESP and the computer. The UNO is just to provide a USB to Serial adapter and 3.3 V power for the ESP-01.

115200baud.png

Nick_Pyner:
I’m betting you didn’t. I think you need to connect Tx>Rx and Rx<Tx.

not if you use the USB chip of an Uno as the title says. because UNO pins are labeled for ATmega pins, not for the USB chip pins

OK

built-in LED is on io 2 on esp-01

the output is for 1000 ms

the timing is irregular because it handles the WiFi startup. AP starts automatically. if there was a WiFi network configured before (maybe with AT firmware) it attempts to connect

"But the ESP-01 built-in blue LED is still blinking at the same rate, even after i increased the delay from 500 to 1000 and then to 2000 ms."

Just from a high level, it seems the new program did not load and the old one is still running.

Juraj:
built-in LED is on io 2 on esp-01

the output is for 1000 ms

the timing is irregular because it handles the WiFi startup. AP starts automatically. if there was a WiFi network configured before (maybe with AT firmware) it attempts to connect

I think the built-in LED pin depends on the ESP-01 model. On mine, it’s GPIO_1. I tried with pin 0 and 2, but the built-in LED didn’t work. I have the ESP-01 black model with 1 MB flash. Here is a photo comparison: Variants of the ("new") black ESP01 1MB - Everything ESP8266

I have tried a few of basic ESP8266 examples in Arduino IDE, but i’m not sure which one would allow me to connect to my local WiFi network. From what i read, the ESP8266 should be set as a station. But i have not been able to find a station mode or sketch in the examples to try out the WiFi capabilities of the ESP-01. So, until now, i have only been able to blink the built-in LED and also an LED connected to GPIO_2.

zoomkat:
‚ÄúBut the ESP-01 built-in blue LED is still blinking at the same rate, even after i increased the delay from 500 to 1000 and then to 2000 ms.‚ÄĚ

Just from a high level, it seems the new program did not load and the old one is still running.

I found this info in the BlinkWithoutDelay sketch example for ESP8266 in Arduino IDE and i think it might explain why the built-in LED blinking is not working as it should. I was trying to change the timing of the LED blinking and also output text in the Serial Monitor so i think that maybe this was causing a clash and messing up the LED blinking.

The blue LED on the ESP-01 module is connected to GPIO1
(which is also the TXD pin; so we cannot use Serial.print() at the same time)

In the Arduino IDE ESP8266WiFi examples, i found this sketch called WiFiScan, which i think is a simple way to test the WiFi on my ESP-01:

/*
    This sketch demonstrates how to scan WiFi networks.
    The API is almost the same as with the WiFi Shield library,
    the most obvious difference being the different file you need to include:
*/
#include "ESP8266WiFi.h"

void setup() {
  Serial.begin(115200);

  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  Serial.println("Setup done");
}

void loop() {
  Serial.println("scan start");

  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
      delay(10);
    }
  }
  Serial.println("");

  // Wait a bit before scanning again
  delay(5000);
}

But the built-in LED just keeps blinking and this is the output on the Serial Monitor:

ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1392, room 16 
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld

Exception (3):
epc1=0x40100718 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4006e9c9 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffc30 end: 3fffffc0 offset: 01a0
3ffffdd0:  00000000 feefeffe feefeffe feefeffe  
3ffffde0:  40102668 00080000 feefeffe 3fffff20  
3ffffdf0:  0000049c 0000049c 00000020 40100908  
3ffffe00:  feefeffe 2c9f0300 4000050c 3fffc278  
3ffffe10:  00000000 400042db 000000fd 40100b60  
3ffffe20:  40004b31 00001000 000000fd 4010027c  
3ffffe30:  40105ae8 00000001 02000000 4022df19  
3ffffe40:  40105ca5 4022e003 3ffef164 0000049c  
3ffffe50:  000000fd 3fffff20 3ffef164 4022dfe6  
3ffffe60:  ffffff00 55aa55aa 00000012 00000020  
3ffffe70:  00000020 0000001a 0000001a aa55aa55  
3ffffe80:  000000ff 4022e4e6 3ffef164 3ffef164  
3ffffe90:  000000ff 3ffed524 00000001 00000001  
3ffffea0:  40105ca5 00000001 3ffef174 4022e706  
3ffffeb0:  00000005 3ffef164 000000ff 3fffff20  
3ffffec0:  3fffff40 3ffef19b 00000012 00000020  
3ffffed0:  3ffef224 3fffff81 00000001 4022e7b6  
3ffffee0:  3fffff20 40239cf0 3ffee348 3ffee410  
3ffffef0:  3ffef564 3fffff40 3fff549c 4022e785  
3fffff00:  3ffef164 4022e7ec 00000001 00000000  
3fffff10:  40201874 00000001 3ffef164 40201850  
3fffff20:  3ffe8400 3ffef164 00000020 401008d3  
3fffff30:  00000020 0000001a 0000001a aa55aa55  
3fffff40:  00000000 4022dbcb 00000000 4010028c  
3fffff50:  3ffe84cc 00000001 3ffee398 4022dbe6  
3fffff60:  4022dc16 00000001 00000001 00000001  
3fffff70:  402011e6 3ffee398 feefeffe feefeffe  
3fffff80:  3fffdad0 3ffee348 3ffee398 40201588  
3fffff90:  3fffdad0 3ffee348 3ffee398 40201056  
3fffffa0:  feefeffe 00000000 3ffee3d0 40202958  
3fffffb0:  feefeffe feefeffe 3ffe84e8 40100b95  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1392, room 16 
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld

Exception (3):
epc1=0x40100718 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4006e9c9 depc=0x00000000

>>>stack>>>

And this output repeats endlessly. I have set the Serial Monitor to ‚ÄėBoth NL & CR‚Äô and 115200 baud. I have no idea what the output means and it is nothing like what i would expect based on the sketch.

io 1 is RX so it blinks on printlns

the module crashed. is it some older revision of Uno or a cheap clone? they can't provide enough current on 3.3 V pin for WiFi