如何通过 USB 从 Android 设备上传 .hex 文件到 arduino uno?

How to upload .hex file to arduino uno via USB from Android device?

想要创建 android 应用程序以通过 USB 将 .hex 文件上传到 arduino uno。 Sketch IDE 编译程序后创建.hex 文件。并可以通过USB 上传到arduino uno。那么任何人都可以告诉我如何让 android 应用程序将 .hex 文件上传到 arduno uno 。 google Play 商店中有一个名为 "Arduino Commander" 的应用程序可以使用 USB 上传。我还想知道 android 的源代码

我不明白你的意思,这就是为什么这篇文章分为两部分:

使用 arduino 的虚拟 COM 端口将二进制文件写入 EEPROM 或使用 RS-232 协议的闪存。

或者您想通过 USB 上的引导加载程序(DFU 编程)闪存一个 .hex 文件(将自己编写和编译的程序写入 arduino)。 我想你想做第一个

通常 arduino uno 的 USB 实现 USB CDC ACM class ( https://en.wikipedia.org/wiki/USB_communications_device_class ) 并且是一个 虚拟 COM 端口 。因此,您可以通过 USB 从 android 到 arduino 与 RS-232 protocol/commands 通信。

在 android 端有一个 USB 主机驱动程序 (https://github.com/mik3y/usb-serial-for-android),它使您的 android 能够像 arduino 一样枚举虚拟 COM 端口(USB CDC ACM 设备)。

在这种情况下,android 是 USB 主机,arduino 是 USB 设备。在 USB 协议中,只能 一个设备处于主机模式 所有其他设备必须处于 设备模式 然后

所以在你的android你可以在你的项目中包含usb-serial-for-andoid驱动程序然后使用RS-232命令与arduinos虚拟COM通信,示例在 https://github.com/mik3y/usb-serial-for-android 中。

在你的 arduino 上,你必须实现一个软件来理解它通过虚拟 com 端口接收的命令,请参阅 https://www.arduino.cc/en/Tutorial/SoftwareSerialExample 用于 arduino 上的 RS-232

通过这个你可以实现类似 Arduino Commander 的功能 https://www.arduino.cc/en/Main/USBSerial

您也可以在 http://arduino.stackexchange.com

询问 arduino 问题

(http://www.v-lad.org/projects/gnu.io.android/)


通过 USB 端口对 arduino 进行编程(闪烁 .hex)是可行的,因为 Arduino 芯片有一个预装的引导加载程序(http://wiki.osdev.org/Bootloader). this is called DFU (Device Firmware Update). DFU is a special USB protocol. you can follow this tutorial https://www.arduino.cc/en/Hacking/DFUProgramming8U2请注意,当你这样做时,你会覆盖/删除任何固件arduino(引导加载程序和其他一些 low-level 任务除外)并将其替换为您新开发的

没有 android 应用程序,arduino 指挥官无法做到这一点,这就是为什么我认为你不想这样做(DFU 使用 android 作为主机)

使用Physicaloid,它提供了一种将草图文件上传到arduino的简单方法。草图文件存储在应用程序的资产文件夹中。

您可以在此处查看示例:https://github.com/t2t-sonbui/ArduinoHexUploadExample 我使用usb串口库,在Android.

上重新实现串口api