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

Moderator: igrr

User avatar
By morcillo
#63241 Well mrburnette @ mrburnette ... I don't know how to talk to you directly via message ... sorry.

Sorry it took so long to answer but I never received a notification e-mail.

So, I knew that there couldn't be anyting wrong with the Rx pin since it is able to receive the code via the CH340G chip. But anyway, I ran your code and as expected everything worked perfectly. Somehow this morning, after a lot of tweaking, some crazy tests and some voodoo magic I got it working (it's not a joke about the crazy tests and voodoo magic ... I literally started messing with everything until it started receiving).

After that I noticed that sometimes the message comes, but its logic level isn't enough to trigger UART, imagine that it behaved like noise on top of 3v3...you could clearly see the byte being sent but its level varied between 3v3 and 3v. Also a ~275ms delay occurred after receiving N bytes (I'm assuming 256 bytes).

After reading your message the only thing I hadn't tried was a level converter, so I built my own with 2 NPN transistor and some resistors. Then I connected it from the arduino mega to nodemcu and it started receiving perfectly. This led me to believe that there was probably a problem with my protoboard wires and resistors, that were lowering the power transmitted (30kohm in series + a few ohms for the wires + protoboard + parasyte capacitance, etc ... probably wasn't enough to drive nodemcu's UART ... but I have used this setup before with other microcontrollers and it worked). But still ... the problem that the communication halts for ~275ms after receiving ~256 bytes is still there. This is certainly due to some buffer being overrun and I can probably deal with it by using shorter commands and the flush function.

Thank you so much for your help and the time you took to write your previous message. Thanks to that I was able to solve my problem.

PS: So my problem was due to the fact that I wanted a quick and dirty setup to test some code and the quick and dirty ended up biting me in the ass. Unfortunately it won't be the last time this type of prblem happens to me, but well ... apparently that's something that not even experience will fix for me
User avatar
By morcillo
#63244
mrburnette wrote: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


Found my problem, check my other post. Forgot to reply to you directly. Thank you very much for your help
User avatar
By mrburnette
#63393 Yea! I love it when things work. The resistor voltage divider often works, but when I use that dirty trick, I usually stay at 9600BAUD.

The level converters are the really right way. I bought like 100 from China 2 years ago and now it is just 2nd nature to grab one.

You really should build yourself one of these:
https://www.hackster.io/rayburne/the-qbf-signal-generator-ae7015


Ray