2017-12-02 6 views
0

問題の検出方法は?私はI2Cバス上で1つのデバイスを見つけようとしています。バスは見つかりましたが、デバイスは見つかりませんでした。私は2つのメインボード、2つの異なるデバイス(AM2321とコンバータI2C-> 3線)を持っていて、それらをさまざまな組み合わせで試しました。私は間違ったことをしますが、正確には何かを理解することはできません。 Androidの物事DP 6でI2CはRaspberry Pi 3でAndroidのものとは動作しません

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

あなたが問題を検出するために、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チュートリアルを見てみましょう。

+0

ありがとうございます。非常に良いリソースが、まだ私のために動作しません。 'pio'は私のコードと同じエラーを返します。また、箱から取り出したスキャナもありません。ハードウェアに問題があるようですが、それを検出する方法はありません。ネイティブのLinuxをセットアップし、そこから試してみましょう。 – tse

+0

私は間違いなくI2Cを使用しており、正常に動作しました。他のコンポーネントで試すことはできますか?おそらくI2Cピンが壊れていますか? – shalafi

+0

"'pio'が私のコードと同じエラーを返す場合" - あなたのコードに問題はありません。問題が有線接続であるか、[shalafi](https://stackoverflow.com/users/539171/shalafi)がI2Cピンが壊れていると書いている可能性があります。 –

関連する問題