In my next Escape Room (PARADOXsquared.com) I want two Arduinos to communicate via HC-05 Bluetooth Modules. I have successfully paired the modules/Arduinos-05 and the Master Bluetooth can send data to the Slave Bluetooth using: SoftwareSerial BTSerial(10, 11); // RX | TX and BTSerial.write(c);. I need the Slave to send data to the Master, but I am clueless on the how.
If this is not possible in Serial communication, can I use I2C with HC-05?
With Classic Bluetooth used by the HC05 modules, the master/slave designation refers to which unit controls the connection. Once the units are connected, they can each talk and receive to/from each other.
What have you tried, and what problems did you encounter.
I ran the Slave code on the Master Arduino/Master AHC05 configuration and ran the Master code on the Slave Arduino/HC05. They could not communicate. I know I2C Masters must request transmission from a Slave. I don't understand the difference between serial communication and I2C. And I don't think there is a BTSerial.request command.
Here is the master code:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
byte c;
int BT_Enable_pin = 9;
void setup() {
Serial.begin(9600); while (!Serial) {}
Serial.println("HC-05_bluetooth_master");
digitalWrite(BT_Enable_pin, LOW); // data mode
BTSerial.begin(38400); while (!Serial) {} // Bluetooth module com rate
}
void loop() {
c = 5;
BTSerial.write(c);
delay(5000);
c = 9;
BTSerial.write(c);
delay(5000);
}
Slave code:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
int firstRead = 0;
byte NewState;
byte FirstState;
void setup() {
Serial.begin(9600); while (!Serial) {}
Serial.println("HC-05_Bluetooth_slave");
BTSerial.begin(38400); // Bluetooth module com rate
}
void loop() {
BTSerial.begin(38400); while (!Serial) {} // Bluetooth module com rate
if (BTSerial.available() > 0) { // Checks for data from master BT
NewState = BTSerial.read(); // Reads data from master BT
if (firstRead == 0) {
firstRead = 1;
FirstState = NewState;
}
Serial.begin(9600); while (!Serial) {}
Serial.print("FirstState "); Serial.print(FirstState);
Serial.print(" NewState "); Serial.println(NewState);
}
}
A few issues. As said, software serial should be at 9600 baud. 38400 is pushing the edge of reliability. The recommended serial input tutorial is also important.
Can you please confirm how your modules are connected to the Arduinos. What module terminal is connected to pin 10(Arduino SS Rx) and what module terminal is connected to pin 11(Arduino SS Tx)?
Thanks for the baud correction cattledog. Removing those lines of code ended the garbage characters on the Arduino Serial Monitor.
pin 10 - TXD, pin 11 - RXD
The Serial Terminal App won't install on my iphone. I could try different app, but I'm more comfortable with the computer. (I'm somewhat tech challenged. This is my 70th winter)
Yes, it is an Android app, and the HC-05 isn't compatible with iOS. You can certainly develop the BT slave code with a serial connection to the computer. When all is complete, the HC05 can replace the monitor and connect to the Serial port pins or through software serial pins.
Are the master and slave now working as you want?
I'm somewhat tech challenged. This is my 70th winter
Merely having one "HC" config'd as a Master and the other as a Slave is not enough.
Here's a great resource. Which approach (pair/bind or cmode) to take is your call.
MC refers to HC-05/HC-06 situations, but an HC-05 can be config'd as either M/S (so an '06 as such is not essential).
My two HC05s are bound, one is Master, the other Slave. The Master sends data to the Slave (38400 baud, 9600 didn't work). I need the Slave to send data to the Master.