LoginSignup
9
6

More than 5 years have passed since last update.

RaspbianでPython 3からpython-smbusを使う

Last updated at Posted at 2015-04-14

python-smbusを使用すると、PythonコードからI2Cバスにアクセスできます。しかし、2015/04/15時点のRaspbianパッケージのリポジトリには、Python 2に対応したpython-smbusしかありません。また、python-smbusを含むi2c-toolsの最新版(3.1.1)も、Python 3に対応していません。しかし、開発版をダウンロードしてビルドすることで、Python 3からpython-smbusを使用できます。なお、開発版はPython 3に対応していることから、i2c-tools 3.1.1の次バージョンではPython 3に対応するものと思います。

方法は下記の通りです。なお、「$」はプロンプトを表します。

  1. ビルドに必要なライブラリのダウンロード
  2. i2c-toolsの開発版のダウンロード
  3. i2c-toolsのビルド、インストール
  4. python-smbusのインストール

ビルドに必要なライブラリのダウンロード

下記の通りlibi2c-devをインストールします。

$ sudo apt-get install libi2c-dev

i2c-toolsの開発版のダウンロード

Subversionがインストール済みであれば、下記の通りi2c-toolsの開発版をダウンロードします。

$ svn export http://lm-sensors.org/svn/i2c-tools/trunk i2c-tools

Subversionが未インストールの場合は、下記の通りインストールします。

$ sudo apt-get install subversion

i2c-toolsのビルド、インストール

python-smbusをインストールする前に、i2c-toolsのビルドとインストールを行います。

$ cd i2c-tools
$ sudo make install

python-smbusのインストール

i2c-toolsのインストールを終えたら、Python 3にpython-smbusをインストールします。

$ cd py-smbus
$ sudo python3 setup.py install
9
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6