Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Serial communication between nodemcu and Arduino

Status
Not open for further replies.

ajit_nayak87

Member level 5
Joined
Oct 30, 2017
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
981
I am trying to serial communicate between arduino and Nodemcu.I have connected my nodemcu & Arduino uno as shown in figure.

NodeMCU should send char in format 01 03 0000 0000 FD. Arduino should receive this string If data is valid price welcome else print hello.

Out1.jpg

Serial_out1.jpg

Arduino code
Code:
int val = 0;
int incoming = 0;
int incoming1 = 0;

void setup()
{
  Serial.begin(115200);  //Begin Serial to talk to the Serial Monitor   

  Serial.println("Serial Monitor Connected"); 
  Serial.parseInt();     //clear any garbage in the buffer.  
}

void loop()
{


  //     From the Rx Arduino
  incoming1 = Serial.available();  
  while(incoming1 != 0)           //While there is something to be read
  {
    val = Serial.parseInt();    //Get new value
    Serial.print("Receiving...  ");    
    Serial.println(val);        //Print new value to the Serial Monitor
    incoming1 = Serial.available();
  }
}

nodemcu code
Code:
int val = 0;
int incoming = 0;
unsigned int i;
byte Send_buf[] = {0x01,0x03,0x00,0x00,0x00,0x0a,0xFD};




void setup()
{
  Serial.begin(115200);

}

void loop()
{
  incoming = Serial.available();
  while (incoming != 0)                 //While there is something to be read
  {
  Serial.write(Send_buf[0]);
   
  }
 
  
  //delay(200);
}
 

Attachments

  • Serial.JPG
    Serial.JPG
    26.7 KB · Views: 186

The serial port monitor of the Arduino IDE is not suitable for displaying binary values, it supports only format coded in ASCII, there are more powerful terminals available for download freeware, such as Realterm for example. Also, the code fragment in the footer of the image above is not present in the code you posted. Does not it seem obvious to you that sending pieces of information is not very effective?
 

Hi,

the wiring picture is of bad quality. Impossible to validate wiring.

Hardware:
* Are you sure both use CMOS/TTL levels with identical signal voltage?
* bot are non inverted = idle high?
* Tx --> Rx?
* Rx --> Tx?
* both interfaces use 8N1?

Klaus
 

Yes i have connected Arduino TX to Nodemcu RX. Arduino Rx to nodemcu tx. Its communicating. I need help in code.
Where i would like to send msg/string/ 01 03 0000 0000 FD from Nodemcu and

arduino check msg is proper or not if msg is proper reply Welcome else reply hello
 

Hi,

Where i would like to send msg/string/ 01 03 0000 0000 FD from Nodemcu and
It seems your code sends
Code:
01 03 00 00 00 0A FD instead of 
01 03 00 00 00 00 00 FD

Klaus
 

i Have tested simple code on both device

If i connect USB to Serial converter and send any data with below code it will be reflected arduino comport. if i connect both device serially it wont connect. Arduino uno only print "started" from Node MCU.

From docklight i m sending welcome for every 5sec . I dont know why its not printing

Nodemcu code
Code:
#include "SoftwareSerial.h"

const byte rxPin = 13;
const byte txPin = 15;

SoftwareSerial mySerial (rxPin, txPin); 

void setup() 
{
  mySerial.begin(115200);
  Serial.begin(115200);
  Serial.print("Started");
}

void loop() 
{
  if(mySerial.available())
  {
    String incomingMessage = mySerial.readString();
    Serial.println(incomingMessage);
  }
}


Arduino code
Code:
#include "SoftwareSerial.h"

const byte rxPin = 2;
const byte txPin = 3;

SoftwareSerial mySerial (rxPin, txPin); 

void setup() 
{
  mySerial.begin(115200);
  Serial.begin(115200);
  Serial.print("Started");
}

void loop() 
{
  if(mySerial.available())
  {
    String incomingMessage = mySerial.readString();
    Serial.println(incomingMessage);
  }
}
 

Have you tried reducing the baud rate a lot? As a rule, I do not trust Softserial much, since it is intrinsically handled by polling, which we are not sure if it gets stuck in some infinite waiting loop that does not make use of the interrupt feature.
 

Yes i have reduce baudrate to 9600. Both device independly work with USB to serial converter used. But when tried to communicate one to one.

With software serial nodemcu won't work.
If I use only serial library then

Only if node mcu send any data arduino receive response if arduino send it won't respond
 

The NodeMCU has hardware UART, actually it has 2 of these peripherals built in, so why are you using Software serial instead ?
 

How can I use 2 uart then I don't know how to use.it. Can give some example code
 

How can I use 2 uart then I don't know how to use.it. Can give some example code

Surely:

Code:
Serial.println("this implements TX0 at GPIO1 and RX0 at GPIO3"); 
Serial1.println("this implements TX1 at GPIO15 and RX1 at GPIO13");

Be aware that UART0 is shared with USB programmer interface, which is the one you see at Arduino IDE serial monitor.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top