Bluetooth: HM-10 vs CC-41A Clone

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).

HM-10-fake

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.
  • CC-41A, I don’t know yet how to make it 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 willing to adventure, install HM-10 firmware –

  1. CCLoader Sketch for Arduino
  2. Windows binary
  3. 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

WP_20160804_23_27_09_Rich_LI

Code for Slave Device

#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 (Case of CC41A)
   if((cmd[iter] == 10) && (cmd[iter-1]==13)){
     cmd[iter-1] = '\0'; iter = 0;
     Serial.println(cmd); //dump to serial console
     BTSerial.write("Command executed:");
     BTSerial.write(cmd); BTSerial.write("\n");
   } else {
     iter++; iter %= 32;
   }
 }

if(Serial.available()){
   BTSerial.write(Serial.read());
 }
}

CC41A_with_Arduino_bb

Advertisements
Posted in IoT.

One thought on “Bluetooth: HM-10 vs CC-41A Clone

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s