Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bluetooth 如何使用基于HM-10蓝牙模块的BLE屏蔽?_Bluetooth_Arduino_Bluetooth Lowenergy_Hm 10 - Fatal编程技术网

Bluetooth 如何使用基于HM-10蓝牙模块的BLE屏蔽?

Bluetooth 如何使用基于HM-10蓝牙模块的BLE屏蔽?,bluetooth,arduino,bluetooth-lowenergy,hm-10,Bluetooth,Arduino,Bluetooth Lowenergy,Hm 10,我是arduino项目的新手。我想请你帮忙。我从()为Arduino买了一个可折叠的盾牌。他们使用Hm-10蓝牙模块()制作了这个防护罩。Itead Studio没有使用此屏蔽的示例代码。我不知道如何编程或从Arduino发送AT命令 我阅读了数据表()中的“AT命令”,并尝试使用此代码()将“AT命令”从arduino发送到BLE shield,但我只收到了返回的命令 这里有人用过这个HM-10蓝牙模块吗 我需要一些arduino草图以获得帮助!这也有点晚了,但请尝试以下代码,如果您将其发送到

我是arduino项目的新手。我想请你帮忙。我从()为Arduino买了一个可折叠的盾牌。他们使用Hm-10蓝牙模块()制作了这个防护罩。Itead Studio没有使用此屏蔽的示例代码。我不知道如何编程或从Arduino发送AT命令

我阅读了数据表()中的“AT命令”,并尝试使用此代码()将“AT命令”从arduino发送到BLE shield,但我只收到了返回的命令

这里有人用过这个HM-10蓝牙模块吗


我需要一些arduino草图以获得帮助!

这也有点晚了,但请尝试以下代码,如果您将其发送到“AT”,它将返回“OK”:

#包括
int bluetoothTx=2;//蓝牙伴侣的TX-O引脚,Arduino D2
int bluetoothRx=3;//蓝牙配对的RX-I引脚,Arduino D3
软件串行蓝牙(bluetoothTx、bluetoothRx);
无效设置()
{
Serial.begin(9600);//以9600bps开始串行监视器
bluetooth.begin(115200);//蓝牙配对默认为115200bps
延迟(100);//短暂延迟,等待大副发回指令
bluetooth.println(“U,9600,N”);//暂时将波特率更改为9600,无奇偶校验
//115200有时可能太快,NewSoftSerial无法可靠地中继数据
bluetooth.begin(9600);//在9600启动bluetooth串行
}
void循环()
{
if(bluetooth.available())//如果蓝牙发送了任何字符
{
//将蓝牙打印的任何字符发送到串行监视器
Serial.print((char)bluetooth.read());
}
if(Serial.available())//如果在串行监视器中键入了内容
{
//将串行监视器打印的任何字符发送到蓝牙
bluetooth.print((char)Serial.read());
}
//并且永远循环!
}
您可以使用波特率自动检测来控制您的HM-10。这是允许通过BLE上传到Arduino板的一部分

#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);
  }
}
或者,您可能有一个工作屏蔽,但由于串行监视器未准备就绪,因此无法响应

请记住,如果蓝牙模块连接到某个设备,则不会收到蓝牙模块的响应,也不会收到串行监视器的命令。当指示灯停止闪烁时,蓝牙模块就会连接到该设备

如果运行此草图,则应获得此输出

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
您需要像我在这里所做的那样,对设备的特性进行分析

bluetooth.write("AT+CHAR?");
或者你会发现它连接到iOS和Android


如果您连接到Android,请使用蓝牙类而不是蓝牙类。

它不工作,为什么要这样做:Bluetooth.begin(115200)hm-10波特率是9600,我不明白这句话,默认值不是115200,他们从来不会这么说。另外,如果你只是把东西连接到uno,尝试什么都不连接,你为人类写了一个非常超级快速的代码。非常感谢。我做得很好!爱。没有连接选项,我们怎么能做一个新的蓝牙服务?在Arduino上?我是不知道你的意思,所以当你运行你的代码时,你需要点击“连接”按钮来读/写十六进制数据。我问,在显示你的BLE的UUID时,是否有可能发送数据看起来不需要像Arduino上的温度值那样连接?写另一个问题,我可以为你发布代码
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
[All the AT commands and a good explanation][1]
bluetooth.write("AT+CHAR?");