40-Pin Expansion Header¶
Copyright © Quectel Wireless Solutions Co., Ltd. 2026. All rights reserved.
The Quectel Pi H1 smart controller board provides a standard 40Pin GPIO expansion header that supports various peripheral interfaces, including GPIO, I2C, SPI, UART, and PWM. The following sections describe how to test these interfaces.
Pin Definition¶
Function4 |
Function3 |
Function2 |
Function1 |
Default Function |
H1 GPIO |
40Pin |
40Pin |
H1 GPIO |
Default Function |
Function1 |
Function2 |
Function3 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
VCC 3V3 |
1 |
2 |
VCC 5V |
|||||||||
I3C11_SDA |
I2C11_SDA |
NFC_I2C_SDA |
GPIO_36 (I2C9_SDA) |
3 |
4 |
VCC 5V |
||||||
I3C11_SCL |
I2C11_SCL |
NFC_I2C_SCL |
GPIO_37 (I2C9_SCL) |
5 |
6 |
GND |
||||||
CAM2_RST |
GPIO_77 |
7 |
8 |
GPIO_50 (UART12_TX) |
UART_TXD |
SPI14_CLK |
UART14_TXD |
|||||
GND |
9 |
10 |
GPIO_51 (UART12_RX) |
UART_RXD |
SPI14_CS0 |
UART14_RXD |
||||||
I2C04_SDA |
UART04_CTS |
SPI04_MISO |
GPIO16 |
GPIO_16 |
11 |
12 |
GPIO_101 |
HALL_INT |
MI2S2_SCLK |
|||
I2C04_SCL |
UART04_RTS |
SPI04_MOSI |
GPIO17 |
GPIO_17 |
13 |
14 |
GND |
|||||
UART04_TXD |
SPI04_CLK |
GPIO18 |
GPIO_18 |
15 |
16 |
GPIO_32 |
GPIO_32 |
SPI10_MISO |
UART10_CTS |
I2C10_SDA |
||
VCC 3V3 |
17 |
18 |
GPIO_33 |
GPIO_33 |
SPI10_MOSI |
UART10_RTS |
I2C10_SCL |
|||||
I2C12_SCL |
UART12_RTS |
SPI12_MOSI |
NFC_INT |
GPIO_41(SPI10_MOSI) |
19 |
20 |
GND |
|||||
I2C12_SDA |
UART12_CTS |
SPI12_MISO |
NFC_DWL_REQ |
GPIO_40(SPI10_MISO) |
21 |
22 |
GPIO_19 |
GPIO19 |
SPI04_CS0 |
UART04_RXD |
||
UART12_TXD |
SPI12_CLK |
GPIO_42 |
GPIO_42(SPI10_SCLK) |
23 |
24 |
GPIO_43(SPI10_CE0) |
GPIO_43 |
SPI12_CS0 |
UART12_RXD |
|||
GND |
25 |
26 |
GPIO_80(SPI10_CE1) |
LCD_TE |
||||||||
I2C15_SDA |
TP_I2C_SDA |
GPIO_52 (I2C13_SDA) |
27 |
28 |
GPIO_53 (I2C13_SCL) |
TP_I2C_SCL |
I2C15_SCL |
|||||
I2C14_SCL |
UART14_RTS |
SPI14_MOSI |
UART_RTS |
GPIO_49 |
29 |
30 |
GND |
|||||
I2C14_SDA |
UART14_CTS |
SPI14_MISO |
UART_CTS |
GPIO_48 |
31 |
32 |
GPIO_76 |
40Pin618:GPIO76 |
||||
PWM2 |
GPIO_78 |
33 |
34 |
GND |
||||||||
MI2S2_WS |
ACCEL_INT |
GPIO_103 |
35 |
36 |
GPIO_34 |
GPIO_34 |
SPI10_CLK |
UART10_TXD |
||||
UART10_RXD |
SPI10_CS0 |
GPIO_35 |
GPIO_35 |
37 |
38 |
GPIO_104 |
MAG_INT |
MI2S2_DATA1 |
||||
GND |
39 |
40 |
GPIO_102 |
GYRO_INT |
MI2S2_DATA0 |
|||||||
Interface Configuration¶
The configuration file for some low-speed interfaces (I2C9/SPI10/UART12_2W/I2C13/SPI14) on the 40Pin header is located at /etc/qpi-config/qpi-config.ini.
Configuration Steps:
Modify the
qpi-config.iniconfiguration fileApply the configuration
qpi-config 40Pin set
Restart the system for the configuration to take effect
GPIO Test¶
Hardware Connection¶
Connection Method 1: Measure Voltage with a Multimeter
Connect pin3 (GPIO_36) of the 40Pin header to the positive probe of the multimeter and pin6 (GND) to the negative probe. The multimeter measures the voltage output by the pin to verify that the GPIO works correctly.
Connection Method 2: Use the GPIO Expansion Board Indicator LEDs
You can also plug a Raspberry Pi 4B/3B GPIO expansion board onto the 40Pin expansion header to test GPIO high and low levels. The expansion board breaks out each GPIO pin with a corresponding indicator LED. Configure the GPIO pin under test as an output and connect it to the expansion board: the LED lights up when the GPIO outputs a high level and turns off when it outputs a low level, so you can directly observe whether the GPIO level changes as expected.
For more information about this expansion board, refer to the GPIO terminal expansion board entry in the Supported Accessories chapter (see Supported accessories).
Test Method¶
GPIO High/Low Level Test Method: Using Pin13 (GPIO_17) as an example, enter adb shell and use the gpiod commands to test the GPIO.
adb shell
# List GPIO controllers
gpiodetect
# Check the status of the specified GPIO
gpioinfo -c gpiochip4 17
# Read the current GPIO level
gpioget -c gpiochip4 17
# Drive high for 10 seconds
gpioset -c gpiochip4 -t 10s,0 17=1
# Drive low for 10 seconds
gpioset -c gpiochip4 -t 10s,0 17=0
# Keep high (the command stays resident; press Ctrl+C to exit)
gpioset -c gpiochip4 17=1
# Keep low (the command stays resident; press Ctrl+C to exit)
gpioset -c gpiochip4 17=0
GPIO Interrupt Test Method: Connect the GPIO under test to a button or an external signal source so that the pin level changes. Use gpiomon to monitor rising-edge and falling-edge events on the GPIO. Pin13 (GPIO_17) is again used as the example here.
# Read the current level of GPIO_17
gpioget -c gpiochip4 17
# Monitor rising-edge and falling-edge events on GPIO_17 and exit after 5 events
gpiomon -n 5 -e rising -c gpiochip4 17
gpiomon -n 5 -e falling -c gpiochip4 17
Note: The pins corresponding to the following multiplexed functions can be released with qpi-config by disabling the corresponding multiplexed functions, so they can be used as general-purpose GPIOs.
Pin3/5:
i2c9Pin8/10:
uart12Pin19/21/23/24/26:
spi10Pin27/28:
i2c13pin29 / GPIO_49 → occupied by the PWRKEY of the 5G module on PCIe1
I2C Test¶
Calling the Device Node¶
Use the I2C peripheral to directly access the corresponding Linux device node. On the 40Pin header, Pin3/5 corresponds to i2c-9. Pin27/28 corresponds to i2c-13.
# ls /dev/i2c*
/dev/i2c-0 /dev/i2c-13 /dev/i2c-17 /dev/i2c-9
/dev/i2c-1 /dev/i2c-16 /dev/i2c-3
Environment Sensor HAT Test:¶
The test code uses the reference source demo-40Pin-HAT. It uses the adapted H1_Environment-Sensor-HAT.sh
Pin3 and Pin5 of the 40Pin header are the I2C data and clock pins by default. To test the I2C interface, an external I2C device is required. This test uses the Environment Sensor HAT, whose corresponding device node is /dev/i2c-9, connected through the 40Pin header.
Hardware Connection Diagram:
Wiring Instructions: The HAT is simply plugged directly onto the 40Pin socket. All five sensors are connected to the I2C bus on Pin3 / Pin5, corresponding to the device node /dev/i2c-9. When the sensor board is connected directly to the 40Pin header, Pin27 / Pin28 are not supported. The board's 40Pin connector routes I2C only to Pin3 / Pin5, not to Pin27 / Pin28. To use the I2C bus on Pin27 / Pin28, connect them with jumper wires.
|
|
|
|---|---|---|
SDA |
Pin3 SDA) |
Pin27 (SDA) |
SCL |
Pin5 (SCL) |
Pin28 (SCL) |
VCC |
Pin1 |
VCC |
GND |
Pin6 |
GND |
Test Steps:
Copy the demo-40Pin-HAT project to the H1, enter the project root directory, and install the offline dependencies once (shared by all HATs; skip if already installed):
cd <demo-40Pin-HAT directory>
chmod +x install_deps.sh
sudo ./install_deps.sh
Change to the Environment-Sensor-HAT directory and run the H1 one-click script:
cd Environment-Sensor-HAT
chmod +x H1_Environment-Sensor-HAT.sh
sudo ./H1_Environment-Sensor-HAT.sh
Test Result: The script checks dependencies and the toolchain, automatically detects the I2C bus of the HAT, compiles the C example, and runs a 10-second self-test that prints the readings of each sensor.
Sensor |
Measured Result |
|---|---|
BME280 (pressure / temperature / humidity) |
1010.8 hPa / 35.9 °C / 31.6 % |
TSL2591 (ambient light) |
184 Lux |
LTR390 (UV) |
0 |
SGP40 (raw VOC value) |
29614 |
ICM20948 (9-axis IMU) |
Initialization OK, attitude data OK |
Notes:
An indoor UVS reading close to 0 is normal; take the board to a window or outdoors for a clear reading.
If an individual sensor does not work, try connecting it with jumper wires; the issue may be power supply when the HAT is plugged in directly.
SPI Test¶
Calling the Device Node¶
Use the SPI peripheral to directly access the corresponding Linux device node. On the 40Pin header, Pin19/21/23/24/26 are configured for the SPI function by default and provide two chip-select signals. The device nodes are spidev10.0 and spidev10.1. They correspond to Pin24 CE0 and Pin26 CE1.
# ls /dev/spi*
/dev/spidev10.0 /dev/spidev10.1
2.23inch-OLED-HAT Test:¶
The test code uses the reference source demo-40Pin-HAT. It uses the adapted H1_2.23inch-OLED-HAT.sh
Wiring Instructions: To test the SPI interface, an external SPI device is required. This test uses the 2.23inch-OLED-HAT connected with jumper wires. It uses Pin19 DIN, Pin23 CLK, Pin24/Pin26 CE0/CE1, Pin18 DC, Pin22 RST, and 5V and GND on Pin2 / Pin4. The corresponding SPI node is /dev/spidev0.0, DC = GPIO134, RST = GPIO76.
OLED Pin |
Should Connect To |
H1 Physical Pin |
Remarks |
|---|---|---|---|
VCC |
5V power |
Pin1 or Pin17 |
5V |
GND |
Ground |
Pin6/9/14 or any other GND |
Common ground |
DIN/MOSI |
SPI data |
Pin19 |
SPI_MOSI |
CLK/SCK |
SPI clock |
Pin23 |
SPI_CLK |
CS |
Chip select |
Pin24/Pin26 |
CS0/CS1 |
D/C |
Data/Command |
Pin18 |
GPIO19 |
RES/RST |
Reset |
Pin22 |
GPIO33 |
Test Steps:
Copy the demo-40Pin-HAT project to the H1, enter the project root directory, and install the offline dependencies once (shared by all HATs; skip if already installed):
cd <demo-40Pin-HAT directory>
chmod +x install_deps.sh
sudo ./install_deps.sh
Change to the 2.23inch-OLED-HAT directory and run the H1 one-click script:
cd 2.23inch-OLED-HAT
chmod +x H1_2.23inch-OLED-HAT.sh
sudo ./H1_2.23inch-OLED-HAT.sh
The script checks dependencies and the toolchain, detects the SPI device and the DC/RST pins, compiles the C example, and runs the self-test. If both chip-select nodes exist, the script prompts you to select one; press Enter to use CE0 by default.
Test Result: the screen displays Welcome to use, Waveshare Electronic, 2.23inch OLED, 128x32 Pixels, and scrolling is enabled.
Notes:
On H1, the 2.23inch-OLED-HAT is hardware-incompatible when plugged directly onto the 40Pin header, so jumper wires are required
UART Test¶
On the 40Pin header, Pin8 and Pin10 are configured for the UART function by default. Use the following command to list all serial devices in the system:
ls /dev/tty*
TTL Serial Test:¶
Hardware connection: connect Pin8 (TX) to the TTL (RX) and Pin10 (RX) to the TTL (TX), and connect Pin6 (GND) to the TTL (GND).
/dev/ttyHS2 40Pin UART to TTL communication
Enter the board with adb shell, open a COM port in any serial terminal tool, switch the input method to English, and type any characters; they should be echoed character by character immediately.
# Text/debug mode (with echo; use this for manual interaction)
stty -F /dev/ttyHS2 115200 sane
# Receive (press Ctrl+C to exit)
cat /dev/ttyHS2
Send characters from the board to the serial window, and the corresponding characters appear in the window.
# Send
echo hello > /dev/ttyHS2
UART Loopback Test¶
The test code uses the reference source demo-40Pin-HAT under the 40Pin-UART directory; select the script for your board and run the loopback test.
Wiring Instructions: Short Pin8 (TX) and Pin10 (RX) of the 40Pin header together with a jumper wire.
Test Steps:
Copy
H1_uart-loopback.shto the H1 and run the test script.
chmod +x H1_uart-loopback.sh
./H1_uart-loopback.sh
Test Result: All seven baud rates passed the loopback test.
device : /dev/ttyHS2
expect : Pin8 (TXD) shorted to Pin10 (RXD)
data : a55a00ff55aa01fe4c4f4f50a55a00ff55aa01fe4c4f4f50a55a00ff55aa01fe
case result
----------------------------------
9600 baud PASS
38400 baud PASS
115200 baud PASS
230400 baud PASS
460800 baud PASS
921600 baud PASS
1500000 baud PASS
RESULT : PASS - all 7 cases matched
PWM Test¶
On the 40Pin header, Pin33 is configured for the PWM function by default. This test uses a Waveshare 40Pin PWM speed-controlled fan as the test device.
Hardware Connection¶
PWM Fan Wiring Definition:
40Pin |
Function |
Wire colour |
40Pin Connection |
|---|---|---|---|
1 |
+5V |
Red |
40Pin2 or 40Pin4 (5V) |
2 |
PWM |
Blue |
40Pin33 (GPIO_78) |
3 |
GND |
Black |
40Pin6/9/14/20/25/30/34/39 (any GND) |
4 |
Tach |
Yellow |
40Pin32 (GPIO_76) |
Connection Diagram:
Notes
Tach pin is used to read the fan speed and is optional
If you do not need speed readings, the Tach pin can be left unconnected
Control via C Code¶
Create a pwm.c file with the following content:
#include <stdio.h>
#include <lgpio.h>
int main(int argc, char **argv)
{
int h;
int gpio = 78;
float pwmFrequency = 1000;
float pwmDutyCycle = 50;
h = lgGpiochipOpen(4); // Open the /dev/gpiochip4 device
if (h < 0) {
printf("ERROR: %s (%d)\n", lguErrorText(h), h);
return 1;
}
int e = lgGpioClaimOutput(h, 0, gpio, 0);
if (e < 0) {
printf("ERROR: %s (%d)\n", lguErrorText(e), e);
return 1;
}
e = lgTxPwm(h, gpio, pwmFrequency, pwmDutyCycle, 0, 0);
if (e < 0) {
printf("ERROR: %s (%d)\n", lguErrorText(e), e);
return 1;
}
lguSleep(5);
lgGpioFree(h, gpio);
lgGpiochipClose(h);
return 0;
}
Compile:
gcc pwm.c -o pwm -llgpio
Run:
sudo ./pwm
The fan runs at medium speed. Adjust the pwmDutyCycle value in the code (range 0-100) to change the fan speed.