Hello, I am attempting to communicate via serial communication between an ESP-32 CAM and an Arduino Uno. Ideally, the communication needs to go in both directions, but as long as I can view data sent from the ESP-32 to the Arduino on the Arduino serial monitor, it will work for my project. The data being sent is a single character. I have tried many variations in both the wiring of the circuit and the programming, but all my attempts have failed thus far. I have attached my current circuit diagram below as well as the pinouts of my specific esp-32. If anyone has any ideas, I would greatly appreciate it.
Try the following simple connection (Fig-1):
Figure-1:
Do you know the procedures of testing?
Note: You must use level shifter to connect STX-line of UNO with U0RXD-line of ESP32-CAM.
Post your code using code tags, please.
Also, if you have never spent time with the linked page by @Robin2 , it's excellent and worth studying.
Firstly, thank you for your responses, the help is greatly appreciated.
I apologize for my own lack of knowledge but I don't see how my diagram is different from the one you suggested other than changing the power source of the ESP-32 CAM from a battery to the 5V supply of the arduino. The reason I did not do this initially was because I did not want to draw too much current from the Arduino uno. If you could elaborate on what exactly I should change, I would greatly appreciate it.
Thank you hallowed31 for the resource you provided. My latest code (which did not work), is posted below. The intended function of this code is that I will send the char A to the arduino through my computer serial monitor, the arduino will then send that same char to the ESP-32, the ESP-32 will read the char and return the character B to the arduino, and finally the arduino will send the character B to the serial monitor of my computer. I ran this code with the same wiring setup as I previously posted.
Arduino Code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Native USB only
}
Serial.println("Arduino is ready");
// set the data rate for the SoftwareSerial port
mySerial.begin(115200);
}
void loop() // run over and over
{
if (Serial.available())
mySerial.write(Serial.read());
if (mySerial.available())
Serial.write(mySerial.read());
}
ESP-32 CAM code:
// ESP32-CAM Serial1 test
void setup() {
// initialize both serial ports:
Serial.begin(115200);
}
void loop() {
// read from port 0, send to port 1:
if (Serial.available()) {
char inByte = Serial.read();
if(inByte == 'A'){
Serial.write('B');
}
}
}
Any help is appreciated, thanks.
Please ignore the comments in the ESP-32 CAM code. This code was adapted from another source.
The majority of people trying that speed never got their communications to work! Don't go above 34k bps.
1. Tell me how are you programming the ESP32-CAM Module? Are you using ESP32-CAM-MB adapter (Fig-1).
Fig-1:
2. Upload the following sketch in ESP32-CAM Module using ESP32-CAM-MB adapter.
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Hello!");
delay(1000);
}
3. Upload the following sketch in UNO (noy tested)
#include<SoftwareSerial.h>
SoftwareSerial SUART(10, 11);
void setup()
{
Serial.begin(9600);
SUART.begin(9600);
}
void loop()
{
byte n = SUART.available();
if(n != 0)
{
char ch = SUART.read();
Serial.print(ch);
}
}
4. Check that Serial Monitor of UNO shows the message Hello! at 1-sec inerval.
You have used level shifter which is not needed if you are connecting the U0TXD-line of CAM with SRX-line of UNO.
I am using the ESP32-CAM-MB adapter to upload the code, and I uploaded the exact code you provided, but there was still no message sent to the serial monitor of the Arduino Uno. I did keep both communication lines going through the level shifter as I assumed there would be no difference on the arduino receiving end. Any ideas?
Perhaps I am wrong, but char can only store one letter, correct? I changed Serial.println("Hello!") to Serial.write('A'), but it still did not work.
Check that your CAM is ok by running a sketch that blinks the onboard LED of CAM.
I ran an object detection code, simply because I already had it pulled up, and it works. If the next troubleshooting step is considering whether or not the components are functional themselves, the number one culprit is probably the level shifter. I soldered the pins myself, and I am not very experienced in this area. I assume that I can bypass the level shifter using a voltage divider between a 2k a 1k ohm resistor on the tx line of the arduino. Is this correct?