Can I have multiple HC-05 modules on the Arduino Uno connected using the SoftwareSerial library?
I have two ESP32 boards and I want them both to communicate with the Uno. The two ESP32 do not communicate with each other. They each only communicate with the Uno.
I have two HC-05 modules, one for each ESP32. I found that when I begin the Serial port for both modules, a connection is established but no messages are sent. Is this to be expected?
1. AT UNO side: Try one BT with Software UART Port (SRX = 5, STX = 6) and the second BT with Hardware UART Port (RX = 0, TX = 1). (During sketch uploading, disconnect BT from DPin-0, 1 and put it back after uploading.)
2. You have to go on Master-Slave scheme.
3. AT ESP32 side: you can use the built-in classic BTs of the ESP32 Dev Boards.
Are you referring to one controller as the Master and the other as the Slave? Since each ESP is only communicating with the Uno, I have both ESPs as master controllers while the Uno is the slave controller.
Be aware that only one SoftwareSerial can listen at a time. So you need to design a protocol to confirm to the sending ESP32 that you indeed have received the data; if not, the ESP32 should retry.
You will be far better of using a board with multiple hardware serial ports (e.g. Mega or Nano Every); or at least one free hardware serial port (Leonardo, Micro).
I did this and it kinda works. If I send a message from ESP1's serial input, I can see the message on the Uno's and ESP2's output. This is also true when I send a message from ESP2.
But I dont see the messages I send from the Uno echoed on either ESP Board.
I am using the BTM example code on the ESP boards. The following is my Uno code:
I have ESP2 connected TX 1, RX 2
SoftwareSerial SUART(5, 6);
void setup()
{
Serial.begin(9600);
SUART.begin(9600);
}
void loop() {
if (SUART.available())
{
char x = SUART.read();
Serial.write(x);
}
if (Serial.available()) {
char c = Serial.read();
SUART.write(c);
Serial.print(c);
}
}
Could you elaborate on this protocol? How do I make sure I'm only reading from one ESP at a time. It would be okay for my project if ESP1 sent a message every 5ms and ESP2 sent a message every 10ms. Would this method allow communication with both ESPs from the Uno at the "same time"?