Up i2c-tools 作成: 2021-04-04
更新: 2021-04-04


  • Raspberry Pi OS では,i2c-tools, python-smbus がはじめからインストールされている:
      $ dpkg -l | grep i2c-tools ii i2c-tools 4.1-1 armhf heterogeneous set of I2C tools for Linux $ dpkg -l | grep python-smbus ii python-smbus:armhf 4.1-1 armhf Python bindings for Linux SMBus access through i2c-dev

  • i2c-tools の内容
      i2cget
      i2cset
      i2cdetect
      i2ctransfer
      i2cdump


  • i2c-tool は,/dev/i2c-1 にアクセスする。
    /dev/i2c-1 のアクセス権限は,root と i2cグループ。
    i2c グループには pi が含まれている。
    よって,i2c-tool コマンドは sudo をつけなくてよい。


    $ i2cdetect -l
      i2c-1 i2c bcm2835 (i2c@7e804000) I2C adapter

    $ i2cdetect -y 1
      0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- 08 -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
    (「29」は,distance sensor のケーブルを GoPiGo の I2Cコネクタに挿していることによる)

    $ i2cdetect -F 1
      Functionalities implemented by /dev/i2c-1: I2C yes SMBus Quick Command yes SMBus Send Byte yes SMBus Receive Byte yes SMBus Write Byte yes SMBus Read Byte yes SMBus Write Word yes SMBus Read Word yes SMBus Process Call yes SMBus Block Write yes SMBus Block Read no SMBus Block Process Call no SMBus PEC yes I2C Block Write yes I2C Block Read yes