的Android / Arduino的蓝牙通信 [英] Android/Arduino bluetooth communication
问题描述
连接成功建立,并能发送数据。
Link successfully established and able to send data.
Android是发送搜索栏数据时,我们曾经改变它。
Android is sending SeekBar data when ever we change it.
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(seekBar.getId() == R.id.seekBar)
{
speed.setText(String.valueOf(progress));
String outputData = String.valueOf(progress);
streams.write(outputData.getBytes());
}
}
streams.write()
将数据写入的OutputStream
的插座的code>。
问题是与数据。如果格式我发送25Arduino是接收'2','5',当我做 Serial.read()
。
Problem is with the format of data.If I Send '25' arduino is receiving '2','5' when I do Serial.read()
.
什么是数据,当 outputData code>转换为字节格式?一切由
终止\\ 0
?
What is the format of data, when outputData
is converted into bytes? Is everything terminated by \0
?
我需要检索的整数,而不是个位数。
I need to retrieve the whole number instead of single digits.
推荐答案
在arduinoboard似乎读取字节RX-流字节。如果您发送25它发送的character'2(这是0x32 /十进制50),然后为字符的ASCII重新presentation的ASCII字节5'(这是0x35 /十进制53)。
Arduino的跨$ P $点这些数字的字符。所以,如果你想传递的数量比256下,你可以这样做:
在Android上:
the arduinoboard seems to read the RX-Stream byte by byte. If you send "25" it transmits the ascii byte for the character'2' (which is 0x32 / decimal 50) and then the ascii representation for the character '5' (which is 0x35 / decimal 53). The arduino interprets these numbers as characters. So if the number you want to transmit is lower than 256 you can do: On Android:
if(seekBar.getId() == R.id.seekBar)
{
speed.setText(String.valueOf(progress));
if(progress<256)
streams.write((byte)progress);
}
要确保的Arduino间$ P $点是正确的,使用接收到的字符为短,而不是作为一个字符。
To make sure the Arduino interprets it right, use the received character as a short and not as a character.
希望这有助于
这篇关于的Android / Arduino的蓝牙通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!