Background: I am attempting to create a "follow me robot" that uses a combination of sensors and visual feedback from the ESP32-CAM for path planning and obstacle avoidance. As you probably would think, for most types of image / video processing, the Arduino Mega2560 and even the ESP32 is simply not strong enough. Hence, why I am using the ESP32-CAM to not only capture images, but also to live stream that image so a stronger computer (in my case a smartphone via an android app) will process the videostream and instruct the "follow me robot" on where to go. But, since my follow me robot would need a lot of input pins just using the ESP32-CAM is not sufficient. I need to find some way to allow serial communication using the RX and TX pins between my ESP32-CAM and my Arduino Mega. I need to be able to send input data from my various sensors to the ESP32-CAM so that the ESP32-CAM can then forward that data via wifi to a smartphone android app.
Anyways, for reference, in order to upload code to the ESP32-CAM, I currently have my Arduino board and ESP cam looked up like this with the settings on my Arduino IDE using the board "AI Thinker ESP32-CAM":
In order to upload code to the Arduino Mega, all I'm doing is disconnecting the GND from the RESET pins, and setting my IDE to the "Arduino Mega" board.
And of course my Arduino mega is connected to my computer and that's how I am uploading code to both my mega and esp cam.
Problem: As I alluded to in the background portion of this, my problem is I am not sure how exactly to go about communicating between the Arduino Mega and ESP Cam. I'm almost certain it's possible via the RX/TX pins, but I haven't the slightest clue on how to approach this programmatically. Here are some things I have tried:
-
As I described in my background, I can upload code individually to both my mega and my esp, and they both work. Moreover, in the serial monitor, I noticed that when both boards have their serial outputs at different baud rates, I can get debug info from both boards by just changing the baud rate I'm listening to. So based off that, I did try setting both boards to the same baud rate to see if I could just use the Serial.available() function to get serial info from each other between the boards.
-
I tried to use the SoftwareSerial library as shown below. In this example, what I was attempting to do:
Code on my MEGA
#include <SoftwareSerial.h>
SoftwareSerial esp(0,1); //RTX, TX
void setup() {
Serial.begin(9600);
while (!Serial.available()) {
}
esp.begin(19200);
}
void loop() {
Serial.println(esp.read());
}
Then I modified the CameraWebServer example code from the ESP32-CAM and added these [not I'm not including code from the CameraWebServer because it's too long and distracting:
#include <SoftwareSerial.h> //Note: This is the esp softwareserial library. Not the regular one. Just an implementation of the regular one for esps.
SoftwareSerial ard(1, 3); //1 for GPIO1 and 3 GPIO3 - not sure if this is right
void setup() {
Serial.begin(9600);
while (!Serial.available()) {
}
ard.begin(19200);
}
void loop() {
if (ard.available()) {
ard.write("Test");
}
}
And well, not only did my webserver stop working for the ESP32-CAM, but I did not get a "Test" printed on my console either. I feel like I am missing some fundamental or approaching this completely the wrong way....
P.S. this is my first post, if I missed anything, or if you need more information from me, do let me know!