Skip to main content

40-Pin GPIO Interface

The Radxa Dragon Q6A 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 Q6A supports connecting external devices to the onboard GPIO pins, including UART, SPI, I2C, I3C, I2S and more.

Function4Function3Function2Function1Function0Pin#Pin#Function0Function1Function2Function3Function4
3V3
1
2
5V
SPI6_MISOI2C6_SDAUART6_CTSGPIO_24
3
4
5V
SPI6_MOSII2C6_SCLUART6_RFRGPIO_25
5
6
GND
PRI_MI2S_MCLKGPIO_96
7
8
GPIO_22UART5_TXSPI5_SCLK
GND
9
10
GPIO_23UART5_RXSPI5_CS_0
SPI7_MOSII2C7_SCLUART7_RFRGPIO_29
11
12
GPIO_97MI2S0_SCK
I3C0_SDASPI0_MISOI2C0_SDAUART0_CTSGPIO_0
13
14
GND
I3C0_SCLSPI0_MOSII2C0_SCLUART0_RFRGPIO_1
15
16
GPIO_26UART6_TXSPI6_SCLK
3V3
17
18
GPIO_27UART6_RXSPI6_CS_0
SPI12_MOSII2C12_SCLUART12_RFRGPIO_49
19
20
GND
SPI12_MISOI2C12_SDAUART12_CTSGPIO_48
21
22
GPIO_57UART14_RFRI2C14_SCLSPI14_MOSI
SPI14_CS_3SPI12_SCLKUART12_TXGPIO_50
23
24
GPIO_51UART12_RXSPI12_CS_0
GND
25
26
GPIO_55UART13_RXSPI13_CS_0SPI12_CS_1
SPI2_MISOI2C2_SDAUART2_CTSGPIO_8
27
28
GPIO_9UART2_RFRI2C2_SCLSPI2_MOSI
SPI7_CS_0UART7_RXGPIO_31
29
30
GND
SPI7_MISOI2C7_SDAUART7_CTSGPIO_28
31
32
GPIO_30UART7_TXSPI7_SCLK
SPI14_MISOI2C14_SDAUART14_CTSGPIO_56
33
34
GND
MI2S0_WSGPIO_100
35
36
GPIO_59UART14_RXSPI14_CS_0
SPI14_SCLKUART14_TXGPIO_58
37
38
GPIO_98MI2S0_DATA0
GND
39
40
GPIO_99MI2S0_DATA1

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-q6a$
sudo apt update
sudo apt install -y python3-periphery -y

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_25 pin for outputting high/low levels and reads the GPIO_25 pin's state through the GPIO_96 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_25 (output) → maps to pin 25 of /dev/gpiochip4
# GPIO_96 (input) → maps to pin 96 of /dev/gpiochip4
OUTPUT_PIN_CHIP = "/dev/gpiochip4"
OUTPUT_PIN_NUMBER = 25 # GPIO_25 (output pin, controlled by the script)
INPUT_PIN_NUMBER = 96 # GPIO_96 (input pin, reads GPIO_25's output state)

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

try:
# Initialize GPIO_25 as OUTPUT mode
gpio_out = GPIO(OUTPUT_PIN_CHIP, OUTPUT_PIN_NUMBER, "out")
# Initialize GPIO_96 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_25): {OUTPUT_PIN_CHIP} - Pin {OUTPUT_PIN_NUMBER} (OUTPUT)")
print(f"Monitoring Pin (GPIO_96): {OUTPUT_PIN_CHIP} - Pin {INPUT_PIN_NUMBER} (INPUT)")
print("Test Behavior: GPIO_25 toggles HIGH/LOW every 1s; GPIO_96 verifies GPIO_25's state")
print("Press Ctrl+C to stop the test\n")

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

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

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

# Keep GPIO_25 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_25 (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_25 (Pin {OUTPUT_PIN_NUMBER})")
except Exception as close_err:
print(f"Failed to close GPIO_25 (Pin {OUTPUT_PIN_NUMBER}): {str(close_err)}")
# Safely close GPIO_96
if gpio_in:
try:
gpio_in.close()
print(f"Successfully closed GPIO_96 (Pin {INPUT_PIN_NUMBER})")
except Exception as close_err:
print(f"Failed to close GPIO_96 (Pin {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_25 and GPIO_96 pins using a jumper wire

  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_25 and the level read by GPIO_96.

  • 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