Hello everyone,
I have a ESP32-S CAM board and 2 Arduino MEGA2560, one with CH340 serial ic and another with original ATMEGA serial 16u2. This 3 boards is working perfectly, i have that for a long time.
Now, i'm trying to get the data in serial of Arduino and transmit using ESP32 Bluetooth.
I found in IDE examples the "SerialtoSerialBT" , and it work perfectly using ESP32 and the original Arduino(16u2 serial IC).
I'm using TX0 and RX0 pins on Arduino and UOT and UOR pin on ESP32
But when i try to connect to CH340 arduino, the arduino TX led just blinks every 0,5S. Ok, it looks like a HW problem, alright?! I thought the same.
So i did a different test:
I connected the ESP32 to 16u2 Arduino, stabilish the comunication, and after that, i just changed the TX and RX wires from 16U2 Arduino to the CH340 Arduino, and it work!
So it could'nt a HW problem, because if i do this procedure, the CH340 Arduino work with ESP32.
I read a lot on google and could'nt find an answer. Does ESP32 need to send a reset command or a specific byte before start running? Why 16U2 don't need this?
The code:
#include "BluetoothSerial.h"
//#define USE_PIN // Uncomment this to use PIN during pairing. The pin is specified on the line below
const char *pin = "1234"; // Change this to more secure PIN.
String device_name = "ESP32-BT-Slave";
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin(device_name); //Bluetooth device name
Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());
//Serial.printf("The device with name \"%s\" and MAC address %s is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str(), SerialBT.getMacString()); // Use this after the MAC method is implemented
#ifdef USE_PIN
SerialBT.setPin(pin);
Serial.println("Using PIN");
#endif
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(20);
}
I'm getting crazy with that.
Thank you guys.