我想通过 I2C 将运行 Android 的 Raspberry Pi 与 Arduino Nano 连接。 Android 官方文档说:
Managing the slave device connection
有没有办法让 Arduino 充当主站,让带有 Android 的 Raspberry 充当从站?
在 Arduino 端,Wire 库提供了 onRequest 或 onReceive 回调,但我在 Android 端没有使用外设 I/O API 看到任何回调。
有没有任何解决方案,或者只是在 Android 端使用一个简单的循环来从 Arduino 寄存器读取,无论是否有更改。 谢谢
最佳答案
Is there any solution or just use on Android side a simple loop to read from Arduino register regardless if there is a change or not.
您可以在两者之间设置 GPIO 连接
https://developer.android.com/things/sdk/pio/gpio.html#input-state
当有数据要读取时,让 arduino“ping”AndroidThings 板。
然后 AndroidThings 板可以使用 I2C 读取此时 https://developer.android.com/things/reference/com/google/android/things/pio/I2cDevice.html#read(byte[],%20int)
(比轮询循环更好)
关于arduino - Android 作为 I2C 从设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49574190/