首页 文章

通过蓝牙将数据传输到arduino

提问于
浏览
0

我打算在arduino和移动设备之间传输数据 . 现在,我可以从移动设备中的arduino读取数据,但无法将数据发送到arduino板 . 这是我用于数据传输的代码:

Android代码:void sendData()抛出IOException {
String msg = myTextbox.getText() . toString();
msg =“\ n”;
mmOutputStream.write(msg.getBytes());
//mmOutputStream.write('A');
myLabel.setText(“Data Sent”msg.getBytes()); }
Arduino代码:SoftwareSerial蓝牙(bluetoothTx,bluetoothRx);

void loop(){
char aChar = bluetooth.read();
Serial.print(ACHAR);
}

如果有人能帮助我解决这个问题,我将不胜感激 .

2 回答

  • 0

    我有同样的问题 . 从Arduino发送数据时我添加了一个小延迟 . 这是一个例子 .

    void loop()
    {
        if (Serial.available() > 0)
        {
            char data = Serial.read();
            Serial.print(data);
        }
    
        delay(5);
    }
    
  • 0

    以前我的Tx和Rx设置为:

    int bluetoothTx = 2;  // TX-O pin of bluetooth mate, Arduino D2
    int bluetoothRx = 3;  // RX-I pin of bluetooth mate, Arduino D3
    

    我把针更改为:

    int bluetoothTx = 8;  // TX-O pin of bluetooth mate, Arduino D8
    int bluetoothRx = 10;  // RX-I pin of bluetooth mate, Arduino D10
    

    现在它的工作正常 .

相关问题