I bought some Bluetooth Low Energy 4.0 HM-10 modules online, turned out to be the cheaper chinese CC-41A clone modules. They are similar to HM-10 and at this point I can only say that CC-41A has limited commands supported, though suffices my requirements. I was able to set it to iBeacon mode too (later on that).
I also learned that
- CC-41A commands are case insensitive, so ‘AT’ and ‘at’ both work!
- CC-41A commands needs to be terminated with \r \n
- CC-41A commands does not entertain ‘?’
- CC-41A default boots to slave mode (Role0)
- CC-41A command – AT+HELP prints all supported commands in that mode
In master role (AT+ROLE1), there is a different set of supported commands
- AT+INQ, runs a scan and lists all devices found (It only searched for CC-41A devices for me)
- AT+CONNn (n is device number from INQ), connects to given device
- Once connected, all commands are passed to remtoe device, and I am not sure how to disconnect from a connected device.
- I don’t know yet how to make CC-41A auto connect to last connected device by default
I tried to update firmware and ended up burning one board, thus I would recommend not to go that direction unless extremely necessary. If you are adventurous, install HM-10 firmware –
- CCLoader Sketch for Arduino
- Windows binary
- HM-10 Original firmware
http://forum.arduino.cc/index.php?topic=393655
Code for Master Controller#include <SoftwareSerial.h>
SoftwareSerial BTSerial(4, 5);
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
BTSerial.write("AT+DEFAULT\r\n");
BTSerial.write("AT+RESET\r\n");
BTSerial.write("AT+NAME=Controller\r\n");
BTSerial.write("AT+ROLE1\r\n");
BTSerial.write("AT+TYPE1"); //Simple pairing
}
void loop()
{
if (BTSerial.available())
Serial.write(BTSerial.read());
if (Serial.available())
BTSerial.write(Serial.read());
}
Switch to Role1 – AT+ROLE1
- AT+HELP will now have different set of commands
- AT+INQ will search for devices
- AT+SHOW fetches search result from cache
- AT+CONN[n] connects to the device by index
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(4, 5);
char cmd[32] = {0};
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
BTSerial.write("AT+NAME=Remote\r\n");
BTSerial.write("AT+TYPE1"); //Simple pairing
}
void loop()
{
static int iter = 0;
if (BTSerial.available())
{
cmd[iter] = BTSerial.read();
//if CRLF (CC41A EOM)
if((cmd[iter] == 10) && (cmd[iter-1]==13))
{
Serial.println(cmd); //dump to serial console
BTSerial.write("Command executed:");
BTSerial.write(cmd); BTSerial.write("\n");
} else {
}
}
if(Serial.available()){
BTSerial.write(Serial.read());
}
}
Comments