【发布时间】:2019-12-30 04:14:40
【问题描述】:
我正在编写一个应用程序,使用 HC-05 蓝牙模块向 Arduino 发送字符串。
我的问题是我只能将它作为 ascii 字节发送,例如这是我的发送方法:
private void sendData()
{
if (!(btOutputStream == null)){
try {
btOutputStream.write("Hello".getBytes());
ToastMaker("Data is sent");
} catch (IOException e) {
e.printStackTrace();
}
}
}
这是 Arduino 串行监视器的输出:
https://i.stack.imgur.com/88l5w.png
这是Arduino的代码:
#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(10, 9); // RX, TX
int Data; // the data received
void setup() {
Bluetooth.begin(9600);
Serial.begin(9600);
Serial.println("Waiting for command...");
}
void loop() {
if (Bluetooth.available()){ //wait for data received
Data=Bluetooth.read();
Bluetooth.println(Data);
Serial.println(Data);
}
delay(100);
}
总之,我正在寻找一种方法来获取接收到的数据(例如 Hello),如下所示: H e l l o
而不是这个: 72 101 108 108 111
【问题讨论】:
标签: java android arduino bluetooth outputstream