我已将arduino与我的Android设备连接,我已建立连接并获得输出流。
ANDROID PART
String one = "1";
byte[] input = one.getBytes(Charset.forName("UTF-8"));
mConnectedThread.write(input);
ARDUINO PART
如何处理收到的byte []并将其转换回String?
答案 0 :(得分:0)
传入流上有一个128字节的缓冲区。使用
在你的循环中():
char inByte;
// check for bytes in the buffer
if (Serial.available() > 0) {
// read the available bytes one at a
// time and purge from buffer
inByte = Serial.read();
// print out byte so you can see it on
// the serial monitor
Serial.print(inByte);
}
如果缓冲区足够大以满足您的需求,那么您不必担心编码其他任何内容。您可以处理char数组中的传入字节,也可以将各个字符读入String对象。
这里有很多好消息: http://arduino.cc/en/Reference/string
...在char数组和该页面顶部到String对象的链接。如果您有其他问题,请告诉我,希望这至少可以帮助您启动并正确调试传入的代码