Serial communication between esp32-cam and Arduino Uno

I was trying to send some data from esp32-cam to Arduino Uno. So I was try this code for Esp32-cam

#include<Wire.h>
int hour=12;
void setup() {
  Wire.begin();
  Serial.begin(115200);
}
void loop() {
  Wire.beginTransmission(9);//9 here is the address of the slave board
  Wire.write(hour);//Transfers the value of potentiometer to the slave board
  Wire.endTransmission();
  Serial.print(hour);
  delay(1000);
}

And code for Arduino Uno:

#include<Wire.h>
int hour;
void setup() {
  // Begin the Serial at 9600 Baud
  Wire.begin(9);
  Serial.begin(15200);
  Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
  while (0 < Wire.available()) {
    hour = Wire.read();
  }
}
void loop() {
  Serial.print(hour);
  delay(1000);
}

But this code not working for me. I also trying some other way. But none of them work.

Any idea, hints will be appreciate.

The UART serial port is a lot easier to use than I2C.

I believe that Wire.onReceive() is an interrupt handler, so "hour" must be declared volatile.

Hi

show us the wiring and how they are powered

As one is 3.3V the other is 5V - do you have an I2C voltage adapter?

I connect the
Tx pin of esp32-cam to Rx Arduino Uno
Rx pin of esp32-cam to Tx Arduino Uno
And a common ground GND.

No ,I don't use .

How I can do this?

See the "Serial Input Basics" tutorial on the forum.

is your ESP 5V compatible ? (arduino Tx can send 5V into ESP Rx)

and Rx and Tx are not the I2C pins...

This COULD be the mistake

@jremington
I tried all of them. They works for two Arduino but not for Esp32-cam and Arduino.

It works perfectly for me.

I don't know what you did wrong, so can't offer anything more, except to ask whether you used level shifters, as required for connecting 5V and 3.3V modules.

1 Like

@jremington
Can you explain how it works for you?
Means have you any example that works for you?

I use Serial.print() on the ESP32, and Serial.available() + Serial.receive() on the Arduino.

With a 5V to 3.3V level shifter, of course.

Did you connect TX on one to RX on the other, using the level shifter?

1 Like

No, I don't. May be this is the issue I have mistake.
Ok, I will try using the level shifter. Then give you feedback.

You may have permanently damaged either the Arduino or the ESP32.

You must not directly connect a 5V signal to a 3.3V input. The other way around (3.3V output to 5V input) is usually, but not always OK.

1 Like

@jremington

One things is Esp32-Cam also have a 5v input. So if I use 5v input for Esp32-Cam then is it necessary to use level shifter?

If level shifter is must, then is this level shifter will work for me?
image

I want to send data from Esp32-Cam to Arduino.

That is for power, to a voltage regulator. The MCU is 3.3V only.

1 Like

Ok. Thanks.

I got it. Is this level shifter work for Esp32-Cam?

That kind of level shifter will work.

this one worked for me without a level shifter
the esp code


#include "string.h"

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}
void loop() {
String cmd ; 
    //Serial.println("Message Received: ");
   cmd = Serial.readString();
   delay(5);
   Serial.println(cmd) ; 
   delay(5);
    Serial.write("Message Received"); 
    delay(5);
     Serial.println();
}

and the arduino code

#include <SoftwareSerial.h>
#include "string.h"
SoftwareSerial SoftSerial(4, 5);


void setup() {
  Serial.begin(9600);
   SoftSerial.begin(9600);
}
void loop() {
  String cmd;
  SoftSerial.write("Hello Boss"); 
  cmd = SoftSerial.readString() ; 
  Serial.println(cmd);
  delay(500);
}

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