I am currently working on a project involving Arduino Mega and the NodeMCU board. The goal of this project is to control a small vehicle with a Camera and sensors via a web browser. I firstly programmed a websocket server to interact with a html file served through SPIFFS. The page is accessible by using my NodeMCU's IP Address and data sent from Javascript is successfully read in the Serial Monitor.
The next step I took was to send this Serial info to the Arduino through the RX1/TX1 ports, and there was where the problem started. I want to send this info because it will give the commands to manage the motors and drive the car. However, when I write to Serial from NodeMCU and try to read on Arduino's Serial1, nothing shows up.
Below it's the schematics of the circuit (unnecessary things for this issue such as the L298N driver are ommited for clarity's sake)
Juraj:
why do you have a voltage divider on RX of Mega?
I don't see a ground connection between Mega and NodeMcu
Hey Juraj! The black wire connects Arduino's GND to the protoboard. Then, there are these two voltage dividers for connecting RX_Ard/TX_MCU and vice versa. I used it because the Arduino operates with 5V whereas the NodeMCU only supports 3.3V
The TX pin on the NodeMCU is a 3.3 V output. The RX1 pin on the Mega is an input. Unless you do something wrong in your code, TX pin on the NodeMCU won't be subjected to 5 V. So remove the voltage divider from the TX pin on the NodeMCU.
pert:
The TX pin on the NodeMCU is a 3.3 V output. The RX1 pin on the Mega is an input. Unless you do something wrong in your code, TX pin on the NodeMCU won't be subjected to 5 V. So remove the voltage divider from the TX pin on the NodeMCU.
Hi pert. I did it but I still cannot receive any data. I failed to mention that I am currently powering Arduino Mega via USB and the NodeMCU via another USB. The Motor Shield is powered with a 9V battery when on.
pert:
Try running a simplified sketch on the NodeMCU that only prints to Serial to verify that serial communication is working correctly.
Hi, pert. I believe the issue is not on NodeMCU. I can print stuff I write on the web out on the Serial Monitor. Then, I wired NodeMCU TX to Arduino RX1 and Arduino TX1 to NodeMCU RX and used Serial.write(0xFF) or anything. This won't show on Arduino's Serial. I tried swapping RX/TX to other GPIOs (as in Arduino/doc/reference.rst at master · esp8266/Arduino · GitHub) and rewired everything.
Also tried setting pin 19 (RX1 on Mega) as a input, input_pullup, setting high and low, everything. Do you believe there is an issue with my board?
I now ran a modified version of Arduino's original sketch. I put it to print "Serial1.available()" content, and it seems like it goes from 0 to 63 (2^6 - 1, or am I trying to find a meaning to it?) and stays at 63. I tried flushing after a delay but once it reaches 63, it keeps on it.
victoroliveirab:
I now ran a modified version of Arduino's original sketch. I put it to print "Serial1.available()" content, and it seems like it goes from 0 to 63 (2^6 - 1, or am I trying to find a meaning to it?) and stays at 63. I tried flushing after a delay but once it reaches 63, it keeps on it.
Does it give you any clue? Thank you
the buffer fills up because it is read too slow.
but it is strange that it fills up with zeros even if you now send only 'a'