Serial data transfer from ESP-01 to UNO

Before startin more complex activities I am checking serial data transfer from ESP-01 and UNO and back. The code obviously doesn't work.

ESP-01 transmitter:

const byte ledpin = 1;
int i;

void setup() 
{
  Serial.begin(9600);
  delay(10);
  pinMode(ledpin, OUTPUT);
  i = 0;
 digitalWrite(ledpin, LOW); 
}

void loop() 
{
  if(Serial.available()) // Check for availablity of data at Serial Port
  {
      Serial.print('A'); // Printing the Serial data
      digitalWrite(ledpin, HIGH); 
      delay (500);
      digitalWrite(ledpin, LOW); 
      delay (500); 
      i = i + 1;
  }
}

UNO receiver:


#include <SoftwareSerial.h>

SoftwareSerial UnoSerial = SoftwareSerial(2,3);

// variables definition
int i; // variable to be used e.g. for indexing the loops
char data;

void setup()  
{
  Serial.begin(9600);
  UnoSerial.begin(9600);

  Serial.println("**** Its a Hardware Serial ****");
  Serial.println(" Designed by Draggon");
  Serial.println();
  i = 0;
}

void  loop()
{ 
  if (UnoSerial.isListening())
  
  { 
    while (i < 5)
    {
      if (UnoSerial.available() > 0)
      {
      
      Serial.println("UnoSerial is listening!");
      char data = UnoSerial.read(); 
      if (data != -1)
      {
        Serial.println(data);

      }
      i = i + 1;
    }


    }
  }
  else 
  {
    Serial.println("UnoSerial is not listening!");
  }
}

I am receiving this:

17:59:58.891 -> **** Its a Hardware Serial ****

17:59:58.936 -> Designed by Draggon

17:59:58.936 ->

17:59:59.410 -> UnoSerial is listening!

17:59:59.410 ->

18:00:00.416 -> UnoSerial is listening!

18:00:00.416 ->

18:00:01.419 -> UnoSerial is listening!

18:00:01.419 ->

18:00:02.421 -> UnoSerial is listening!

18:00:02.421 ->

18:00:03.421 -> UnoSerial is listening!

18:00:03.421 ->

A wiring problem seems likely. Then there is the voltage level mismatch to consider. Best to use logic level converters for RX and TX.

used

I checked multiple wiring configurations without any improvement. Wiring and voltage levels are identical as for communication via Rx and Tx (UNO pins 0, 1), ESP pins Rxd Txd. Threre is activity on UNO receiving pin 2 and the Serial monitor shows data only after ESP starts transmitting.

Data transfer from UNO to ESP via SoftSerial is working as expected.
For the original configuration (ESP -> UNO) baud rate reduction down to 2400 doesnot help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.