Bye Bye Moore

猫マンション建築の野望を胸に零細事業主として資本主義の荒波に漕ぎ出したアラサー男の技術メモ

RasPiのGPIOのBCM番号をみる

実際のところ

PythonのGPIOコマンドを使おうとする場合、

raspbian組み込みの以下のコマンドでピン状況をみる

$ gpio readall
 +-----+-----+---------+------+---+---Pi 3+--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT5 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT5 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 1 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 1 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 1 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 1 | 37 || 38 | 1 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 1 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3+--+---+------+---------+-----+-----+||<

全部のピンにアクセスする

readallコマンドは通常アクセスのピンをボード種類に合わせて表示します。
一方、allreadallコマンド*1では、産業用で使われるCompute Moduleの規格でアクセスできる外部ピン全てを表示できます。

$ gpio allreadall
+-----+------+-------+      +-----+------+-------+
| Pin | Mode | Value |      | Pin | Mode | Value |
+-----+------+-------+      +-----+------+-------+
|   0 | IN   | High  |      |  27 | IN   | Low   |
|   1 | IN   | High  |      |  28 | IN   | High  |
|   2 | IN   | High  |      |  29 | OUT  | Low   |
|   3 | IN   | High  |      |  30 | ALT3 | Low   |
|   4 | IN   | High  |      |  31 | ALT3 | Low   |
|   5 | IN   | High  |      |  32 | ALT3 | High  |
|   6 | IN   | High  |      |  33 | ALT3 | High  |
|   7 | IN   | High  |      |  34 | ALT3 | Low   |
|   8 | IN   | High  |      |  35 | ALT3 | High  |
|   9 | IN   | High  |      |  36 | ALT3 | High  |
|  10 | IN   | High  |      |  37 | ALT3 | High  |
|  11 | IN   | High  |      |  38 | ALT3 | High  |
|  12 | IN   | Low   |      |  39 | ALT3 | High  |
|  13 | IN   | Low   |      |  40 | ALT0 | Low   |
|  14 | ALT5 | High  |      |  41 | ALT0 | Low   |
|  15 | ALT5 | High  |      |  42 | ALT0 | Low   |
|  16 | IN   | Low   |      |  43 | ALT0 | Low   |
|  17 | IN   | Low   |      |  44 | IN   | High  |
|  18 | IN   | Low   |      |  45 | IN   | High  |
|  19 | IN   | Low   |      |  46 | IN   | High  |
|  20 | IN   | High  |      |  47 | OUT  | High  |
|  21 | IN   | High  |      |  48 | ALT0 | Low   |
|  22 | IN   | Low   |      |  49 | ALT0 | High  |
|  23 | IN   | Low   |      |  50 | ALT0 | High  |
|  24 | IN   | Low   |      |  51 | ALT0 | High  |
|  25 | IN   | Low   |      |  52 | ALT0 | High  |
|  26 | IN   | High  |      |  53 | ALT0 | High  |
+-----+------+-------+      +-----+------+-------+

"gpio: command not found"なら、wiringPiを入れ忘れてる

$ gpio readall
-bash: gpio: command not found

などと、コマンドが見つからない等々と出た場合、wiringPiが入ってません。

$ sudo apt-get install wiringpi

*1:ややこしい!