Hello
I'm developing a code to send and receive code from Android phone to Arduino using Bluetooth (HC-06 module).
Now I'm using Arduino Leonardo but then I need to use an Arduino Mini Pro (because the size).
And all is working right. I can send and receive data from Android to arduino and viceversa.
The problem is that I want to change the name and the password from Android and I test a lot of things but nothing work properly.
#include <SPI.h>
String BT_msg, type_msg;
void setup() {
Serial1.begin(9600); //BT
}
void loop() { ////// RECEIVE A STRING FROM PHONE
while (Serial1.available()) {
delay(10);
char c = Serial1.read();
BT_msg += c;
}
if(BT_msg.length() > 0) { ////////// IT DO TWO STRINGS WITH THE MAIN STRING
type_msg = BT_msg.substring(0, 1);
BT_msg = BT_msg.substring(2, BT_msg.length());
}
if (BT_msg != "") {
BT_options(); ///////////////// CALL FUNCTION BT_OPTIONS
}
type_msg=""; //// CLEAN VARIABLES
BT_msg="";
}
void BT_options() {
char lett = type_msg.charAt(0);
switch (lett) {
case '1': ////// IF THE FIRST PART OF THE STRING IS 1 PRINT HELLO
Serial.println("HELLO");
break;
case '2': /////////// IF THE FIRST PART OF THE STRING IS 2 TRY TO CHANGE THE NAME OF THE BT MODULE
Serial.println("AT+NAME" + BT_msg);
delay(1000);
Serial1.println("2*" + BT_msg); ///// AND SEND A MESSAGE TO ANDROID PHONE WITH THE NAME
break;
default:
Serial.print("TEST");
break;
}
delay(1500);
}
BUT DOESN'T WORK, THE NAME DOESN'T CHANGE
Someone knows something about change the name (or the password) of the HC-06 from ANDROID??