Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By morcillo
#62990 Hello,

I'm using a nodemcu and an arduino mega in order to exchange data and then send the data to a server.
After a little bit of tweaking I was able to send data from nodemcu to mega, and I can see the data arriving without any problems.

The thing is that when I try to send data from mega to nodemcu, the data doesn't arrive. And I mean that it physically doesn't get to the board.

I connect the output of the mega's uart3 to 3 10k resistors and reduce the siganl from 5V to 3V3 approximately. When I don't connect the nodemcu I can see the data in an oscilloscope. My byte is there @3V3. But as soon as I connect the pin to the nodemcu It goes to 0V and there is no more signal. It was connected in Rx pin of nodemcu.

Naturally I thought that maybe the CH30 usb-serial converter is driving the pin to 0V or maybe some software on my computer is doing it. So I used the Serial.swap function in order to use TX2 and RX2 instead of TX0 and RX0.

Again I can easily get the data from nodemcu, but I can't send data to nodemcu. The same thing happens, it goes to 0V as soon as I connect it to nodemcu. Obviously the TX and RX are both working as they should, or else I wouldn't be able to flash new firmwares nor debug the output via serial port.

I'm thinking that there must be something wrong with my code.

Code: Select allvoid setup() {
    Serial.begin(9600);
    Serial.swap();
}
void loop() {
    if(Serial.available()) {
        uint8_t data = Serial.read();
        Serial.write(data);
    }
}


As you can see it's extremely simple. Wait until data arrives and send it back, but data never arrives.
User avatar
By mrburnette
#63088 Oh, my....

When things go wrong, consider the big picture... like, we all know that the ESP8266 under Arduino will correctly work with serial in and serial out. Why? Too many published projects to dispute a major issue.

Now, when we are doing something odd - like connecting a Mega 2560 5V to an ESP8266 3.3V module, things can go bonkers. Is the module/software at fault? Highly unlikely. We need to think this out and do some bench testing.

The Lolin NodeMCUpinout is here. The default Rx and Tx go to the serial-USB chip. Tx & Rx also appear on the header pins D10 & D9 which are also known as GPIO01 & GPIO03 respectively.

Lets determine where the issue is ... we can do that by crafting a quickie program just to do loopback at the internal level .... that is, from PC keyboard to USB to serial-bridge to uC to software to uC to serial-Bridge to USB and back to the IDE serial monitor. This is very simple:

Code: Select all#define LED 2
char c ;


void setup() {
  Serial.begin(115200) ;
  Serial.println(".... initializing ....") ;
  pinMode(LED, OUTPUT) ;
}

void loop() {
  if(Serial.available() ) {
    c = Serial.read() ;
    Serial.print ( c ) ;
    digitalWrite( LED, ! digitalRead(LED) ) ;
  }
}


Output on the serial monitor with "No line ending" option set...
1384, room 16
tail 8
chksum .... initializing ....
abcdefgHIJKLM


So, we KNOW for certain the NodeMCU is functioning, the PC, its USB, and the ArduinoIDE serial monitor are all OK.

If your testing shows this correct, then the issue is not the NodeMCU or the Arduino core.

The Arduino ESP8266"swap" command is covered in this paragraph. I have never used it, so you are pretty much on your own here. Maybe some googlin' will help out.

Caveat:
Going from 5V to 3.3V really needs to be done with a decent voltage-level converter... not a resistor bridge. While the R1/R2 bridging may work under some circumstances, it is prone to noise and interference from AC, RF, etc. Decent bridges can be had on eBay or AliExpress for pennies. Both Adafruit and Sparkfun sell them with schematics on how to use same.

Ray