的Andr​​oid / Arduino的蓝牙通信 [英] Android/Arduino bluetooth communication

查看:102
本文介绍了的Andr​​oid / Arduino的蓝牙通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

连接成功建立,并能发送数据。

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 插座

问题是与数据。如果格式我发送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 转换为字节格式?一切由终止\\ 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.

希望这有助于

这篇关于的Andr​​oid / Arduino的蓝牙通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆