原廠連結:http://www.seeedstudio.com/wiki/index.php?title=Seeed-BLE_Shield_v1
Seeed BLE Shield v1 是一款低功耗藍牙4.0傳輸模塊。模塊採用的是TI CC2540芯片,配置256Kb空間,支持AT指令。你可以將此模塊應用於遙控、遊戲手柄、數據無線採集、智能家居等領域。同時作為Shield系列的一員,它能很方便的直插到開發板上使用。
註:此圖為樣板示意圖,生產圖請在簡介版塊查看。
直接將BLE Shield插入到Arduino/Seeeduino上. 請注意PCB板上跳帽的選擇.
當你使用不同代碼的時候,Seeed BLE Shield可以作為主機或從機。當使用軟串口通信時,即使用軟件代碼對BLE模塊進行通信時,跳帽的選擇應為:BLE_TX-->D2,BLE_RX-->D3.
然後打開Arduino IDE v1.0.5,複製以下主機或從機的代碼,並下載到主板中。
從機代碼
#include <SoftwareSerial.h> //Software Serial Port #define RxD 2 #define TxD 3 #define DEBUG_ENABLED 1 SoftwareSerial BLE(RxD,TxD); void setup() { Serial.begin(9600); pinMode(RxD, INPUT); pinMode(TxD, OUTPUT); setupBleConnection(); } void loop() { char recvChar; while(1){ if(BLE.available()){//check if there's any data sent from the remote BLE shield recvChar = BLE.read(); Serial.print(recvChar); } if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here recvChar = Serial.read(); BLE.print(recvChar); } } } void setupBleConnection() { BLE.begin(9600); //Set BLE BaudRate to default baud rate 9600 BLE.print("AT+CLEAR"); //clear all previous setting BLE.print("AT+ROLE0"); //set the bluetooth name as a slaver BLE.print("AT+SAVE1"); //don't save the connect information }
主機代碼
#include <SoftwareSerial.h> //Software Serial Port #define RxD 2 #define TxD 3 #define DEBUG_ENABLED 1 SoftwareSerial BLE(RxD,TxD); void setup() { Serial.begin(9600); pinMode(RxD, INPUT); pinMode(TxD, OUTPUT); setupBleConnection(); } void loop() { char recvChar; while(1){ if(BLE.available()){//check if there's any data sent from the remote BLE shield recvChar = BLE.read(); Serial.print(recvChar); } if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here recvChar = Serial.read(); BLE.print(recvChar); } } } void setupBleConnection() { BLE.begin(9600); //Set BLE BaudRate to default baud rate 9600 BLE.print("AT+CLEAR"); //clear all previous setting BLE.print("AT+ROLE1"); //set the bluetooth name as a master BLE.print("AT+SAVE1"); //don't save the connect information }
當然,你可以通過AT指令直接對BLE模塊進行操作,而不需要使用任何代碼。但需要注意跳帽的位置:BLE_TX-->D1,BLE_RX-->D2。
然後打開串口工具,比如MAC版用戶可以打開CoolTerm串口助手,PC版用戶可打開Sscom32串口工具。串口工具的設置如下:Baudrate: 9600(default) , Data Bits: 8, Parity: none, Stop Bits: 1
你可以發送指令"AT"進行測試,如果返回「OK」,即能夠通信。如果沒有返回任何值,用戶可以嘗試燒錄一個空程序到主板上,然後再發送指令「AT」進行測試。
void setup() { } void loop() { }
確認可以通信之後,便可以發送AT指令給BLE模塊了。比如設置BLE模塊為從機,發送指令「AT+ROLE0」,如果返回「OK+Set:0」,即表示BLE模塊已設置成功。
所有的AT指令都包含在以下的資源版塊的BLE模塊data sheet中,用戶請自行下載查閱。
Schematic of Seeed BLE Shield
BLE_apk_for_Android
DataSheet of BLE module
資料來源:https://www.seeedstudio.com/Seeed-BLE-Shield-p-1859.html
Dimensions | 115mm x 75mm x 25mm |
Weight | G.W 45g |
Battery | Exclude |
Seeed BLE Shield | 1 |