Skip to main content

40-Pin GPIO Interface

The Radxa Dragon Q8B features an onboard 40-pin GPIO (General-Purpose Input/Output) interface, providing highly flexible interface support for hardware expansion.

Users can connect various sensors, actuators, communication modules, displays, and other embedded peripherals via the 40-pin GPIO interface, enabling rapid prototyping and functional verification in fields such as the Internet of Things (IoT), robotics control, and industrial automation.

danger

When using the 40-pin GPIO interface, pay attention to the wiring of the pins and peripherals, and ensure that the pins are connected correctly. Improper operation may result in damage to the device hardware.

GPIO Functions

Dragon Q8B supports connecting external devices to the onboard GPIO pins and provides multiple multiplexed functions, including UART, SPI, and I2C.

Function4Function3Function2Function1Function0Pin#Pin#Function0Function1Function2Function3
3V3
1
2
5V
SPI9_MISOUART9_CTSI2C9_SDAGPIO_41
3
4
5V
SPI9_MOSIUART9_RFRI2C9_SCLGPIO_42
5
6
GND
SPI4_CS_3GPIO_175
7
8
GPIO_63UART17_TX
GND
9
10
GPIO_64UART17_RX
SPI4_CS_1I2C5_SDAGPIO_111
11
12
GPIO_174UART4_RXSPI4_CS_0
HS-UART18_CTSSPI18_MISOUART18_CTSI2C18_SDAGPIO_66
13
14
GND
HS-UART18_RFRSPI18_MOSIUART18_RFRI2C18_SCLGPIO_67
15
16
GPIO_68UART18_TXSPI18_SCKLHS-UART18_TX
3.3V
17
18
GPIO_110
SPI20_MOSIUART20_RFRI2C20_SCLGPIO_88
19
20
GND
SPI20_MISOUART20_CTSI2C20_SDAGPIO_87
21
22
GPIO_92SPI20_CS_2
SPI20_SCKLUART20_TXGPIO_89
23
24
GPIO_90UART20_RXSPI20_CS_0
GND
25
26
GPIO_91SPI20_CS_1
SPI9_SCKLUART9_TXI2C8_SDAGPIO_43
27
28
GPIO_44I2C8_SCLUART9_RXSPI9_CS_0
SPI6_CS_0UART6_RXGPIO_157
29
30
GND
SPI6_SCKLUART6_TXGPIO_156
31
32
GPIO_114CCI_I2C_SCL0GCC_GP2_CLK_MIRA
GCC_GP3_CLK_MRIACCI_I2C_SDA1GPIO_115
33
34
GND
SPI4_MISOUART4_CTSI2C4_SDAGPIO_171
35
36
GPIO_112I2C5_SCLSPI4_CS_2
HS-UART18_RXSPI18_CS_0UART18_RXGPIO_69
37
38
GPIO_172I2C4_SCLUART4_RFRSPI4_MOSI
GND
39
40
GPIO_173UART4_TXSPI4_SCKL

GPIO Usage

This section demonstrates common GPIO usage through the onboard 40-pin GPIO interface.

Install Python Library

Use the python-periphery library to control GPIO pins.

radxa@dragon-q8b$
sudo apt update
sudo apt install -y python3-periphery

GPIO Output/Input

Hardware Requirements

  • Board
  • Dupont wire

Software Requirements

  • python-periphery library

Test Code

The following code uses the python-periphery library to control the GPIO_42 pin for outputting high/low levels and reads the GPIO_42 pin's state through the GPIO_175 pin.

gpio_output_input.py
from periphery import GPIO
import time

def gpio_output_with_feedback():
# GPIO Configuration (modify pin numbers based on your hardware)
# GPIO_42 (output) → maps to line 42 of /dev/gpiochip4
# GPIO_175 (input) → maps to line 175 of /dev/gpiochip4
OUTPUT_PIN_CHIP = "/dev/gpiochip4"
OUTPUT_PIN_NUMBER = 42 # GPIO_42 (output pin, controlled by the script)
INPUT_PIN_NUMBER = 175 # GPIO_175 (input pin, reads GPIO_42's output state)

# Initialize GPIO objects as None first (for safe release later)
gpio_out = None
gpio_in = None

try:
# Initialize GPIO_42 as OUTPUT mode
gpio_out = GPIO(OUTPUT_PIN_CHIP, OUTPUT_PIN_NUMBER, "out")
# Initialize GPIO_175 as INPUT mode
gpio_in = GPIO(OUTPUT_PIN_CHIP, INPUT_PIN_NUMBER, "in")

# Print test initialization info
print("=== GPIO Output-Input Feedback Test Started ===")
print(f"Controlled Pin (GPIO_42): {OUTPUT_PIN_CHIP} - Line {OUTPUT_PIN_NUMBER} (OUTPUT)")
print(f"Monitoring Pin (GPIO_175): {OUTPUT_PIN_CHIP} - Line {INPUT_PIN_NUMBER} (INPUT)")
print("Test Behavior: GPIO_42 toggles HIGH/LOW every 1s; GPIO_175 verifies GPIO_42's state")
print("Press Ctrl+C to stop the test\n")

# Main loop: Toggle GPIO_42 and read GPIO_175 feedback
while True:
# 1. Set GPIO_42 to HIGH level
gpio_out.write(True)
time.sleep(0.1) # Short delay for signal stabilization (avoid read lag)
gpio175_reading = gpio_in.read()
print(f"GPIO_42 Output: HIGH (True) | GPIO_175 Reading: {gpio175_reading}")

# Keep GPIO_42 HIGH for 1 second
time.sleep(1)

# 2. Set GPIO_42 to LOW level
gpio_out.write(False)
time.sleep(0.1) # Short delay for signal stabilization
gpio175_reading = gpio_in.read()
print(f"GPIO_42 Output: LOW (False) | GPIO_175 Reading: {gpio175_reading}")

# Keep GPIO_42 LOW for 1 second
time.sleep(1)

# Handle user-initiated exit (Ctrl+C)
except KeyboardInterrupt:
print("\n\nTest stopped by user (Ctrl+C)")
# Handle other unexpected errors (e.g., GPIO access failure)
except Exception as e:
print(f"\nError during test: {str(e)}")
# Ensure GPIO resources are released even if an error occurs
finally:
print("\nReleasing GPIO resources...")
# Safely close GPIO_42 (set to LOW first to avoid residual high level)
if gpio_out:
try:
gpio_out.write(False)
gpio_out.close()
print(f"Successfully closed GPIO_42 (Line {OUTPUT_PIN_NUMBER})")
except Exception as close_err:
print(f"Failed to close GPIO_42 (Line {OUTPUT_PIN_NUMBER}): {str(close_err)}")
# Safely close GPIO_175
if gpio_in:
try:
gpio_in.close()
print(f"Successfully closed GPIO_175 (Line {INPUT_PIN_NUMBER})")
except Exception as close_err:
print(f"Failed to close GPIO_175 (Line {INPUT_PIN_NUMBER}): {str(close_err)}")
print("Resource release complete.")

# Run the test when the script is executed directly
if __name__ == "__main__":
gpio_output_with_feedback()

Test Steps

  1. Short-circuit the GPIO_42 and GPIO_175 pins using a Dupont wire (these are pins 5 and 7 of the 40-pin header, respectively)

  2. Save the code as gpio_output_input.py

  3. Run the test code using the command: sudo python3 gpio_output_input.py

Expected Results

The terminal will display the output level of GPIO_42 and the level read by GPIO_175.

  • False represents a LOW level
  • True represents a HIGH level

    You need to be logged into GitHub to post a comment. If you are already logged in, please ignore this message.

    Radxa-docs © 2026 by Radxa Computer (Shenzhen) Co.,Ltd. is licensed under CC BY 4.0