簡體   English   中英

I2C在帶有Android Things的Raspberry Pi 3上不起作用

[英]I2C doesn't work on Raspberry Pi 3 with Android Things

如何發現問題? 我正在嘗試在I2C總線上找到一台設備。 它找到了總線,但是沒有找到任何設備。 我有兩個主板,兩個不同的設備(AM2321和轉換器I2C-> 3wire),並嘗試了不同的組合。 我做錯了事,但無法理解,究竟是什么。

    val bus = manager.i2cBusList.first() // in my device one and only one bus now
    Log.d("happy", "bus: $bus")

    val devices = (0..127).filter { address ->
        manager.openI2cDevice(bus, address).use { device ->
            try {
                device.write(ByteArray(1), 1)
                true
            } catch (e: IOException) {
                false
            }
        }
    }

    if (devices.isEmpty()) {
        Log.d("happy", "no devices")
    } else {
        devices.forEach { address ->
            Log.d("happy", "device $address")
        }
    }

借助Android Things DP 6,您可以使用PIO CLI工具檢測問題:

 pio i2c name address subcommand [arg] name is the name of a valid I2C bus. address is the address of an I2C device. subcommand can be one of the following: Subcommand Description read-raw size Read size bytes from device. read-reg-byte reg Read a byte from reg. read-reg-word reg Read a word (2 bytes) from reg. read-reg-buffer reg size Read size bytes from reg. write-raw val [val ...] Write val to device. write-reg-byte reg val Write byte val to reg. write-reg-word reg val Write word val to reg. write-reg-buffer reg val [val ...] Write val to reg. 

 $ pio i2c I2C1 0x10 write-reg-byte 0x20 0x40 $ pio i2c I2C1 0x12 read-reg-byte 0x24 0x7F 

也看看這個那個教程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM