🛠 Getting Started with GPIO on LattePanda Mu Ultra

LattePanda Mu Ultra: x86 Compute Module for Embedded AI · debutant · Apprenez à contrôler une LED et lire un bouton via les broches GPIO de la carte porteuse.

Objectives

This tutorial aims to familiarize you with the digital General Purpose Input/Output (GPIO) interfaces of the LattePanda Mu Ultra module. We will configure one pin as an output to light up an LED and another as an input to detect a button press. Although the Mu Ultra is optimized for embedded AI with its 115 TOPS, it remains a full x86 computer capable of interacting with the physical world via its Mini Carrier Board.

Materials Needed

Steps

  1. System Preparation: Ensure your Linux system (Ubuntu 24.04+ recommended) is up to date. Open a terminal and install the libgpiod library, which facilitates GPIO management on modern Linux.
sudo apt update
sudo apt install gpiod libgpiod2 python3-libgpiod
  1. Pin Identification: Consult the Mini Carrier Board documentation to identify available GPIO pins. Here, we assume pin 17 is the output (LED) and pin 4 is the input (Button). Note that GPIO voltages are typically 3.3V.
  2. Wiring: Connect the long leg (anode) of the LED to pin 17 via the resistor. Connect the short leg (cathode) to Ground (GND). For the button, connect one leg to pin 4 and the other to Ground.
  3. Control Script: Create a file named test_gpio.py.
import gpiod
import time

chip = gpiod.Chip('gpiochip0')
line_out = chip.get_line(17)
line_out.request(consumer='led', type=gpiod.LINE_REQ_DIR_OUT)

line_in = chip.get_line(4)
line_in.request(consumer='btn', type=gpiod.LINE_REQ_DIR_IN, flags=gpiod.LINE_REQ_FLAG_BIAS_PULL_UP)

try:
    while True:
        if line_in.get_value() == 0:
            print("Button pressed!")
            line_out.set_value(1)
        else:
            line_out.set_value(0)
        time.sleep(0.1)
except KeyboardInterrupt:
    line_out.release()
    line_in.release()
  1. Execution: Run the script with necessary permissions.
sudo python3 test_gpio.py

Verification

Press the push button. The LED should light up immediately, and the terminal should display "Button pressed!". If nothing happens, check the wiring, LED polarity, and pin numbers in the carrier board documentation.

Going Further

Explore analog inputs if available on your configuration, or use the Intel Arc GPU to process sensor data in real-time, leveraging the Mu Ultra's AI power.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials