Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Raspberry PI 3与Android Things连接到Arduino_Android_Arduino_Communication_Android Things - Fatal编程技术网

将Raspberry PI 3与Android Things连接到Arduino

将Raspberry PI 3与Android Things连接到Arduino,android,arduino,communication,android-things,Android,Arduino,Communication,Android Things,我的问题是关于如何与Arduino通信Android of Things应用程序。我想在我的Android of Things项目上使用所有的Arduino传感器。我找到了两个源链接并尝试了,但没有得到值 我在stack上找到了这个源代码,但讨论与我的问题无关。我想要从arduino到android things RPI 3的所有值 我们如何使用java通过android框架从arduino获得价值?Pi和arduino中嵌入了各种通信协议。最简单的方法是通过UART交换数据 您的Arduin

我的问题是关于如何与Arduino通信Android of Things应用程序。我想在我的Android of Things项目上使用所有的Arduino传感器。我找到了两个源链接并尝试了,但没有得到值

我在stack上找到了这个源代码,但讨论与我的问题无关。我想要从arduino到android things RPI 3的所有值


我们如何使用java通过android框架从arduino获得价值?

Pi和arduino中嵌入了各种通信协议。最简单的方法是通过UART交换数据


您的Arduino代码可以持续传输数据,Pi可以有代码接收数据。如果您的数据不适合单个字节,您可以编写额外的自定义逻辑对其进行编码和解码。

Pi和Arduino中嵌入了多种通信协议。最简单的方法是通过UART交换数据

您的Arduino代码可以持续传输数据,Pi可以有代码接收数据。如果您的数据不适合单个字节,您可以编写额外的自定义逻辑对其进行编码和解码。

查看project。它有一个重要的部分:双向逻辑电平转换器。它有重要的组成部分:双向逻辑电平转换器。
class Arduino(uartDevice: String = "UART0"): AutoCloseable {
    private val TAG = "Arduino"
    private val uart: UartDevice by lazy {
        PeripheralManagerService().openUartDevice(uartDevice).apply {
            setBaudrate(115200)
            setDataSize(8)
            setParity(UartDevice.PARITY_NONE)
            setStopBits(1)
        }
    }

    fun read(): String {
        val maxCount = 8
        val buffer = ByteArray(maxCount)
        var output = ""
        do {
            val count = uart.read(buffer, buffer.size)
            output += buffer.toReadableString()
            if(count == 0) break
            Log.d(TAG, "Read ${buffer.toReadableString()} $count bytes from peripheral")
        } while (true)
        return output
    }

    private fun ByteArray.toReadableString() = filter { it > 0.toByte() }
            .joinToString(separator = "") { it.toChar().toString() }

    fun write(value: String) {
        val count = uart.write(value.toByteArray(), value.length)
        Log.d(TAG, "Wrote $value $count bytes to peripheral")
    }

    override fun close() {
        uart.close()
    }
}