如何基于HM-10蓝牙模块上使用BLE盾牌? [英] How to use BLE Shield based on HM-10 bluetooth module?
问题描述
我在Arduino的项目,一个新的国际展览局。我想问您一些帮助。我买了BLE盾的Arduino从(的http://imall.iteadstudio.com/development-platform/arduino/shields/im130704001.html )。他们使用HM-10蓝牙模块使这个盾( http://www.jnhuamao.cn/ bluetooth.asp?ID = 1 )。 Itead Studio有使用这种屏蔽没有样品codeS。我对如何把它的程序或Arduino的发送AT命令不知道。
我读了AT命令的数据表(<一个href=\"ftp://imall.iteadstudio.com/Shield/IM130704001_ITEAD_BLE_Shield/DS_IM130704001_ITEAD_BLE_Shield.pdf\" rel=\"nofollow\">ftp://imall.iteadstudio.com/Shield/IM130704001_ITEAD_BLE_Shield/DS_IM130704001_ITEAD_BLE_Shield.pdf)我试图用这个code从Arduino的发送AT命令来屏蔽BLE(的http:// arduino.cc/en/Reference/SoftwareSerial ),但我只收到的命令回来了。
有没有人曾经在这里利用这个HM-10蓝牙模块?
我需要一些Arduino的草图帮助!
的#include&LT; SoftwareSerial.h&GT; INT领导= 13;
INT bluetoothTx = 2;
INT bluetoothRx = 3;
SoftwareSerial蓝牙(bluetoothTx,bluetoothRx);
INT波特率[8] = {4800,9600,14400,19200,28800,38400,57600,115200};
INT I = 1;无效设置(){
Serial.begin(9600);
bluetooth.begin(9600);
而(!串行){} Serial.write(AT派);
延迟(500);
bluetooth.write(AT + NAME?);
延迟(500);
而(bluetooth.available()){
Serial.write(bluetooth.read());
}
延迟(100);
Serial.println(); bluetooth.write(AT + POWE3);
延迟(500);
而(bluetooth.available())
{
Serial.write(bluetooth.read());
}
延迟(100);
Serial.println(); 延迟(500);
bluetooth.write(AT + CHAR?);
延迟(500);
而(bluetooth.available()){
Serial.write(bluetooth.read());
}
延迟(100);
Serial.println(); 延迟(500);
bluetooth.write(AT + NAMEFlightline); //检查状态
延迟(500);
而(bluetooth.available()){
Serial.write((char)的bluetooth.read()); } Serial.println();
bluetooth.write(AT + CHAR0x2901); //添加charicteristic
延迟(500);
而(bluetooth.available()){
Serial.write(bluetooth.read()); }
Serial.println();
bluetooth.write(AT + RELI0);
延迟(500);
而(bluetooth.available()){
Serial.write(bluetooth.read());
}
Serial.println();
bluetooth.write(AT +秀王);
延迟(100);
而(bluetooth.available()){
Serial.write(bluetooth.read()); }
Serial.println(); pinMode(LED,OUTPUT);
digitalWrite(LED,HIGH);
}无效testAllBaudRates(){
对于(INT J = 0; J&LT; 8; J ++)
{
bluetooth.begin(波特率[J]);
延迟(100);
Serial.println(boud率+字符串(波特率[J],DEC)+&I- GT;+字符串(J,DEC));
// Serial.println();
bluetooth.write(AT);
延迟(500);
而(bluetooth.available()){
Serial.write(bluetooth.read());
Serial.println();
}
延迟(100);
}
}//现在的LED几闪烁,
//这样我们就知道在程序运行无效循环()
{
//从蓝牙读写USB串行
而(bluetooth.available())
{
焦炭toSend =(char)的bluetooth.read();
如果(toSend =='X'){
digitalWrite(LED,HIGH);
Serial.println(设置高);
bluetooth.write(RXOK);
}否则如果(toSend =='Y'){
digitalWrite(LED,LOW);
Serial.println(定低);
bluetooth.write(RXOK);
}
Serial.print(toSend); } //从USB串行读给蓝牙
而(Serial.available())
{
焦炭toSend =(char)的Serial.read();
bluetooth.write(toSend);
Serial.print(toSend);
}
}
有一个看看我的素描上面我有一些事情要指出的是,我浪费了时间。
请确保您有行
而(!串行){}
或者,你可能会得到有一个工作盾,但错过了回应作为串行显示器是没有准备好。
记住你不会从串行监视器获得从蓝牙模块的响应,用一命令,如果它被连接到一个设备上。当指示灯停止闪烁它连接到该设备。
如果你运行这个小品,你应该得到这样的输出
AT SENT
OK +套装:3
OK +送:0x2901&LT; - 这可能为空你第一次运行
OK +套装:飞行线
OK +套装:0x2901
OK +套装:0
OK +套装:1
目前的大多数COM prehensive命令列表可以在这里找到。
[所有的AT命令和一个很好的解释] [1]
您需要的特性为我在这里做设备
bluetooth.write(AT + CHAR?);
或你会发现它连接到iOS和Android
如果您连接到Android使用BluetoothLE类没有蓝牙的。
I'm a new bie on arduino projects. I would like to ask you for some help. I bought a BLE Shield for Arduino from ( http://imall.iteadstudio.com/development-platform/arduino/shields/im130704001.html ). They made this shield using Hm-10 Bluetooth module(http://www.jnhuamao.cn/bluetooth.asp?ID=1). Itead Studio has no sample codes using this shield. I have no idea on how to program it or send AT commands from Arduino.
I read the "AT commands" at the data sheet (ftp://imall.iteadstudio.com/Shield/IM130704001_ITEAD_BLE_Shield/DS_IM130704001_ITEAD_BLE_Shield.pdf) and I tried to send "AT commands" from arduino to BLE shield using this code ( http://arduino.cc/en/Reference/SoftwareSerial ) but I only received the commands back.
Did anybody here ever use this HM-10 bluetooth module ?
I need some arduino sketch for help !
#include <SoftwareSerial.h>
int led = 13;
int bluetoothTx = 2;
int bluetoothRx = 3;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
int baudrate[8] ={4800,9600,14400,19200,28800,38400,57600,115200};
int i = 1;
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
while(!Serial){}
Serial.write("AT sent");
delay(500);
bluetooth.write("AT+NAME?");
delay(500);
while (bluetooth.available()) {
Serial.write(bluetooth.read());
}
delay(100);
Serial.println("");
bluetooth.write("AT+POWE3");
delay(500);
while(bluetooth.available())
{
Serial.write(bluetooth.read());
}
delay(100);
Serial.println("");
delay(500);
bluetooth.write("AT+CHAR?");
delay(500);
while (bluetooth.available()) {
Serial.write(bluetooth.read());
}
delay(100);
Serial.println("");
delay(500);
bluetooth.write("AT+NAMEFlightline"); //Check Status
delay(500);
while (bluetooth.available()) {
Serial.write((char)bluetooth.read());
}
Serial.println("");
bluetooth.write("AT+CHAR0x2901"); //add charicteristic
delay(500);
while (bluetooth.available()) {
Serial.write(bluetooth.read());
}
Serial.println("");
bluetooth.write("AT+RELI0");
delay(500);
while (bluetooth.available()) {
Serial.write(bluetooth.read());
}
Serial.println("");
bluetooth.write("AT+SHOW1");
delay(100);
while (bluetooth.available()) {
Serial.write(bluetooth.read());
}
Serial.println("");
pinMode(led,OUTPUT);
digitalWrite(led,HIGH);
}
void testAllBaudRates(){
for(int j=0; j<8; j++)
{
bluetooth.begin(baudrate[j]);
delay(100);
Serial.println("boud rate " + String(baudrate[j],DEC) +" i-> "+String(j,DEC));
// Serial.println("");
bluetooth.write("AT");
delay(500);
while (bluetooth.available()) {
Serial.write(bluetooth.read());
Serial.println();
}
delay(100);
}
}
// and now a few blinks of the LED,
// so that we know the program is running
void loop()
{
//Read from bluetooth and write to usb serial
while(bluetooth.available())
{
char toSend = (char)bluetooth.read();
if(toSend == 'x'){
digitalWrite(led,HIGH);
Serial.println("set high");
bluetooth.write("RXOK");
}else if(toSend == 'y'){
digitalWrite(led,LOW);
Serial.println("set low");
bluetooth.write("RXOK");
}
Serial.print(toSend);
}
//Read from usb serial to bluetooth
while(Serial.available())
{
char toSend = (char)Serial.read();
bluetooth.write(toSend);
Serial.print(toSend);
}
}
Have a look at my sketch above I have a few things to point out that I wasted time on.
make sure you have the line
while(!Serial){}
Or you may get have a working shield but miss the responses as the serial monitor is no ready.
remember that you wont get a response from the blue-tooth module, with a command from the Serial Monitor if it is connected to a device. It is connected to the device when the light stops flashing.
if you run this sketch you should get this output
AT sent
OK+Set:3
OK+Get:0x2901 <- this may be blank the first time you run it
OK+Set:Flightline
OK+Set:0x2901
OK+Set:0
OK+Set:1
the most comprehensive list of AT commands can be found here
[All the AT commands and a good explanation][1]
You will need to at Characteristics to the device as I have done here
bluetooth.write("AT+CHAR?");
or you will find it to connect to iOS and Android
If you are connecting to Android use the BluetoothLE Classes not Bluetooth ones.
这篇关于如何基于HM-10蓝牙模块上使用BLE盾牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!