First hardware project

Copyright © Quectel Wireless Solutions Co., Ltd. 2026. All rights reserved.


This guide walks you through two introductory hardware tutorials using the Quectel Pi H1 development kit: capturing photos with an IMX219 camera and handling onboard button events.

Capture your first photo with the IMX219 camera

If you do not have an IMX219 camera module, you can skip this section.

Install the camera

  1. Always disconnect power from the Quectel Pi H1 before attaching or removing ribbon cables.

  2. Find the MIPI CSI ribbon connector labeled CAMERA1 or CAMERA2 on the board (the following examples use CAMERA1).

  3. Gently lift the black locking latch, then insert the IMX219 camera ribbon cable with the metal contacts facing down (toward the top surface of the board). Once fully seated, press the latch back down to lock it in place. (Caution: Never insert the cable backward or misaligned at an angle. Doing so may cause an electrical short and damage the board upon boot.)

  4. Verify that the ribbon cable is securely seated and straight, then reconnect power and boot the board.

../../_images/image_O9uXblA8now8ewxMgBXcmpeuncb.webp

Capture a photo with the camera

Configure the environment

Before running the photo capture command, set the plugin path (you must set it again each time you open a new terminal window):

export GST_PLUGIN_PATH=/usr/lib/gstreamer-1.0:$GST_PLUGIN_PATH

Capture a photo

Run the following command to capture a photo and save them as JPEG files:

max-files controls both the number of photos captured and the number of files saved locally. With max-files=1, the command captures one photo and saves one JPEG file in /home/pi. Setting max-files=n captures n photos and saves n local files.

sudo -E gst-launch-1.0 -e \
    qtiqmmfsrc name=camsrc ! \
    'video/x-raw,format=NV12,width=1280,height=720,framerate=30/1' ! \
    queue ! videoconvert ! jpegenc ! \
    multifilesink location=/home/pi/shot-%05d.jpg max-files=1

When the pipeline state changes to PLAYING, image capture is active. Press Ctrl+ C to stop the pipeline.

Once stopped, run the following command to verify that the photo was captured successfully, or double-click the image directly on the GNOME desktop to view it:

ls -lh /home/$USER/shot-*.jpg

Expected output:

-rw-r--r-- 1 root root 128K Oct  1 10:30 /home/$USER/shot-00000.jpg

Advanced: Capture a photo with Python and OpenCV

Install OpenCV:

sudo apt update
sudo apt install -y python3-opencv

Create the file ~/capture.py:

import cv2

# Access the MIPI camera through a GStreamer pipeline
gst_pipeline = (
    "qtiqmmfsrc name=camsrc ! "
    "video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! "
    "videoconvert ! video/x-raw,format=BGR ! appsink drop=true max-buffers=1"
)

cap = cv2.VideoCapture(gst_pipeline, cv2.CAP_GSTREAMER)

if not cap.isOpened():
    print("Error: Unable to open the camera")
    exit(1)

# Skip the first few frames to allow automatic exposure and white balance to settle
for i in range(30):
    cap.read()

ret, frame = cap.read()
if ret:
    cv2.imwrite("/home/pi/opencv_photo.jpg", frame)
    print("Photo captured successfully and saved to /home/pi/opencv_photo.jpg")
else:
    print("Error: Unable to read an image frame")

cap.release()

Note

The script saves the photo to /home/pi/opencv_photo.jpg. Edit this path to save the file elsewhere.

Run the script (requires sudo privileges; ensure export GST_PLUGIN_PATH=/usr/lib/gstreamer-1.0:$GST_PLUGIN_PATH is set beforehand):

sudo -E python3 ~/capture.py

Note

The IMX219 is a MIPI CSI-2 image sensor. On the Quectel Pi H1 platform, the camera is managed centrally by the Qualcomm Multi-Media Framework (QMMF) service via the qtiqmmfsrc plugin. This example accesses the camera through a GStreamer pipeline.

Explore GPIO

View GPIO pin status

Install the GPIO command-line tools:

sudo apt update && sudo apt install -y gpiod

List all GPIO controllers in the system:

sudo gpiodetect

Example output:

pi@quectelpi:/$ sudo gpiodetect
gpiochip0 [c440000.spmi:pmic@8:pinctrl@c00] (12 lines)
gpiochip1 [c440000.spmi:pmic@1:gpio@8800] (10 lines)
gpiochip2 [c440000.spmi:pmic@2:gpio@8800] (9 lines)
gpiochip3 [c440000.spmi:pmic@0:gpio@b000] (4 lines)
gpiochip4 [f100000.pinctrl] (176 lines)
gpiochip5 [33c0000.pinctrl] (15 lines)

View the status of all pins on a specific controller:

sudo gpioinfo --chip gpiochip4

Example output:

pi@quectelpi:/$ sudo gpioinfo --chip gpiochip4
gpiochip4 - 176 lines:
        line   0:       unnamed                 input
        line   1:       unnamed                 input
        line   2:       unnamed                 output active-low consumer=perst
        line   3:       unnamed                 input
        line   4:       unnamed                 input
        line   5:       unnamed                 input
        line   6:       unnamed                 output consumer=switch
        line   7:       unnamed                 output consumer=enable
        line   8:       unnamed                 output
        line   9:       unnamed                 output consumer=soc@0:pin40_en_vr
 ...

Each output line represents a GPIO pin. A pin marked with consumer=xxx is in use by a kernel driver.

Note

The onboard KEY1 and KEY2 buttons are managed by the kernel's gpio-keys and pmic_resin drivers and are exposed to user space as standard Linux input devices. Therefore, use evtest or evdev to read button events instead of manipulating GPIO pins directly.

Verify the buttons with evtest

Install the evtest utility:

sudo apt install -y evtest

Quectel Pi H1 smart single-board computer provides two user buttons, KEY1 and KEY2, which are exposed through the Linux input subsystem. Event device numbers can change between system versions. Run sudo evtest first to identify the event devices for gpio-keys and pmic_resin; the table below shows the mapping used in this example.

Button

Input device

Mapped key code

KEY1

/dev/input/event3

KEY_VOLUMEDOWN (114)

KEY2

/dev/input/event1

KEY_VOLUMEUP (115)

Run the following command to monitor KEY1:

sudo evtest /dev/input/event3

Press KEY1. The terminal displays the button events in real time:

Event: time ..., type 1 (EV_KEY), code 114 (KEY_VOLUMEDOWN), value 1   ← Pressed
Event: time ..., type 1 (EV_KEY), code 114 (KEY_VOLUMEDOWN), value 0   ← Released

Press Ctrl+ C to exit. Similarly, you can use sudo evtest /dev/input/event1 to monitor KEY2.

../../_images/image_DDdQbsb7foTZwbxqNGMcnzVsn2g.webp

Monitor button events with Python

Install the evdev library:

sudo apt update && sudo apt install -y python3-evdev

Create the file ~/button_monitor.py:

from evdev import InputDevice, ecodes
import selectors

# Bind device event nodes (verify against the actual node numbers retrieved from evtest)
dev_key1 = InputDevice("/dev/input/event3")
dev_key2 = InputDevice("/dev/input/event1")

print(f"Monitoring KEY1: {dev_key1.name}")
print(f"Monitoring KEY2: {dev_key2.name}")
print("Press Ctrl+C to exit")

sel = selectors.DefaultSelector()
sel.register(dev_key1, selectors.EVENT_READ)
sel.register(dev_key2, selectors.EVENT_READ)

try:
    while True:
        for key, _ in sel.select():
            device = key.fileobj
            for event in device.read():
                if event.type == ecodes.EV_KEY and event.value == 1:
                    if event.code == ecodes.KEY_VOLUMEDOWN:
                        print("KEY1 pressed!")
                    elif event.code == ecodes.KEY_VOLUMEUP:
                        print("KEY2 pressed!")
except KeyboardInterrupt:
    print("\nMonitoring stopped")

Run the script:

sudo python3 ~/button_monitor.py

Press KEY1 or KEY2. The terminal displays the corresponding message. Press Ctrl+ C to exit.

Note

Accessing Linux input devices requires root privileges, so run the script with sudo.

../../_images/image_NPKcbt0WromHAPxtr7scDBVQnUd.webp

Troubleshooting

  1. The photo capture command reports "no element qtiqmmfsrc".

Set the plugin path first:

export GST_PLUGIN_PATH=/usr/lib/gstreamer-1.0:$GST_PLUGIN_PATH

Then run the photo capture command.

  1. The photo capture command reports "Failed to connect to bus".

  • Ensure the command includes the sudo -E prefix, as the camera plugin requires root privileges.

  • If the error persists, the background camera daemon may be in an abnormal state. Restart the media service in the terminal:

sudo systemctl restart qmmf-server
  1. evtest does not display button events.

The device numbers may differ from those in the examples. Run sudo evtest without arguments to list all input devices. Then locate the gpio-keys and pmic_resin devices and use their corresponding event numbers.

  1. The Python script reports a permission error.

Both input devices and the camera require root privileges:

  • Button script: sudo -E python3 ~/button_monitor.py

  • Photo capture script: sudo -E python3 ~/capture.py