I have a serial communication issue between a Arduino Uno and a NodeMCU (ESP8266 12f) that I do not understand.
The setup is the following. Arduino uno powered by USB cable plugged on computer with :
- RESET to ground to bypass anycode on it
- TX and RX (hardware serial) connected to the TX and RX of the NodeMCU
NodeMCU powered by USB cable plugged on computer with :
- EN to 3.3v
- I have a Reset button on the NodeMCU so it's not plugged
- GPIO0 and GPI015 not plugged
Between both, there is a level shifter to account for the voltage difference
The problem is the following. When I connect Arduino IDE on the Arduino serial with baud rate 115200 and hit the reset button on the NodeMCU, I get the usual init garbage followed by "ready", so communication works this way. When I send "AT" through the arduino serial monitor, I get nothing in responses (the arduino serial TX led flashes properly though)
I have tried and tested several things
- I plugged arduino TX to RX, the echo works, so no issue with arduino serial PINs
- I plugged the 3.3v end of the level shifter corresponding to Arduino's TX to arduino's RX : echo works, and the reverse is true, so level shifter works like a charm
- I tested the voltage on both ends of the level shifter, it is absolutly as expected 5V and 3.3v
- I tested the nodeMCU in arduino ide serial monitor, I get the same garbage + "ready" after nodemcu's reset but this time, all AT commands work from nodeMCU serial monitor.
- I connected NodeMCU rx to tx and the echo works fine in serial monitor connected on NodeMCU directly (via USB on NodeMCU) so NodeMCU serial PINs work
- I tested with two NodeMCU to be sure I did not have a weird issue with one NodeMCU
I haven't tried to connect the arduino and nodemcu rx/tx directly cause I don't want to fry the nodemcu. I haven't flashed the NodeMCU, haven't changed the firmware, so on either side (Arduino grounded on reset and NodeMCU as it was out of factory), it does not seem possible that it is a programming issue.
Oh, one last thing, there will probably be someone wondering why I do not get rid of the arduino alltogether. Well, two reasons :
- I have a relay board in 5V and no separate 5V power supply for now.
- I hate being bothered by such a baffling issue and simply walking away.
[Edit] To be sure there wasn't a weird interaction between hardware serial used for comm with NodeMCU and used for Arduino-PC comm, I decided to switch to soft serial for the communication with the NodeMCU connected on pins 8/9 with the following code :
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9,8);
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
}
void loop() {
char myc = mySerial.read();
if (myc != -1) {
Serial.print(myc);
}
char c = Serial.read();
if (c != -1) {
mySerial.print(c);
}
}
And surprisingly, it works.
But why didn't it work with everything wired through the hardware serial ?
I mean, if the data comes from NodeMCU to the computer through arduino, why doesn't it work in reverse from comp to NodeMCU through arduino hardware serial ?