6

I'm playing around with this udp-example. Both this and the blink-example work perfectly. Now I would like to use the LED to indicate what the ESP is currently doing, as well as reading some data over Serial. My code looks like this:

void setup(){
  Serial.begin(115200);
  Serial.setTimeout(500);
  while(Serial.available()==0){
  }
  String password = Serial.readStringUntil('.');
  Serial.println(password);
  WiFi.begin(ssid.c_str(), password.c_str());
  //pinMode(LED_BUILTIN, OUTPUT);
  while (WiFi.status() != WL_CONNECTED){
    //digitalWrite(LED_BUILTIN, LOW); 
    delay(250);
    //digitalWrite(LED_BUILTIN, HIGH); 
    delay (250);
  }
  Serial.println("connected");
  Udp.begin(localUdpPort);
}

It works fine, but if I uncomment the led-lines the serial communication doesn't seem to work anymore. All the stuff that is printed on the Serial Monitor is now messed up (missing characters, ...). Is there a problem with my code or what else could be possible going wrong here?

EDIT: I recently tried the same code again, but used an additional power supply (3.3V, 500mA) for the chip. However, this didn't resolve the problem.

dda
  • 1,588
  • 1
  • 12
  • 17
user2224350
  • 113
  • 6
  • 2
    Turn the baud rate down to 9600 and see if that helps. Also not sure about the setTimeout call. – Code Gorilla Aug 15 '17 at 12:57
  • 1
    Setting the baud rate to 9600 has no effect when the led stuff is commented out, but if it's not commented I cant see anything on SerialMonitor at all ( setTimeout is also commented out) – user2224350 Aug 15 '17 at 14:58
  • 1
    Do you have a drivers to the LEDs or are they directly attached to the ESP-01? And have you a extra capacitor as power stabilizer over Vcc and GND? – MatsK Aug 18 '17 at 19:49
  • 1
    It is the built in led on the esp I am using. I just connected VCC to VCC of my usb/ftdi- chip (which is plugged in on my notebook). – user2224350 Aug 18 '17 at 19:53
  • 1
    I'm using this chip from AzDelivery FTDI Adapter FT232RL – user2224350 Aug 18 '17 at 19:55
  • 1
    i would suggest you add something to the body of that while loop, just to allow the background activities to continue, even if it's just a short delay or a yield – James Kent Aug 21 '17 at 14:19
  • 1
    Do you mean the first one? Why should this change something? – user2224350 Sep 04 '17 at 21:48
  • Do you get the same results with another module? Did you enter anything through the serial monitor? Can you place a while (1); after the Serial.println(password) to see if that at least is printed? Maybe also place a yield() in the while (Serial.available() == 0) { } loop. – SoreDakeNoKoto Sep 04 '17 at 23:45

1 Answers1

7

I would bet that the built-in LED pin is also the TX pin for the serial interface.

Check here, LED Pin section: http://www.esp8266.com/wiki/doku.php?id=esp8266_gpio_pin_allocations

LED Pin

GPIO1, which is also TX, is wired to the blue LED on many devices. Note that the LED is active low (connected to Vcc and sinks through the chip to ground) so setting a logical value of 0 will light it up. Since GPIO1 is also the TX pin, you won't be able to blink the LED and perform Serial communications at thew same time unless you switch TX/RX pins.

This would be confirmed if the LED blinks when serial communication is active.

If this is the case you would have to add your own LED on a different pin, or switch the RX/TX pins.

Mazaryk
  • 1,149
  • 6
  • 15