Problem with serial

Hello! Im trying to make my esp32-cam and Arduino UNO communicate with one another serially. I made the ESP32-CAM run a Teachable Machine model which uses hand signals to move right or left or stop and send strings like "STOP" serially. My problem right now is the Arduino is not able to receive messages from the ESP32-CAM, can someone tell me whats wrong? Heres the code:

void Stop() {
  digitalWrite(2,LOW);
  analogWrite(5,0);
  digitalWrite(4,HIGH);
  analogWrite(6,0);
}

void Move_Backward(int speed) {
  digitalWrite(2,LOW);
  analogWrite(5,speed);
  digitalWrite(4,HIGH);
  analogWrite(6,speed);
}

void Rotate_Left(int speed) {
  digitalWrite(2,LOW);
  analogWrite(5,speed);
  digitalWrite(4,LOW);
  analogWrite(6,speed);
}

void Rotate_Right(int speed) {
  digitalWrite(2,HIGH);
  analogWrite(5,speed);
  digitalWrite(4,HIGH);
  analogWrite(6,speed);
}

void Move_Forward(int speed) {
  digitalWrite(2,HIGH);
  analogWrite(5,speed);
  digitalWrite(4,LOW);
  analogWrite(6,speed);
}

void setup() {
  Serial.begin(115200);
}
void loop() {
  if (Serial.available()) {
    String data = Serial.readString();
    if (data=="RIGHT") {
      Rotate_Right(75);
      delay(2100);
    if (data=="LEFT") {
      Rotate_Left(75);
      delay(2100);
    }
    if (data=="STOP") 
    {
      Stop();
    }
    if (data=="FORWARD") 
    {
      Move_Forward(100);
    }
    if (data=="BACKWARD") 
    {
      Move_Backward(100);
    }
    }
  }
}

How re the two devices connected? Do you have the board grounds connected? There are NO messages in the snippet of code you included.

They are both connected by RX and TX pins. Yes, they are both grounded. The ESP32-CAM code actually sends the messages by serial.

Then what was the snippet of code supposed to show? Certainly NOTHING to do with sending or receiving messages.

This code was for the Arduino Uno side of things. At least in my understanding, when the ESP32-CAM sends a string serially to the Arduino Uno, it will do the following movements like moving forward or left.

Imagine we don't have any ability to see what is in front of you. Use more words than fewer.

Better: take a pencil and draw a schematic and post it.

Do you have TX on one board hooked to RX and the other, and the RX on the first connected to TX on the second?

Maybe you think that's a dumb question as it would be a dumb thing to do otherwise. Believe me, we've seen dumber problems, hope that it isn't yours here.

a7

The esp is a 3.3V device and the Uno is a 5v Device.
It’s ok to have the esp Tx to th Uno Rx but the other way needs a voltage adaptation.

You say they are grounded but do the share the same ground ?

If you really need two arduino (explain why?), I would suggest to study Serial Input Basics to handle this serial communication

Have you tested the ESP-32-CAM tx pin with your digital voltmeter? Do you detect ANY voltage fluctuations? That would indicate a message being sent.

First of all, make a simple test of Serial Link by sending character 'A' from ESP32-CAM Board to UNO at 2-sec interval and blinking the onboard LED (at GPIO-33) of ESP32-CAM Board.

1. Upload the following sketch into ESP32-CAM Board using ESP32-CAM-MB adapter.

#define LED 33  //onboard LED
void setup() 
{
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
}

void loop() 
{
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);
  delay(1000);
  //-----------
  Serial.println('A');
}

2. Check that onboard LED is blinking.
3. Open Serial Moniotr at Bd = 9600 and check that A appears on SM.
4. Disconnect the CAM Board from the adapter board.
5. Upload the following sketch into UNO.

#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11); //SRX, STX

void setup()
{
 Serial.begin(9600);
 SUART.begin(9600);
}

void loop()
{
 byte n = SUART.available();
 if (n != 0)
 {
   char y = SUART.read();
   Serial.print(y);
 }
}

6. Connect CAM board with UNO as per Fig-1.


Figure-1:

7. Press RST button of UNO and open Serial Monitor at Bd = 9600.
8. Check that A appears on SM at 2-sec interval.
9. Now, add codes with both the sketches incrementally to realize your project.

Output on SM:

A
A
A

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