I was try to send some data in form of string form esp32 cam to Arduino mega 2560.
This is the code for esp32 cam:
#include <HardwareSerial.h>
HardwareSerial SerialPort(1);
void setup() {
// Inisialisasi Serial untuk komunikasi dengan PC
Serial.begin(115200);
// Inisialisasi Serial1 untuk komunikasi dengan Arduino Mega
SerialPort.begin(9600, SERIAL_8N1, 16, 17); // RX=16, TX=17
}
void loop() {
// String yang akan dikirim
String message = "Hello from ESP32-CAM";
// Kirim string ke Arduino Mega
SerialPort.println(message);
// Tampilkan di Serial Monitor
Serial.println("Message sent: " + message);
// Tunggu 2 detik sebelum mengirim lagi
delay(2000);
}
and this is the code for the mega:
void setup() {
// Inisialisasi Serial untuk komunikasi dengan PC
Serial.begin(115200);
// Inisialisasi Serial1 untuk komunikasi dengan ESP32-CAM
Serial2.begin(9600);
delay(1000);
}
void loop() {
// Periksa apakah ada data yang tersedia di Serial1
if (Serial2.available()) {
// Baca data yang diterima dari ESP32-CAM
String message = Serial2.readStringUntil('\n');
// Tampilkan di Serial Monitor
Serial.println("Message received: " + message);
} else{
Serial.println("serial2 is not available");
}
delay(100);
}
And then I uploaded the code for the esp32 cam first and the for the mega. When I run the code for the mega I got this result:
Message received: Jk�
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
I got that result over n over again without the string form the variable message in the mega.
What did I do wrong? and how to fix it?
Yes i know that esp32 cam can run at 3.3V. But i read online that esp32 cam run better at 5V and many people ran issues when 3.3V used. The esp32 cam GND is connected to the GND arduino mega.
yes i use a voltage divider for the Rx pin esp32 cam. The 5V i used only for the power to power the esp32 cam that connected to the 5V pin in esp32 cam.
Thank you for showing me the mistake and I already updated it and it still got this result:
Message received: Jk�
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
serial2 is not available
at some point it the serial 2 is available but the message are those character and the question mark icon and other time the serial2 is not available.