简体   繁体   English

Arduino上的蓝牙接收

[英]Bluetooth reception on arduino

I have created an android application which sends a value between 0 and 20 like this : 我创建了一个android应用程序,它发送的值介于0到20之间,如下所示:

    public void write(byte[] msg) {
        cnt++;
        Log.v("CNT", Integer.toString(cnt));
        try {
            for(byte b : msg)
            {
                Log.v("Buffer", Byte.toString(b));
            }
            mmOutStream.write(msg);
        } catch (Exception e) { Log.e("ConnectedThread","Send Error",e); }
    }

My arduino code is the following : 我的arduino代码如下:

SoftwareSerial bluetooth(2,8);


void setup()
{
  Serial.begin(9600);
  bluetooth.begin(9600);
  Serial.println("Bluetooth Start!");

}

void loop()
{
  char inDat;
  char outDat;
  if(bluetooth.available())
  {
    inDat = bluetooth.read();
    Serial.println(inDat);
  }
  if(Serial.available())
  {
    outDat = Serial.read();
    bluetooth.write(outDat);
  }
}

I was hoping to get numbers between 0 and 20 on the serial console but i only get "ÿ" 我希望在串行控制台上获得0到20之间的数字,但我只得到“ÿ”

Can someone help me please ? 有人能帮助我吗 ?

Thanks in advance 提前致谢

Sometimes I get this ÿ stuff when in the serial monitor I put a different baudrate than the Arduino board is using. 有时候,我得到这个ÿ的东西时,在串行监控我把不同的波特率比Arduino板使用。 May be this? 可能是这个吗? Also (and this is just a tip), you should use Serial.write(inDat) instead of Serial.println(inDat) , because println function adds '\\n' at the end. 同样(这只是一个提示),您应该使用Serial.write(inDat)而不是Serial.println(inDat) ,因为println函数在末尾添加了'\\n'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM