-1

I've just received several LoLin NodeMCUs from a 'cheap Chinese ebay vendor'. They're working well except for the fact that I'm getting garbage in the Arduino IDE Serial monitor.

I am able to:

  1. Load and run sketches
  2. Use the NodeMCU as a webserver and connect to it from a computer/smartphone/etc
  3. Everything you else you would expect an ESP8266 to do EXCEPT

I am not able to get readable data to display in the Serial Monitor.

Some Details: -My computer is running Linux Mint so I understand that drivers shouldn't be a problem

-The NodeMCU board has instructions printed on it to 1) Install CH340G driver 2) Use 9600 baud rate 3) Connect to WiFi

-I have not tried issuing an AT command to slow the default baud rate down to 9600 (as suggested in answer to another question on this forum). Since the NodeMCU standard rate is 115200 and it's only talking to my computer and not another Arduino, I didn't think that would be required. {Could that be the answer to my problem?}

-I've tried all the standard baud rates between 9600 and 115200. None produced readable outputs.

-I've connected stabilized external 5 and 3.3 V power sources to the board and added some caps for extra smoothing.

I'm running the simplest sketch I could think of to send data back the Arduino Serial Monitor:

int LEDState = LOW;
int pinNum = D7;  //LED on D7 will flash while loop is running

void setup()
{
  Serial.begin(15200);
  pinMode(pinNum, OUTPUT);
}

void loop()
{
  digitalWrite(pinNum, HIGH);
  Serial.println("T");  // send the Letter T to the serial output
  for (int c = 0; c < 10; c++)
  {
    Serial.println(c); // send the count 0 to 9 to the serial output
    delay (200);
    LEDState = blinkLED(pinNum, LEDState); // blink the LED to demonstrate that the loop is running
  }
}

int blinkLED(int pinNum, int State)
{
  if (State == LOW)
  {
    digitalWrite(pinNum, HIGH);
    State = HIGH;
  }
  else
  {
    digitalWrite(pinNum, LOW);
    State = LOW;
  }
  return State;
}

I've tried all the various line endings (CR/LF, CR, LF, nothing at all). No success with any of them.

1
  • 1
    When you upload a sketch to you NodeMCU board the AT firmware is erased (the sketch you upload becomes the firmware) so AT commands don't apply. You should have the baud rate menu in the bottom right corner of the Serial Monitor set to 115200 since that is the speed you set with Serial.begin(115200).
    – per1234
    Dec 17, 2017 at 3:34

2 Answers 2

1

That's not the simplest sketch to send serial data to Serial Monitor. Instead, try this:

void setup(){
    Serial.begin(9600);
}

void loop(){
    delay(500);
    Serial.println("Hello World");
}

Upload and open Serial Monitor at 9600 baudrate. Your AT firmware is already erased, never expect 'OK' response for 'AT' command. If Serial Monitor displays 'Hello World', then your board is okay. Then, you have to reflash AT firmware if needed.

1

I seem to have found a solution to my own problem. I poached a code snippet from another post on this forum (which I don't seem to be able to find now or I would happily give credit for) and inserted it into my sketch. Works like a charm.

The code snippet resets the baud rate to 9600 within the program itself. I upload the sketch at 115200 baud, but then switch to 9600 baud to talk to the Serial Monitor.

I've been running this code on the NodeMCU for 14 hours now and it's still going strong.

My next steps will be to insert this code into the rest of the Example Sketches that use the Serial Monitor and see if they all work on the NodeMCU V3 now.

#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX

int LEDState = LOW;
int pinNum = D7;  //LED on D7 will flash while loop is running

void setup() {
//   ***  Additional Code that fixed my problem  ****
  Serial.begin(9600);
  ESPserial.begin(115200);
  ESPserial.println("AT+IPR=9600");
  delay(1000);

  // Start the software serial for communication with the ESP8266
  ESPserial.begin(9600);

  Serial.println("Ready");
  ESPserial.println("AT+GMR");

// ***   End of additional code


  pinMode(pinNum,OUTPUT);

}

void loop() {
  digitalWrite(pinNum, HIGH);
  Serial.println("T");  // send the Letter T to the serial output
  for (int c = 0; c<10;c++)
  {
    Serial.println(c); // send the count 0 to 9 to the serial output
    delay (200);
    LEDState = blinkLED(pinNum, LEDState); // blink the LED to demonstrate that the loop is running

  }

}

int blinkLED(int pinNum, int State)
   {
      if (State == LOW)
        {
          digitalWrite(pinNum, HIGH);
          State = HIGH;
        }
        else
        {
          digitalWrite(pinNum,LOW);
          State = LOW;
        }
        return State;
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.