Serial.println not working for ESP8266

Hi,

I have my ESP8266 hooked up using an FTDI232 and am able to upload the following sketch:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, you've entered setup()...");
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Good day, you're in loop()...");
  delay(2000);
}

The Arduino IDE tells me "Done uploading" after the following:

Sketch uses 231,189 bytes (53%) of program storage space. Maximum is 434,160 bytes.
Global variables use 31,724 bytes (38%) of dynamic memory, leaving 50,196 bytes for local variables. Maximum is 81,920 bytes.
Uploading 235344 bytes from to flash at 0x00000000
...

There's a heap more ... characters but this forum is stripping them...

So I'm pretty confident it's doing what it needs to do. I remove GPIO0 from ground, reboot the ESP8266 and have the serial monitor open, but I get nothing displayed.

Any ideas?

1 Like

Is your serial monitor set to the same baud rate as what's defined in the sketch? Mine doesn't default to that rate.

Yes, my serial monitor is on 115200.. I also tried 9600, but to no improvement.

I also tried the ESP8266 blink sketch, but no blinking!

/*
 ESP8266 Blink by Simon Peter
 Blink the blue LED on the ESP-01 module
 This example code is in the public domain
 
 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)
 
 Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
                                    // but actually the LED is on; this is because 
                                    // it is acive low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

I was just thinking about that. If your sketch is truly just what you posted then yes that should work. But if you are doing other things that could interfere with the serial connection then it might not. So if you are in the middle of sending or receiving with the esp then that may conflict with the serial monitor's ability to hear the board. I'm just digging out an esp project that I just finished to compare notes.

On other thing. I didn't see you including the ESP8266WiFi.h lib. Do you not need that?

Update:
Apples to apples. I've got a Hussah Feather ESP8266 here so that may need that library and yours may not. Ironically I have a raw 8266 on my desk I'm just about to start playing with.
I checked my sketch and yes you can use the serial monitor while connected and actively sending.

Did I miss you defining LEDBUILTIN or is that a constant that I'm not used to yet. If not then it's set to 0 and won't address the correct pin.

And here's the dumb question of the day - esp's tend to come ready to accept only Lua and not Arduino. Have you done what's needed so the arduino IDE will work?

And FYI, I seem to remember that esp's can ONLY use 115200 as their baud rate for serial. So you've got that right - I just didn't want you flailing in other baud speeds.

I'm starting to feel like the ESP-01 are buggy. I had inconsistencies with Lua and now with Arduino IDE built projects.

I swapped over to a different ESP-01 module, uploaded the blink sketch and still the same.

I tried rebooting it a few times, and nothing. I then uploaded the same blink sketch and suddenly the on board LED starts blinking..

I added the Serial.begin and Serial.println code.. uploaded and rebooted and the LED blinks, but no serial output. My serial monitor is correctly set to 115200 and normally when you see some serial transmission, my FTDI232 blinks.. but nothing right now.

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

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

Is there anything else needed to properly initialise the ESP8266 or the serial output on these devices?

So is LEDBUILT defined somewhere? Is it a predifined constant I'm not used to? There is no int LEDBUILT=1; statement anywhere i can see, so without that (or it being a constant) it's equal to 0 and the pulse will be sent to the GPIO 0 port, not 1.

Isn't there another LED you blink on there? (pin 13 comes to mind) . That would at least get you out of the communication pin zone.

Presumably the Arduino IDE is mapping it correctly upon build.

Here's the weird thing.. I've had the ESP-01 running for 20 mins and the LED has been failthfully blinking on and off.. suddenly, it stops.

Power cycled the ESP a few times and still the LED doesn't start blinking.

I pull GPIO 0 to GND and re-flash.. now it's blinking again even after several reboots.

I suspect I'm just missing something here but these modules are coming across as very unreliable.

Is it blinking because you set it that way? or is it blinking because it's got a wifi connection? The one I have here blinks all the time it's got a valid connection: no blink code required.
(it's the blue LED right? Next to the antenna?)

I just compiled one with LEDBUILTIN - boy it didn't like that. So at least for me, I don't have that as a predefined constant.

Also we've only had luck with the ESPs using (the very slow to boot) 1.65 IDE

It's LED_BUILTIN and I have zero code in there related to any Wifi connection, plus it's pulsing in accordance with the delays in the code.

Anyway, that aside.. the Serial.println doesn't show anything on the terminal emulator..

Ideas?

Ya sorry - typo on my part - I did use the underscore in my code.

Can you choose one of the other pins to pulse (even if there's no LED on it). That way we can rule out a Serial/pin1 collision issue. (say GPIO pin 12 or 14)

I looked back at any FTDI issues we've had and there have been a few:

Clock on a proc board wasn't as advertised. We could write sketch but couldn't read back any serial data. We did have one that was performing at half speed so setting the baud to 4800 instead of 9600 did the trick.
Usually if its a baud rate issue what you get out of the monitor is junk but you do get something.

Can the FTDI operate as a serial monitor device at the baud rate of the ESP? The esp we're using has USB com port on it so the FDTI wasn't a factor. But a sanguino board we had (precursor to the Mega) would only feed back serial data through the FDTI chip at 57600 and below (mind you that was at least 4 years ago)

Can you try the FDTI on another arduino? Or is this one you use all the time and you know it's solid.

Here's a little goofiness: I just pulled in the blink sketch from the esp libs and its the one you have: it compiles perfectly. But if I start with a blank sketch and write that one out by hand the compile hates that LED_BUILTIN statement. There is no #include in the blink code, so I don't quite know why one sketch likes that declaration and one does not. (1.65 IDE)

The differences I see are:
We're using the ESP library
We're defining pins based on numbers, so pinMode(12,OUTPUT);
We've got a usbcom on the esp board
We've got a 10ms delay after the Serial.begin declaration but we did that because we then immediately start to handshake with a wifi node and didn't want the pokey serial interface slowing that process down.

I'll crack open the raw esp tomorrow and have a go. I feel like with the feather I've got a little more infrastructure than yours so some of the hurdles may be tackled behind the scenes.

Your example does not work because the LED_BUILTIN is on the same pin than TX.

It works with the following modifications:

void setup() {
  Serial.begin(115200);
  Serial.println("LED Example");
  delay(1000);                      // Wait for a second
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

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

/Joe

I'm not so sure.. if you look at the original post, all I wanted to do was have Serial.println work on the ESP-01, but since I wasn't receiving any output I put the LED blink program in. Perhaps that test case has confused the situation.

The objective is to see serial output from the ESP-01 in my terminal emulator. When I used Lua it worked, but after flashing the ESP-01 with the Arduino IDE code below, I see no output:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, you've entered setup()...");
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Good day, you're in loop()...");
  delay(2000);
}

Any suggestions on the lack of serial output? Yes, the baud rates are identical.. I have 115200 above and my terminal emulator is at 115200. I tried setting both to 9600 and that didn't help.

Bit of a wild guess here but you're right that should be working - as long as the IDE and the 8266 are set up right.
While the link below is for the HuzzahFeather it has some links within it for the 8266 alone and the packages needed, as well as the frequency, memory etc setups that you don't normally need for a standard arduino.
Have a look: it may shed some light.

For the sake of completeness:

Board Manager settings for ESP-01:

  • Generic ESP8266 Module
  • QIO
  • 40 MHz
  • Serial
  • 80 MHz
  • 1M (128K SPIFFS)
  • Disabled
  • none (in German: keine)
  • ck
  • 115200

Do not connect RTS with RESET or DTR with GPIO 0, when working with the Arduino Serial Monitor. Unfortunately the Serial Monitor resets the DTR and RTS pins, which holds the ESP8266 in reset mode.

/Joe

OK there were a few differences in that link vs what I had.. notably I set the reset mode to be nodemcu.

It now works! Thanks!

Hello,

I have the same issue, I have a NodeMCU 0.9 with CH340 USB Chip.
On the Node is nothing connect.
I can upload sample, for example the HelloHTTP, the Node ist running and i can connect with http, but
no serial output.

regards
ThomasD

Hello,

I found an answer to add a delay of 1000ms after Serial.begin(115200).
I try it, but it did not work.

I try a delay of 1000ms before the Serial.begin(115200) and it works.

regards
ThomasD

Thanks for this, couldn't understand why serial worked and then didn't after I changed to use the LED_BUILTIN in the server example! And then I looked in the blink example code and it says:

/*
 ESP8266 Blink by Simon Peter
 Blink the blue LED on the ESP-01 module
 This example code is in the public domain
 
 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)
 
 Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

JoeSto:
Your example does not work because the LED_BUILTIN is on the same pin than TX.

/Joe

If all else fails ... read the instructions!

Now to go and see if there's a way to change it so that you can toggle the pin to be able to revert back to using it for serial IO, as well as a handy indicator.

Apart from that I'm thrilled. Finally decided to try programming one of the ESP8266-01 modules that I've had for ages. Hooked it up to my FTDI converter, and an external breadboard type power supply and everything worked first time.

cheers, Andrew