2

I am beginner for NodeMcu. I brought a Adraxx ENTDEV019 ESP8266 NodeMcu WiFi Development Board. I am trying to program with arduino Ide. I tried some basic examples. Below is code I am trying for the board. I am using Serial1 port for debug communication. I connected:

  • Tx from board to Rx of Serial Adapter
  • Rx from board to Tx of Serial Adapter

I tried this for different baud rates. I powered NodeMcu with external power bank,but I don't see correct output in Serial Monitor.

Same code works fine if I use Serial port instead of Serial1 and connect with USB cable to Computer.

#define LED D0 
#define DBG_OUTPUT_PORT Serial1

// the setup function runs once when you press reset or power the board
void setup() {
  DBG_OUTPUT_PORT.begin(9600);
  DBG_OUTPUT_PORT.print("\n");
  DBG_OUTPUT_PORT.setDebugOutput(true);
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LED, OUTPUT);  

}

// the loop function runs over and over again forev`er
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED, HIGH);// turn the LED off.(Note that LOW is the voltage level but actually 
  delay(2000);                       // wait for a second
  DBG_OUTPUT_PORT.print("Connected! IP address: \n");

  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW

  digitalWrite(LED, LOW); // turn the LED on.

}

enter image description here enter image description here

What mistake am I doing?

James Z
  • 12,209
  • 10
  • 24
  • 44
Sarfraj
  • 312
  • 1
  • 5
  • 16
  • is your serial adapter a USB-to-UART? – Andy Mar 10 '19 at 07:39
  • yes its USB-to-UART – Sarfraj Mar 10 '19 at 10:01
  • The software is evidently not an issue if it works for teh `Serial` object but not `Serial1` - therefore the question is off topic on SO, and perhaps better asked at https://electronics.stackexchange.com/. Or just read the documentation (such as it is). You are to be connected to RXD0/TXD0 (the same `Serial` UART already exposed via the USB). Serial1 supports TX only on D4 according to the IOCONN block at https://github.com/nodemcu/nodemcu-devkit-v1.0/blob/master/NODEMCU_DEVKIT_V1.0.PDF. – Clifford Mar 10 '19 at 14:59
  • 1
    I'm voting to close this question as off-topic because it is not a software issue https://electronics.stackexchange.com/ – Clifford Mar 10 '19 at 15:02
  • Borderland firmware/hardware is more suitable for https://electronics.stackexchange.com (MCU programming is on-topic there, doesn't need to be pure hw questions). Arduino-specific questions about libs and utilities etc should be asked at https://arduino.stackexchange.com/. – Lundin Mar 12 '19 at 07:58

2 Answers2

2

From (https://arduino-esp8266.readthedocs.io/en/latest/reference.html#serial):

Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). Serial may be remapped to GPIO15 (TX) and GPIO13 (RX) by calling Serial.swap() after Serial.begin. Calling swap again maps UART0 back to GPIO1 and GPIO3.

Serial1 uses UART1, TX pin is GPIO2. UART1 can not be used to receive data because normally it’s RX pin is occupied for flash chip connection.


Pinouts that you connected seem like GPIO1(TX) and GPIO3(RX). GPIO2 is D4 pin.

(pinmap from: https://github.com/nodemcu/nodemcu-devkit-v1.0)

Andy
  • 377
  • 6
  • 10
  • Was looking at https://www.arduino.cc/reference/en/language/functions/communication/serial/ didn't find swap() here. – Sarfraj Mar 15 '19 at 17:38
0

I could use the Serial1 input Port with this code:

#include <SoftwareSerial.h>   //allows e.g.Serial1 to serial-receive
 
SoftwareSerial mySerial(0, 2); // enables RX, TX via d3 and d4 (Serial1-   port)

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600); //(This port seems only to work with 8N1)
} //setup

void loop() {
  if (mySerial.available()) {      // If anything comes in d3
    Serial.write(mySerial.read());   // read it and send it out Serial0 (pin   TX)
    //for TX:
    if (Serial.available()) {      // If anything comes in RX (Serial0)
      mySerial.write(Serial.read());   // read it and send it out on d4     (Serial1)
    }
  }
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31