I2C并不适用于使用Android Things的Raspberry Pi 3

时间:2017-12-02 14:00:55

标签: android raspberry-pi3 i2c 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")
        }
    }

1 个答案:

答案 0 :(得分:1)

使用Android Things DP 6,您可以使用PIO CLI Tool来检测问题:

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

另请参阅thisthat教程。