i have an esp8266 and an arduino pro micro . i cant establish serial communication between them i tryed all the code that i found on youtube can any one give me two programes for them i want to send same data from the esp to my arduino
I have programs for ESP8266 (NodeMCU) and UNO for UART Communication. See the sketches which could be useful for you.
ESP Codes:
#include<SoftwareSerial.h>
SoftwareSerial mySUART(4, 5); //D2, D1
void setup()
{
Serial.begin(115200);
mySUART.begin(115200);
}
void loop()
{
if(Serial.available()>0)
{
byte x = Serial.read();
mySUART.write(x);
}
if(mySUART.available()>0)
{
Serial.write((char)mySUART.read());
}
}
UNO Codes:
#include<SoftwareSerial.h>
SoftwareSerial mySUART(2, 3); //SRX = Din-2, STX = Dpin-3
void setup()
{
Serial.begin(115200);
mySUART.begin(115200);
}
void loop()
{
if (Serial.available() > 0)
{
byte x = Serial.read();
mySUART.write(x);
}
if (mySUART.available() > 0)
{
Serial.write((char)mySUART.read());
}
}
Operations:
1. Upload the sketches in ESP and UNO.
2. OPen SM1 and SM2.
3. Enter Arduino in the InputBox of SM1 and click on the Send Button. Check that the message has appeared on SM2.
4. Enter Forum in the InputBox of SM2 and click on the Send Button. Check that the message has appeared on SM1.
The ProMicro is like a small Leonardo so it has a spare HardwareSerial port (Serial1) on pins 0 and 1. There is no need to use SoftwareSerial.
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.
You can send data in a compatible format with code like this (or the equivalent in any other programming language)
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker
...R