一切都在标题中。当我将字符串数据从 Arduino 发送到 android 时,我会收到这个 ������������������。我尽一切努力获得真正的价值,但没有。请帮忙。在这里编辑 Arduino 部分:
#include <SoftwareSerial.h>
#define rxPin 19
#define txPin 18
SoftwareSerial BTserial(rxPin, txPin);
void setup() {
// put your setup code here, to run once:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
BTserial.begin(38400);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
BTserial.println("ROGER AIME LES POMMES. HEIN LE SALAUD");
delay(5000);
}
Android part :
public void run() {
byte[] buffer = new byte[1024];
int bytes;
while (true) {
try {
bytes = mmInStream.read(buffer);//read bytes from input buffer
bluetoothIn.obtainMessage(handlerState, bytes, -1, buffer).sendToTarget();
}
catch (IOException e) {
break;
}
}
}
在 onCreate
bluetoothIn = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what == handlerState) {
byte[] readBuff = (byte[]) msg.obj;
String readMessage = new String(readBuff,0,msg.arg1);
blue_tv2.setText("Data Received = " + readMessage);
Log.d("", "handleMessage: "+readMessage);
}
}
};
我跑步时的控制台。
D/: handleMessage: z
D/: handleMessage: z_�~�
D/: handleMessage: z
D/: handleMessage: z_�~�
D/: handleMessage: 7
D/: handleMessage: z_�~�
D/: handleMessage: 7
D/: handleMessage: z_�~�