Hardware/Bluetooth

HM-10 BLE4.0 (Bluetooth Low Energy, CC2540, CC2541) 모듈을 iOS와 Arduino 시스템에서 사용하기

초인로크 2017. 9. 14. 10:01
반응형

아이폰 등의 iOS 기기에서 블루투스 모듈을 이용하기 위해서는,

iOS에서 지원하는 기기인가 아닌가를 알아봐야 하는데,

실제로 지원되는 기기가 적기 때문에, 시스템을 만들다 보면 많은 고민을 하게된다.

아마존에서 모듈 하나당 312엔으로 판매하고 있는 곳이 있어서 구매 해 봤다.

(https://www.amazon.co.jp/gp/product/B013QI09BW/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1)

실제로 배송은 중국에서 오는 관계로 일주일 이상 기다린 끝에 아래와 같은 모듈이 왔다.

(실제로는 블루투스 기판밖에 안오며, 아래의 다리 부분은 내가 따로 주문해서 납땜질 했다.)

아두이노 경유의 AT 커멘드를 이용하여, 블루투스의 설정을 바꿀 수 있다.

(첫번째 참고문헌의 필자의 말로는, 이 모듈(Bolutek사 제품)은 호환모듈이라서 기능이 적고 구현하는데 조금 다른 방법이 필요하다고 적혀있으니 구매를 고려한 경우에는 주의 바란다.)

아두이노용 AT 커멘드 소스코드는 아래와 같으니 참고하길 바란다.

(시리얼 모니터 설정을 "Both NL & CR" 로 해준다.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <SoftwareSerial.h>
 
SoftwareSerial BTSerial(23);   //Tx:Digital 2 Rx:Digital 3
 
void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);
  Serial.println("ATcommand");  //ATcommand Start
}
 
void loop() {
  if (BTSerial.available()>0)
    Serial.write(BTSerial.read());
  if (Serial.available()>0)
    BTSerial.write(Serial.read());
}
cs


실제로 테스트 해 본 결과, AT 커멘드도 잘 먹히고, 아두이노를 이용한 데이터의 송/수신에 문제가 없었다.

블루투스 송/수신에 관한 테스트는 아래의 소스로 확인이 가능하다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <SoftwareSerial.h>
 
#define LED13 0x0D
 
SoftwareSerial BTSerial(23); //Tx:Digital 2 Rx:Digital 3
 
int count, ss;
char Rec;
String sCommand = "";
 
void setup()  
{
  Serial.begin(9600);
  BTSerial.begin(57600);
}
 
void loop()
  sCommand = "";
  if (BTSerial.available()>0){
    digitalWrite(LED13, HIGH);
    while(BTSerial.available())
    {
      Rec = BTSerial.read();
      sCommand.concat(Rec);
    }
    Serial.println(sCommand);
  }
 
  if (BTSerial.available()>0) {
    Serial.println(BTSerial.read());
    digitalWrite(LED13, HIGH);
  }
 
  if (Serial.available()>0){
    BTSerial.write(Serial.read());
    digitalWrite(LED13, HIGH);
  }
 
  delay(100);
  digitalWrite(LED13, LOW);
}
cs

이전까지는 OLS426i를 썼었는데, 구하기가 쉽지 않아서 고민을 좀 했는데 잘 되었다.

좀 더 자세한 내용은 아래의 페이지를 참고하길 바란다.

<참고문헌>

1. HM-10에 대한 설명: http://fab.cba.mit.edu/classes/863.15/doc/tutorials/programming/bluetooth.html

2. AT 커멘드 설명: http://www.instructables.com/id/AT-command-mode-of-HC-05-Bluetooth-module/

3. iOS용 샘플 소스: https://github.com/hoiberg/HM10-BluetoothSerial-iOS

4. iOS용 샘플 소스(아이튠즈): https://itunes.apple.com/us/app/hm10-bluetooth-serial-lite/id1030454675?mt=8

5. 블루투스 아두이노 개발 : https://ladvien.com/robots/connect-an-arduino-to-iphone/

반응형