1
0

Raspberry PIのGPIO PIN情報確認

Last updated at Posted at 2023-12-08

概要

今日はRPIのGPIO状態を確認するパッケージをインストールして簡単に
GPIO状態を確認してみましょう。

パッケージインストール

次のコマンドを使用してWiringPiパッケージをダウンロードします。
※gpio readall コマンドを実行するためにインストールするパッケージです。

wget https://project-downloads.drogon.net/wiringpi-latest.deb
pi@RPI3B:~ $ wget https://project-downloads.drogon.net/wiringpi-latest.deb
--2023-12-05 21:36:27--  https://project-downloads.drogon.net/wiringpi-latest.deb
Resolving project-downloads.drogon.net (project-downloads.drogon.net)... 188.246.205.22
Connecting to project-downloads.drogon.net (project-downloads.drogon.net)|188.246.205.22|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 52260 (51K) [application/x-debian-package]
Saving to: ‘wiringpi-latest.deb’

wiringpi-latest.deb 100%[===================>]  51.04K   102KB/s    in 0.5s    

2023-12-05 21:36:29 (102 KB/s) - ‘wiringpi-latest.deb’ saved [52260/52260]

ダウンロードしたパッケージを次のコマンドでインストールします。

pi@RPI3B:~ $ sudo dpkg -i wiringpi-latest.deb
Selecting previously unselected package wiringpi.
(Reading database ... 177638 files and directories currently installed.)
Preparing to unpack wiringpi-latest.deb ...
Unpacking wiringpi (2.52) ...
Setting up wiringpi (2.52) ...
Processing triggers for man-db (2.9.4-2) ...
pi@RPI3B:~ $ 

次のコマンドで現在のGPIO状態を確認できます。

pi@RPI3B:~ $ gpio readall
 +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 0 | IN   | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | IN   | 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 | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | 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 | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+
pi@RPI3B:~ $ 

以下は実際のボード上の表記です。
各ピンの情報は以下の通りです。

wPi(WiringPi)とBCM(Python)の情報は、プログラム内のポートを制御するためのピン番号に対応しています。
そしてVに表示されている数字1と0については、対応するGPIOピンの状態を示します。

5V出力が2個、3.3V出力が2個、GNDが8個で合計12個が電源用なので使用できないです。
GPIO 0とGPIO 1のID_SDピンはID_SCピンが予約されており、使用できません。
GPIO 2、GPIO 3番ピンがI2C機能として使用可能です。
GPIO 14、GPIO 15番ピンはUART rx、txピンとして使用可能です。
GPIO 10、9、11、8はSPIインターフェースに使用できます。

image.png

RPI独自のコマンド

次のコマンドを実行すると、RPIでピン情報を確認できます。

pinout

コマンドを実行した結果は次のとおりです。

pi@RPI3B:~ $ pinout
,--------------------------------.
| oooooooooooooooooooo J8     +====
| 1ooooooooooooooooooo  PoE   | USB
|  Wi                    1o   +====
|  Fi  Pi Model 3B+ V1.3 oo      |
|        ,----.               +====
| |D|    |SoC |               | USB
| |S|    |    |               +====
| |I|    `----'                  |
|                   |C|     +======
|                   |S|     |   Net
| pwr        |HDMI| |I||A|  +======
`-| |--------|    |----|V|-------'

Revision           : a020d3
SoC                : BCM2837
RAM                : 1GB
Storage            : MicroSD
USB ports          : 4 (of which 0 USB3)
Ethernet ports     : 1 (300Mbps max. speed)
Wi-fi              : True
Bluetooth          : True
Camera ports (CSI) : 1
Display ports (DSI): 1

J8:
   3V3  (1) (2)  5V    
 GPIO2  (3) (4)  5V    
 GPIO3  (5) (6)  GND   
 GPIO4  (7) (8)  GPIO14
   GND  (9) (10) GPIO15
GPIO17 (11) (12) GPIO18
GPIO27 (13) (14) GND   
GPIO22 (15) (16) GPIO23
   3V3 (17) (18) GPIO24
GPIO10 (19) (20) GND   
 GPIO9 (21) (22) GPIO25
GPIO11 (23) (24) GPIO8 
   GND (25) (26) GPIO7 
 GPIO0 (27) (28) GPIO1 
 GPIO5 (29) (30) GND   
 GPIO6 (31) (32) GPIO12
GPIO13 (33) (34) GND   
GPIO19 (35) (36) GPIO16
GPIO26 (37) (38) GPIO20
   GND (39) (40) GPIO21

POE:
TR01 (1) (2) TR00
TR03 (3) (4) TR02

For further information, please refer to https://pinout.xyz/
pi@RPI3B:~ $ 

終わりに

今回はラズベリーパイのピン情報を確認するコマンドを調べました。
電子回路を接続して実行する場合は、現在のピン情報の状態を確認することで
正常な動作が行われているかどうかを確認できます。
たとえば、LEDにオンオフまたはスイッチを使用したオンオフを介したピン情報の状態変化を知ることができます。
今日はここまで! ありがとうございます。

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