Using GPIO
Import GPIO Python Library
The development board is equipped with the GPIO Python library Hobot.GPIO. Users can import the GPIO library with the following command.
sunrise@ubuntu:~$ sudo python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
Type "help", "copyright", "credits" or "license" for more information.
>>> import Hobot.GPIO as GPIO
Get board ID: 0x504
>>> GPIO.VERSION
'0.0.2'
>>> GPIO.model
'RDK_X5'
Setting Pin Numbering Mode
The development board has 4 pin numbering modes:
- BOARD: Physical pin numbering, corresponding to the silk screen numbering on the development board.
- BCM: GPIO naming based on the Broadcom SoC.
- CVM: Use strings instead of numbers, corresponding to the signal names of the CVM/CVB connectors.
- SOC: The corresponding number is the GPIO pin number inside the chip.
This article recommends using the BOARD pin numbering mode. The pin numbering can be set as follows:
Note: The encoding can only be set once at a time. If you want to reset it, you need to call GPIO.cleanup() and then set it again.
GPIO.setmode(GPIO.BOARD)
# or
GPIO.setmode(GPIO.BCM)
# or
GPIO.setmode(GPIO.CVM)
# or
GPIO.setmode(GPIO.SOC)
To check the current pin numbering mode:
mode = GPIO.getmode()
The program will output one of the results BOARD, BCM, CVM, SOC, or None.