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.stack.imgur.com/oOKwL.png

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.
    – Juraj
    May 2 '20 at 13:06
  • @Juraj Is the Wemos Mini 5V tolerant? Otherwise a voltage divider would be needed between Mega TX and Wemos RX
    – chrisl
    May 2 '20 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?
    – chrisl
    May 2 '20 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
    – Juraj
    May 2 '20 at 18:06
  • I am not getting anything when I try to serially communicate them. May 3 '20 at 8:15
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"));
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.