ESP8266 two serial ports with SoftwareSerial library

ESP8266_Softwareserial

In certain cases we need to use more than one Serial port in the case of arduino, I use the arduino mega 2560 which has 4 serial ports including the programming port, in the case of arduino’s as the nano has a single programming port and as a solution Have created the softwareserial library, given the incompatibility of certain functions the softwareserial library for arduino does not work on esp8266.

Softwareserial Library

I have tested with ESP8266 NodeMCU and SoftwareSerial library of the espsoftwareserial repository created or supplied by plerup thanks for your contribution to the community.

Recommendations

In the case that these libraries that create a uart in code must be taken into account that at high speeds it is possible to have bit errors since they use interrupts and the microcontroller you are in many tasks at a time, in my case and the tests that I have I configured the port at Maximo 9600 Bauds, it is a relatively low speed but I consider it to be safe.

Test

To verify the operation of the softwareserial library, I downloaded the library for esp and I have temporarily replaced the serial software version for arduino.

Tutorial ESP8266 12E NodeMCU  & SoftwareSerial

 

Arduino IDE Code

This test creates a bridge between the 2 serial ports.

#include
SoftwareSerial mySerial(13, 15, false, 256);

//Mas informacion http://pdacontrolen.com/
// More info http://pdacontrolen.com/

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Connect! - Conexion ");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Connect! - Conexion SOFTWARESERIAL");
}

void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}

View

ESP8266 SoftwareSerial



Materials very Cheaps!!!


1 Esp8266 12e  NodeMCU

1 Converter  USB -TTL (FTDI)

ConnectionsESP8266 SoftwareSerial

 

References and Downloads

SoftwareSerial for ESP8266






Conclusions

Although this is a basic test, it requires more complete tests regarding the configuration of more serial serial ports.

The idea is to use this library in future integrations in Modbus RTU, Recommended TrialCommand.

 Youtube Channel

PDAControl



Leave a Reply