Android 无错误-从手机应用程序向hm-10 BLE模块发送数据不工作
我已经创建了一个react本机应用程序,正在使用react本机ble管理器库。 我正在使用hm-10 BLE模块和arduino nano,代码->Android 无错误-从手机应用程序向hm-10 BLE模块发送数据不工作,android,react-native,arduino,bluetooth-lowenergy,Android,React Native,Arduino,Bluetooth Lowenergy,我已经创建了一个react本机应用程序,正在使用react本机ble管理器库。 我正在使用hm-10 BLE模块和arduino nano,代码-> #include <SoftwareSerial.h> #define LED_PIN 13 SoftwareSerial mySerial(0, 1); // RX, TX // Connect HM10 Arduino Uno // Pin 1/TXD Pin 7 // Pin 2
#include <SoftwareSerial.h>
#define LED_PIN 13
SoftwareSerial mySerial(0, 1); // RX, TX
// Connect HM10 Arduino Uno
// Pin 1/TXD Pin 7
// Pin 2/RXD Pin 8
void setup() {
Serial.begin(9600);
// If the baudrate of the HM-10 module has been updated,
// you may need to change 9600 by another value
// Once you have found the correct baudrate,
// you can update it using AT+BAUDx command
// e.g. AT+BAUD0 for 9600 bauds
mySerial.begin(9600);
}
void loop() {
int c;
int s;
if (Serial.available()) {
s = Serial.read();
Serial.println("Got other input:");
Serial.println(c);
}
if (mySerial.available()) {
c = mySerial.read();
Serial.println("Got input:");
Serial.println(c);
}
}
我可以通过arduino串行监视器发送数据,代码会打印值,但当我使用上述方法从手机应用程序发送数据时,串行监视器中不会打印值
我不确定我会错在哪里。我的手机应用程序可以连接arduino101上的蓝牙模块并向其发送数据,但当使用arduino nano连接hm-10并发送数据时,什么都不会发生。您可以查看我们的侧面项目,该项目使用相同的lib向arduino发送颜色并处理LED灯
在Arduino方面,我们也使用串行端口。更新:我使用了MSMBLE应用程序,我可以在串行监视器中键入字符并在应用程序上读取字符,但我无法将字符从应用程序发送到设备。为什么要在硬件串行引脚上使用软件串行?对此我没有直接的答案,我看到的所有草图都用过了谢谢你提到了关于使用软件串行和硬件串行引脚的事情,我很遗憾你没有提出修改的建议,但它给了我正确的方向,我通过A:在arduino nano上使用D2和D3,以及B:将softwareSerial对象的波特率设置为57600,因为我找到了一些提到arduino nano需要的文档
deviceObject.writeCharacteristicWithoutResponseForService(writeService, writeChar, encodedString);