Communication between ESP32-CAM and Arduino UNO

Hi, I’m new to Arduino hardware and I find there is not much info on serial communication between ESP32-CAM and Arduino UNO.
I have a project that is running object detection on ESP32-CAM and send signal to Arduino UNO to perform other task. Is the hardware setup same as ESP32 and Arduino UNO based on this link How to Exchange Data between Arduino and ESP32 using Serial Communication? ?
Thanks in advance. I would appreciate if anyone could answer my question.

1 Like

show your wiring ? be careful the UNO uses a 5V logic and the ESP-CAM uses 3.3V therefore level converters may be required
upload code used (using code tags </>)
what happens when you connect the devices and run the programs? show output of the serial monitors
do you realy require the UNO - could the ESP32-CAM carryout the tasks?

1 Like

sorry for my bad drawing. I haven't connected the devices yet because I just purchased a logic level converter.

Also, there's a problem, since TX and RX of ESP32-cam connect to TX and RX of Arduino Mega, how can I upload the program using FTDI programmer. Does it work if I upload the code to ESP32-CAM using a level converter first then connect to Arduino Mega?

As it is a group project, I have to integrate my part with my friends' part, they are using Arduino Mega.

ps: my bad, it's actually Arduino Mega, not Arduino UNO.

rather than using pins GPIO1 (U0TXD) and GPIO3 (U0RXD) to communicate with the Mega use different pins
e.g. setup Serial1 on the ESP32-CAM
ESP32-CAM GPIO15 TXD1 to Mega Serial1 RX1 (pin 19)
ESP32-CAM GPIO14 RXD1 to Mega Serial1 TX1 (pin 18) - note this requires a potential divider to convert the Mega 5V logic to ESP32 3.3V logic

ESP32-CAM serial test program

// ESP32-CAM  Serial1 test

#define RXD1 14
#define TXD1 15

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);
  Serial.println();
  Serial.println("serial1  test Rx pin 14 Tx pin 15");
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    //Serial.write(inByte);
    Serial1.write(inByte);
  }
}

Arduino Serial1 test

// Arduino Mega serial1 test

// mega pin 18 is Tx
//      pin 19 is Rx
// for loopback test connect pin 18 to pin 19

// for RS232 shield connect pin 18 to Tx and pin 19 to Rx
// for loopback test connect 9 pin D connector pins 2 and 3

unsigned long time;

void setup() {
  Serial.begin(115200);   // initialise serial monitor port
  Serial1.begin(115200);  // initialise Serial1
  Serial.write("Arduino Mega Serial1 test -  for loopback test connect pin 18 to pin 19\n");
}

void loop() {
  if (Serial1.available())        // read from Serial1 output to Serial
    Serial.write(Serial1.read());
  if (Serial.available()) {       // read from Serial outut to Serial1
    int inByte = Serial.read();
    //Serial.write(inByte);     // local echo if required
    Serial1.write(inByte);
  }
}

when the programs are executed information typed on the Mega serial monitor should appear on the ESP32 serial monitor etc etc

a photo

May I know why use 2.2 k ohm instead of 2 k ohm ? Isn’t it using 1:2 ratio to get 3.3 V ? I also don’t have 2.2 k ohm but I can do 2.32 k ohm (1k + 0.33 + 0.33 + 0.33 + 0.33).

the 5v/3.3v potential divider only requires approximatly 1K/2K
2.2.K are common which is why they are used
2K or 2.32K or a pair if 1K would be OK
3.3v logic devices have some tolerance on the pins (e.g. to 3.5V) - it is applying 5V which can kill the device
some 3.3V devices even have some GPIO pins which are 5v tolerant, e.g. PIC24FJ1024GB610
clearly if you are looking a lines with bidirectional signals (e.g. I2C) you need a level converter

Is that I can use the same concept if I'm using Arduino UNO instead of Arduino Mega?

Yes.

But it's worth noting that the GPIO pins of the ESP32 are actually 5v tolerant.

See Are the ESP32 and ESP8266 5V tolerant (Yes they officially are) – QWORQS

For safety use a voltage shifter between Arduino to ESP32 CAM. Try following Serial Communication Between Arduino and ESP32 CAM for a better understanding.

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