0

Can anyone help me connecting arduino mega to D1 Wemos Mini serially? Please let me know most efficient and easy steps to setup a communication.

Using that following tutorial:

https://engineeringprojectshub.com/serial-communication-between-nodemcu-and-arduino/amp/

Following is the circuit diagram: https://i.sstatic.net/oOKwL.png

asked May 2, 2020 at 12:59
9
  • 1
    Rx to Tx3 and Tx to RX3, gnd and 3.3 V. ready. in Mega in code use Serial3 to communicate with esp8266. Commented May 2, 2020 at 13:06
  • @Juraj Is the Wemos Mini 5V tolerant? Otherwise a voltage divider would be needed between Mega TX and Wemos RX Commented May 2, 2020 at 16:59
  • @AliHassanRaza What exactly is your problem with setting up the connection? Serial (aka UART) has only 2 lines plus ground connection. There are many tutorials on the web. Did they not help you? What exactly couldn't you understand there? Commented May 2, 2020 at 17:01
  • @chrisl, voltage divider would limit the speed and complicate troubleshooting.. the esp8266 can handle 5 V logic pull-up current for a test. in long term setup I recommend a level shifter, not voltage divider Commented May 2, 2020 at 18:06
  • I am not getting anything when I try to serially communicate them. Commented May 3, 2020 at 8:15

1 Answer 1

2

Apart from ensuring you're wiring TX -> RX and connecting all grounds, you can use SerialTransfer.h to automatically packetize and parse your data for inter-Arduino communication without the headace. The library is installable through the Arduino IDE and includes many examples.

Here are the library's features:

This library:

  • can be downloaded via the Arduino IDE's Libraries Manager (search "SerialTransfer.h")
  • works with "software-serial" libraries
  • is non blocking
  • uses packet delimiters
  • uses consistent overhead byte stuffing
  • uses CRC-8 (Polynomial 0x9B with lookup table)
  • allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 254 bytes)
  • can transfer bytes, ints, floats, and even structs!!

Example TX Arduino Sketch:

#include "SerialTransfer.h"
SerialTransfer myTransfer;
void setup()
{
 Serial.begin(115200);
 Serial1.begin(115200);
 myTransfer.begin(Serial1);
}
void loop()
{
 char buff[] = "hi";
 myTransfer.txObj(buff, sizeof(buff));
 myTransfer.sendData(sizeof(buff));
 delay(100);
}

Example RX Arduino Sketch:

#include "SerialTransfer.h"
SerialTransfer myTransfer;
void setup()
{
 Serial.begin(115200);
 Serial1.begin(115200);
 myTransfer.begin(Serial1);
}
void loop()
{
 if(myTransfer.available())
 {
  char buff[40];
  
  myTransfer.rxObj(buff, sizeof(buff));
  
  Serial.println("New Data: ");
  Serial.write(buff, sizeof(buff));
  Serial.println();
 }
 else if(myTransfer.status < 0)
 {
  Serial.print("ERROR: ");
  if(myTransfer.status == -1)
   Serial.println(F("CRC_ERROR"));
  else if(myTransfer.status == -2)
   Serial.println(F("PAYLOAD_ERROR"));
  else if(myTransfer.status == -3)
   Serial.println(F("STOP_BYTE_ERROR"));
 }
}
answered May 9, 2020 at 5:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.