Achindra Bhatnagar
Published © MIT

Bluetooth LE: Using CC-41A (HM-10 Clone)

Using Bluetooth LE module CC-41A (HM-10 clone) with arduino

BeginnerProtip4 hours36,953
Bluetooth LE: Using CC-41A (HM-10 Clone)

Things used in this project

Story

Read more

Schematics

CC41A with Arduino

CC41A connection with Arduino

Code

Code snippet #1

Plain text
#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());
 }
}

Code snippet #2

Plain text
#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());
 }
}

Github

https://github.com/RedBearLab/CCLoader/blob/master/Arduino/CCLoader/CCLoader.ino

Credits

Achindra Bhatnagar

Achindra Bhatnagar

20 projects • 161 followers
Windows Kernel Hacker, IoT Hobbyist, Enthusiast, Developer and Dreamer

Comments