首页 > 解决方案 > android studio 通过 USB 与 arduino 进行串行通信

问题描述

我正在尝试通过 USB 在我的 arduino nano 和我的应用程序之间传递数据。我正在使用https://github.com/felHR85/UsbSerial/库。

经过几次尝试使用提供的示例代码后,我尝试测试我的测试代码的问题:

UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
    if (usbDevices.isEmpty()) {
       Log.d(TAG, "findSerialPortDevice() usbManager returned empty device list." );
     }

在我的清单中:

<uses-feature android:name="android.hardware.usb.host" android:required="true"/>

问题是 UsbManager 总是空的,我认为手机没有检测到 USB 设备。

我将我的 arduino 和计算机都用作 USB 设备,并尝试使用我的 pocophone、三星平板电脑和另一部三星手机。我使用了 2 根不同的电缆。

我读到问题可能出在我的设备上(即使我使用了 3 个设备)我使用了 USB 主机诊断应用程序,结果如下:

在此处输入图像描述

我第一次尝试在android中使用任何类型的通信。谢谢你。

标签: javaandroidandroid-studioarduino

解决方案


推荐阅读