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
-
1Rx to Tx3 and Tx to RX3, gnd and 3.3 V. ready. in Mega in code use Serial3 to communicate with esp8266.Juraj– Juraj ♦2020年05月02日 13:06:09 +00:00Commented 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 RXchrisl– chrisl2020年05月02日 16:59:03 +00:00Commented 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?chrisl– chrisl2020年05月02日 17:01:36 +00:00Commented 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 dividerJuraj– Juraj ♦2020年05月02日 18:06:25 +00:00Commented May 2, 2020 at 18:06
-
I am not getting anything when I try to serially communicate them.Ali Hassan Raza– Ali Hassan Raza2020年05月03日 08:15:23 +00:00Commented May 3, 2020 at 8:15
1 Answer 1
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"));
}
}
Explore related questions
See similar questions with these tags.