【发布时间】:2019-12-20 16:39:58
【问题描述】:
我目前正在尝试从我的 Arduino 卡 + Seeed BLE Shield HM-11 发送数据(主要是文本),但我有。我可以从我的 android 蓝牙终端毫无问题地发送文本,但是当我在手机上从盾牌接收数据时,它不起作用并且不会引发任何异常。
请注意,LED 仅用于验证手机和屏蔽是否已连接。
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 3
#define TxD 4
#define PINLED 7
#define LEDON() digitalWrite(PINLED, HIGH)
#define LEDOFF() digitalWrite(PINLED, LOW)
#define DEBUG_ENABLED 1
SoftwareSerial Bluetooth(RxD, TxD);
void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(PINLED, OUTPUT);
LEDOFF();
setupBlueToothConnection();
}
void loop()
{
char recvChar;
while(true)
{
if (Bluetooth.available())
{ //check if there's any data sent from the remote bluetooth shield
recvChar = Bluetooth.read();
Serial.print(recvChar);
if (recvChar == '1')
{
LEDON();
Bluetooth.write("Led ON");
}
else if (recvChar == '0')
{
LEDOFF();
}
}
}
}
/***************************************************************************
Function Name: setupBlueToothConnection
Description: initilizing bluetooth connction
Parameters:
Return:
***************************************************************************/
void setupBlueToothConnection()
{
Bluetooth.begin(9600);
Bluetooth.print("AT");
delay(400);
Bluetooth.print("AT+DEFAULT"); // Restore all setup value to factory setup
delay(2000);
Bluetooth.print("AT+NAMESeeedBTSlave"); // set the bluetooth name as "SeeedBTSlave" ,the length of bluetooth name must less than 12 characters.
delay(400);
Bluetooth.print("AT+PIN0000"); // set the pair code to connect
delay(400);
Bluetooth.print("AT+AUTH1"); //
delay(400);
Bluetooth.print("AT+NOTI1"); //
delay(400);
Bluetooth.flush();
}
我希望该代码在收到“1”但没有任何反应时回答“LED ON”
【问题讨论】:
标签: android arduino bluetooth bluetooth-lowenergy