LoginSignup
0
0

More than 3 years have passed since last update.

初めてのRaspberry Pi Pico ㉚ CircuitpythonでI2CScanner

Last updated at Posted at 2021-03-15

 PicoにはI2Cバスが2系統ありますが、利用できるピンはいっぱいあります。つまり、いっぱいあるGPIOのうち2組が同時に使えます。
ファイル名

 ピンの組み合わせは、次のペアです。奇数がSCLで偶数ピンがSDAです。

[GP1,GP0], [GP3,GP2], [GP5,GP4], [GP7,GP6], [GP9,GP8], [GP11,GP10], [GP13,GP12],[GP15,GP14], [GP17,GP16], [GP19,GP18], [GP21,GP20], [GP27,GP26]

スキャナ

 見つけてきたスレーブ・デバイス(複数対応)のアドレスを16進で表示します。GPIOのピンは、手動で利用するピンを入力して使ってください。なお、モジュールはbusioではなくbitbangioでも同じように使えます。

from board import *
from busio import I2C

i2c = I2C(GP21, GP20)

while not i2c.try_lock():
    pass

for i in i2c.scan():
    print('addr 0x{0:x}'.format(i))

i2c.deinit()

PS.

for i in i2c.scan():
    print('addr 0x{0:x}'.format(i))

は、

print([hex(i) for i in i2c.scan()])

でも、16進表示ができます。

0
0
0

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
0
0