Hello there,
I'm working on a project in which I need to connect 2 Arduino cards using Bluetooth. I therefore bought 2 HM-10 modules.
I need the information to be transfered with a 19200 baud rate, but I encounter problems doing that.
First of all, I need the information to be transfered with no delay, but the terminal doesn't seem to be okay and sends me back either nothing, or interrogation points.
When I put delays, information is sent. But the other card receives and prints weird infos.
Here is the code :
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11); //RX,TX
void setup() {
Serial.begin(19200); //launching the Serial on 19200
mySerial.begin(9600); //launching the HM-10 on its native mode, 9600baud
mySerial.write("AT+BAUD?"); //making sure of what's the actual baud rate
delay(20);
mySerial.write("AT+BAUD1"); //change the baud rate to 19200
delay(20);
mySerial.write("AT+ROLE1"); //changing the role to master
delay(20);
mySerial.write("AT+ADDR?"); //finds the address (we don't always know which controller is master) and connects
delay(100);
if(mySerial.read()=="34151387DE12"){
delay(100);
mySerial.write("AT+CON341513E640BF");
delay(100);
}
else{
delay(100);
mySerial.write("AT+CON34151387DE12");
delay(100);
}
Serial.write(mySerial.read()); //prints on the terminal what has been sent back
delay(20);
}
//at this point the 2 cards are connected and should be ready to work, the other in slave mode doesn't have the connection part but has roughly the same code
void loop() {
mySerial.write('1'); //sends 1 on the HM-10
Serial.write('1'); //sends 1 on the terminal
delay(1000);
if(mySerial.available()) {
Serial.write(mySerial.read()); //permits seeing what has been sent to the card
}
if(Serial.available())
mySerial.write(Serial.read()); //permits sending the 1 from the terminal to the HM-10 (double checking)
}
}
Anyone has an idea ?