🛠 Mastering GPIO on Banana Pi BPI-CM5

Banana Pi BPI-CM5: Amlogic A311D2 Compute Module with Raspberry Pi CM4 Compatibility · debutant · Apprenez à contrôler les broches GPIO de votre BPI-CM5 pour allumer une LED et lire un bouton, une première étape essentielle pour l'interaction physique.

Objectives

This tutorial guides you through manipulating the General Purpose Input/Output (GPIO) pins of your Banana Pi BPI-CM5. Although compact (55x40 mm), the module offers remarkable flexibility thanks to its Board-to-Board connectors compatible with the Raspberry Pi CM4. We will configure an output to light up an LED and an input to detect a button press. This practice is fundamental to understanding how your Linux system (Ubuntu, Debian, or Armbian) interacts with the physical world via the Amlogic A311D2 SoC.

Required Materials

Steps

  1. System Preparation: Connect via SSH or serial port. Ensure your system is up to date with sudo apt update && sudo apt upgrade. Install GPIO control tools if necessary. While python3-rpi.gpio is common for Pi, libgpiod tools are often better for Amlogic architectures. Check availability with sudo apt install python3-gpiod or use sysfs directly.
  1. Pin Identification: Consult your carrier board's documentation. The B2B connectors expose pins following the Raspberry Pi standard. Identify a GPIO-capable pin (e.g., GPIO17) for output and another (e.g., GPIO27) for input.
  1. LED Wiring (Output):
  1. Button Wiring (Input):

``bash # Export pin 17 (BCM numbering may vary, check with gpioinfo) echo 17 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio17/direction echo 1 > /sys/class/gpio/gpio17/value # Turn LED on sleep 2 echo 0 > /sys/class/gpio/gpio17/value # Turn LED off ``

  1. Command Line Test (Sysfs): Test quickly without complex programming using the sysfs directory.

``bash echo 27 > /sys/class/gpio/export echo in > /sys/class/gpio/gpio27/direction # Check state (0 if pressed due to pull-up, 1 otherwise) cat /sys/class/gpio/gpio27/value ``

  1. Reading Input: Configure pin 27 as input with pull-up.

Verification

You should observe the LED turning on and off according to the sent commands. While holding the button pressed, the cat command on the input pin must return 0. If nothing happens, check physical connections and ensure you have root rights (sudo) to access sysfs files.

Further Reading

Once basics are mastered, explore Python libraries like libgpiod for robust interrupt handling (press detection without polling loops). You can also integrate these I/Os into applications using the BPI-CM5's advanced interfaces, such as video capture via MIPI-CSI ports or display on multiple HDMI outputs.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials