【问题标题】:Arduino HC-05 writes to serial monitor but not Bluetooth (Android)Arduino HC-05 写入串行监视器但不写入蓝牙 (Android)
【发布时间】:2023-03-30 08:25:01
【问题描述】:

问候 Stack Overflow 社区,

我正在编写一个从 HC05 蓝牙模块读取一些数据的 Android 应用程序。

我只是想读取一个字节,但它只是挂在那里几分钟,然后就崩溃了。也许它是一个硬件问题,但也许我的代码中有一些我没有看到的错误。如果有人知道为什么我无法从这个模块中阅读,我将不胜感激。

谢谢!

for (BluetoothDevice iterator : bondedDevices) {
    if (iterator.getName().equals("HC-05")) {
        BluetoothDevice device = iterator;

        try { btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);} catch (IOException ex) {}
        try {btSocket.connect();} catch (IOException ex) {}

        if (btSocket.isConnected()) {
            Toast.makeText(getApplicationContext(), "Connected to HC05", Toast.LENGTH_SHORT).show();

            //Write 'r' to arduino to tell it to send data.
            try {
                outStream = btSocket.getOutputStream();
                outStream.write('r');
            } catch (IOException ex) {}

            int byteCount = 1;
            byte[] rawBytes = new byte[byteCount];

            try {
                inputStream= btSocket.getInputStream();
                int a = inputStream.read(rawBytes, 0, 1);
            }

【问题讨论】:

    标签: java android bluetooth arduino


    【解决方案1】:

    您是否尝试过使用安卓的蓝牙终端应用程序?通过这种方式,您可以确定是硬件问题还是软件问题。

    你可以试试这个应用:

    https://play.google.com/store/apps/details?id=Qwerty.BluetoothTerminal

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-10
      • 1970-01-01
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      相关资源
      最近更新 更多