serial communication from esp32 to arduino uno

Dear community,
i want to establish a serial communication to send data from my esp32 and read it on my arduino uno .
I am pretty sure that the esp32 is doing well and sends serial data perfectly . I think the problem is in the arduino code . Any help please ?

i am trying to send those values from esp 32 ( strings ) :

              SUART.println(progress1+"/"+progress2+"/"+progress3+"/"+progress4+"/"+progress5+"/"+progress6+"\r");

arduino code

void loop() {
  if (Serial.available()>0) {                         /* i think there is something wrong here */
    byte c = Serial.read();
    Serial.println(c);


    if (indx < sizeof buff) {
     
      buff [indx++] = c; // save data in the next index in the array buff
      if (c == '\r') { //check for the end of the word
        Serial.write(buff);
        progress1=(getValue(String(buff), '/', 0)).toInt();
        progress2=(getValue(String(buff), '/', 1)).toInt();
        progress3=(getValue(String(buff), '/', 2)).toInt();
        progress4=(getValue(String(buff), '/', 3)).toInt();
        progress5=(getValue(String(buff), '/', 4)).toInt();
        progress6=(getValue(String(buff), '/', 5)).toInt();
       
      }}}
              Serial.println(String(progress1)+'/'+String(progress2)+'/'+String(progress3)+'/'+String(progress4)+'/'+String(progress5)+'/'+String(progress6));
      }

      String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

did you do some basic testing with just sending

Serial.println("Hello World");

an ESP32 runs on 3.3V an Arduino runs on 5V.It might be if you directly connected the IO-pins without any protection
that the IO-pin of the ESP32 is damaged.

So for reliable serial communication you need a voltage-level-converter.

global defined Strings will cause memory-problems over time because each assigning of a String allocates new memory and leave memory holes behind. After a certain time all RAM us in use and another assigning of a String will overwrite other variables.

You should always post complete sketches. In 95% of all cases the error is not at the guessed place but somewehre else

best regards Stefan

Yea, your missing a lot of code you should post. Questions such as how your are receiving info on a Uno by way of serial.

Read this: https://blog.startingelectronics.com/how-to-use-arduino-serial-ports/#:~:text=The%20Arduino%20Uno%20has%20only%20one%20hardware%20serial,Due%20both%20have%203%20extra%20hardware%20serial%20ports.

As a note, the ESP32 is NOT 5V tolerant. Most likely if you did not use a level shifter, the ESP32 could be damaged.

Have a look at the examples in Serial Input Basics - simple reliable non-blocking 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

yep i did some basic text examples . i tried to read "hello ! " ( sent by esp32) on arduino but nothing is happening .
and yep i am using protection for the esp32 .
this is the whole code

#include <Servo.h>
Servo Servo1;
Servo Servo2;
Servo Servo3;
Servo Servo4;
Servo Servo5;
Servo Servo6;
char buff [50];
volatile byte indx;
int progress1;
int progress2;
int progress3;
int progress4;
int progress5;
int progress6;



void setup() {
  Serial.begin(9600);
  Servo1.attach(6);
  Servo2.attach(5);
  Servo3.attach(4);
  Servo4.attach(7);
  Servo5.attach(8);
  Servo6.attach(9);


}


void loop() {
  if (Serial.available()>0) {
    byte c = Serial.read();
    Serial.println(c);


    if (indx < sizeof buff) {
     
      buff [indx++] = c; // save data in the next index in the array buff
      if (c == '\r') { //check for the end of the word
        Serial.write(buff);
        progress1=(getValue(String(buff), '/', 0)).toInt();
        progress2=(getValue(String(buff), '/', 1)).toInt();
        progress3=(getValue(String(buff), '/', 2)).toInt();
        progress4=(getValue(String(buff), '/', 3)).toInt();
        progress5=(getValue(String(buff), '/', 4)).toInt();
        progress6=(getValue(String(buff), '/', 5)).toInt();
       
      }}}
              Serial.println(String(progress1)+'/'+String(progress2)+'/'+String(progress3)+'/'+String(progress4)+'/'+String(progress5)+'/'+String(progress6));
      }

      String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

I see that you echo the received characters. You say "nothing is happening", I have to assume that you mean, you don't see any characters on the serial debug output.

The sketch doesn't have any obvious problem. So it is time to show us a wiring diagram.

yep that's what i meant .
i didn't make a writing diagramme xD I am just connecting the Rx and Tx of esp32 with the Tx Rx of the arduino , with a commun GND, and each one has its power source .

mahmoudreg:
yep that's what i meant .
i didn't make a writing diagramme xD I am just connecting the Rx and Tx of esp32 with the Tx Rx of the arduino , with a commun GND, and each one has its power source .

Please make and post one.

mahmoudreg:
yep i did some basic text examples . i tried to read "hello ! " ( sent by esp32) on arduino but nothing is happening .
and yep i am using protection for the esp32 .
this is the whole code

#include <Servo.h>

Servo Servo1;
Servo Servo2;
Servo Servo3;
Servo Servo4;
Servo Servo5;
Servo Servo6;
char buff [50];
volatile byte indx;
int progress1;
int progress2;
int progress3;
int progress4;
int progress5;
int progress6;

void setup() {
  Serial.begin(9600);
  Servo1.attach(6);
  Servo2.attach(5);
  Servo3.attach(4);
  Servo4.attach(7);
  Servo5.attach(8);
  Servo6.attach(9);

}

void loop() {
  if (Serial.available()>0) {
    byte c = Serial.read();
    Serial.println(c);

if (indx < sizeof buff) {
   
      buff [indx++] = c; // save data in the next index in the array buff
      if (c == '\r') { //check for the end of the word
        Serial.write(buff);
        progress1=(getValue(String(buff), '/', 0)).toInt();
        progress2=(getValue(String(buff), '/', 1)).toInt();
        progress3=(getValue(String(buff), '/', 2)).toInt();
        progress4=(getValue(String(buff), '/', 3)).toInt();
        progress5=(getValue(String(buff), '/', 4)).toInt();
        progress6=(getValue(String(buff), '/', 5)).toInt();
     
      }}}
              Serial.println(String(progress1)+'/'+String(progress2)+'/'+String(progress3)+'/'+String(progress4)+'/'+String(progress5)+'/'+String(progress6));
      }

String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

2nd time.

Read this: https://blog.startingelectronics.com/how-to-use-arduino-serial-ports/#:~:text=The%20Arduino%20Uno%20has%20only%20one%20hardware%20serial,Due%20both%20have%203%20extra%20hardware%20serial%20ports.

How shall we analyse the problem if so much nescessary information is left out.

Post the two sketches that you used to do a simple test.
Just a plain pure send "Hello World"
And a program that does receive serial characters and echo them

A wiRing-diagram shows the cables. A wiring-diagram shows the electrical connections.

Make a free hand drawing how you connected the boards.

Post pictures that show easy to identify which wire (which cable) is connected to which IO-pin. Best thing for such pictures is to take the picture from vertically above the microcontroller.

On the Arduino you are using the same serial connection that is used by the virtual-comport. It might be that having the USB-chip and a second serial device connected to the same IO-pins are disturbing each other.
So for testing DIS-connect the USB-cable and connect a different powersupply to the Arduino.

An ESP has three serial interfaces this is another reason to post the whole sketch of the ESP32.
Posting the whole ESP32-sketch in combination with pictures of the real wiring enables to look if hardware-connections and software use the right IO-pins.

As a sidenote: on the long run it is tiring to write this again and again and again. So please read the sticky threads how to write a good question.

best regards Stefan