← Back to Blog

Embedded Systems – Banana Pi BPI-M2 Ultra GPIO Control

Complete GPIO control guide for the Banana Pi BPI-M2 Ultra – Allwinner A40i, 2GB RAM, 8GB eMMC. Working with Raspberry Pi images, WiringPi, and GPIO control for LEDs, sensors, and automation.

10 min read Roman Swetly

Embedded Systems – Banana Pi BPI-M2 Ultra GPIO Control

Complete GPIO control guide for the Banana Pi BPI-M2 Ultra – Allwinner A40i, 2GB RAM, 8GB eMMC. Working with Raspberry Pi images, WiringPi, and GPIO control for LEDs, sensors, and automation.


Overview

The Banana Pi BPI-M2 Ultra is a powerful single-board computer based on the Allwinner A40i SoC, featuring:

  • Allwinner A40i – Quad-core ARM Cortex-A7.
  • 2GB DDR3 RAM – Ample memory for embedded applications.
  • 8GB eMMC – On-board storage.
  • On-board Wi-Fi & Bluetooth – Built-in wireless connectivity.
  • Raspberry Pi compatible – 40-pin GPIO header with Raspberry Pi pinout.

This page documents my experience getting the Banana Pi BPI-M2 Ultra running with GPIO control, including the critical steps to choose the right OS image and configure the GPIO pins.


Architecture

BANANA PI BPI-M2 ULTRA

Getting Started

Hardware Specifications

ComponentSpecification
SoCAllwinner A40i (Quad-core ARM Cortex-A7)
RAM2GB DDR3
Storage8GB eMMC + microSD card slot
NetworkingOn-board Wi-Fi + Bluetooth
GPIO40-pin header (Raspberry Pi compatible)
Power5V DC (quality power supply essential)

⚠️ Critical: Power Supply Quality

Quality power is essential. The Banana Pi is sensitive to power fluctuations. Use a reliable power supply (I used a laptop adapter). Poor power can cause:

  • Random crashes and reboots.
  • GPIO instability.
  • USB device detection issues.

OS Image Selection: Working vs Non-Working

✅ Working Image (GPIO Works)

Image: 2017-08-24-raspbian-jessie-beta-bpi-m2u-sd-emmc.img.zip

  • OS: Raspbian Jessie (Raspberry Pi OS).
  • GPIO: Fully working with WiringPi.
  • Source: Google Drive (Banana Pi official).

Download: Banana Pi Google Drive

❌ Non-Working Image (GPIO Does Not Work)

Image: Armbian-unofficial_26.02.0-trunk_Bananapim2ultra_trixie_current_6.12.68_xfce_desktop.img.xz

  • OS: Armbian Trixie (current).
  • GPIO: No GPIO effect (WiringPi not compatible or missing drivers).
  • Issue: The newer kernel does not support the GPIO interface correctly.

Recommendation

Use the older Raspbian Jessie image for reliable GPIO control. The newer Armbian images may offer more modern features, but GPIO is broken.


GPIO Pin Mapping

gpio readall Output

root@bpi-iot-ros-ai:/home/pi# gpio readall
 +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |  53 |   8 |   SDA.1 | ALT5 | 0 |  3 || 4  |   |      | 5v      |     |     |
 |  52 |   9 |   SCL.1 | ALT5 | 0 |  5 || 6  |   |      | 0v      |     |     |
 |  35 |   7 | GPIO. 7 | ALT3 | 0 |  7 || 8  | 0 | ALT4 | TxD     | 15  | 274 |
 |     |     |      0v |      |   |  9 || 10 | 0 | ALT4 | RxD     | 16  | 275 |
 | 276 |   0 | GPIO. 0 | ALT3 | 0 | 11 || 12 | 0 | ALT3 | GPIO. 1 | 1   | 273 |
 | 277 |   2 | GPIO. 2 | ALT3 | 0 | 13 || 14 |   |      | 0v      |     |     |
 | 249 |   3 | GPIO. 3 | ALT2 | 0 | 15 || 16 | 0 | ALT3 | GPIO. 4 | 4   | 272 |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | ALT2 | GPIO. 5 | 5   | 250 |
 |  64 |  12 |    MOSI | ALT4 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |  65 |  13 |    MISO | ALT4 | 0 | 21 || 22 | 0 | ALT2 | GPIO. 6 | 6   | 251 |
 |  66 |  14 |    SCLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE0     | 10  | 87  |
 |     |     |      0v |      |   | 25 || 26 | 0 | ALT2 | CE1     | 11  | 248 |
 | 257 |  30 |   SDA.0 | ALT3 | 0 | 27 || 28 | 0 | ALT3 | SCL.0   | 31  | 256 |
 | 224 |  21 | GPIO.21 | ALT4 | 0 | 29 || 30 |   |      | 0v      |     |     |
 | 225 |  22 | GPIO.22 | ALT4 | 0 | 31 || 32 | 0 | ALT3 | GPIO.26 | 26  | 116 |
 | 226 |  23 | GPIO.23 | ALT4 | 0 | 33 || 34 |   |      | 0v      |     |     |
 | 227 |  24 | GPIO.24 | ALT4 | 0 | 35 || 36 | 0 | ALT4 | GPIO.27 | 27  | 231 |
 | 228 |  25 | GPIO.25 | ALT4 | 0 | 37 || 38 | 0 | ALT4 | GPIO.28 | 28  | 230 |
 |     |     |      0v |      |   | 39 || 40 | 0 | ALT4 | GPIO.29 | 29  | 229 |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi ?---+---+------+---------+-----+-----+

Key Pins for GPIO Control

Physical PinwPiBCMNameCurrent ModeStatus
4029229GPIO.29ALT4⚠️ Needs mode change
3828230GPIO.28ALT4⚠️ Needs mode change
3627231GPIO.27ALT4⚠️ Needs mode change
3323226GPIO.23ALT4⚠️ Needs mode change
3524227GPIO.24ALT4⚠️ Needs mode change
3725228GPIO.25ALT4⚠️ Needs mode change

Important: Many GPIOs are in ALT4 (alternative function) by default. They must be switched to OUTPUT mode before use.


Controlling GPIO.29 (Pin 40)

Pin 40 is a useful GPIO pin (GPIO.29, wPi 29, BCM 229). However, it is in ALT4 mode by default.

Step 1: Change Mode to OUTPUT

# Set pin 29 to output mode
gpio mode 29 out

# Verify the change
gpio readall

Now Pin 40 should show OUT in the Mode column.

Step 2: Write Values

# Set HIGH (1)
gpio write 29 1

# Set LOW (0)
gpio write 29 0

Connect an LED with a 330Ω resistor between Pin 40 and GND (Pin 39), then run:

# Blink the LED
while true; do
    gpio write 29 1
    sleep 0.5
    gpio write 29 0
    sleep 0.5
done

Example Projects

1. 🚦 LED Blinker (Hardware Test)

Hardware: LED + 330Ω resistor between Pin 40 and GND.

# Simple blink using gpio command
while true; do
    gpio write 29 1
    sleep 0.5
    gpio write 29 0
    sleep 0.5
done

2. 🎮 Button Input

Hardware: Push button between Pin 40 and GND.

# Read button state
while true; do
    state=$(gpio read 29)
    if [ $state -eq 0 ]; then
        echo "Button pressed!"
    else
        echo "Button released"
    fi
    sleep 0.1
done

3. 🐍 Python GPIO Control

#!/usr/bin/env python3
import time
import wiringpi

# Initialize WiringPi
wiringpi.wiringPiSetup()

# Set pin 29 (wPi) as output
wiringpi.pinMode(29, 1)  # 1 = OUTPUT

try:
    while True:
        wiringpi.digitalWrite(29, 1)  # HIGH
        print("LED ON")
        time.sleep(0.5)
        wiringpi.digitalWrite(29, 0)  # LOW
        print("LED OFF")
        time.sleep(0.5)
except KeyboardInterrupt:
    wiringpi.digitalWrite(29, 0)
    print("\nExited")

4. 🌡️ DHT11 Sensor

# Install DHT library
sudo apt update
sudo apt install python3-pip
sudo pip3 install Adafruit_DHT
#!/usr/bin/env python3
import Adafruit_DHT
import time

sensor = Adafruit_DHT.DHT11
pin = 29  # wPi pin number

while True:
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
    if humidity is not None and temperature is not None:
        print(f"Temp: {temperature:0.1f}°C  Humidity: {humidity:0.1f}%")
    else:
        print("Sensor error")
    time.sleep(2)

Troubleshooting

Issue: GPIO Not Responding

Symptom: gpio write commands have no effect.

Cause:

  1. Pin is in ALT mode (e.g., ALT4) and not configured as GPIO.
  2. Using a non-working OS image (Armbian).

Solution:

# Check current mode
gpio readall

# Change to output mode
gpio mode <wPi_pin> out

Issue: gpio Command Not Found

# Install WiringPi
sudo apt update
sudo apt install wiringpi

# Or compile from source
git clone https://github.com/WiringPi/WiringPi.git
cd WiringPi
./build

Issue: Power Supply Problems

Symptom: Random reboots, USB devices not detected, GPIO unstable.

Solution: Use a quality 5V power supply with at least 2A capacity. Avoid phone chargers or cheap USB adapters.


GPIO Reference Table

Physical PinwPiBCMNameRecommended Use
4029229GPIO.29✅ General purpose
3828230GPIO.28✅ General purpose
3627231GPIO.27✅ General purpose
3323226GPIO.23✅ General purpose
3524227GPIO.24✅ General purpose
3725228GPIO.25✅ General purpose
3226116GPIO.26✅ General purpose
3122225GPIO.22✅ General purpose

Key Achievements

  • Identified working OS image for Banana Pi BPI-M2 Ultra.
  • Documented GPIO pin mapping using gpio readall.
  • Successfully controlled GPIO.29 (Pin 40) with WiringPi.
  • Created reusable scripts for LED, button, and DHT11.
  • Solved common issues with power supply and GPIO mode.

Technology Stack

CategoryTechnology
BoardBanana Pi BPI-M2 Ultra
SoCAllwinner A40i
OSRaspbian Jessie (Working)
GPIO ControlWiringPi, gpio commands
LanguagePython 3, Bash
SensorsDHT11
PeripheralsLED, Button


This Banana Pi GPIO exploration is part of my broader Embedded Systems Engineering practice. For a detailed technical walkthrough or custom automation design, feel free to reach out.

← Previous Post
Embedded Systems – Radxa Zero 3W Setup & Docker Environment
Next Post →
Embedded Systems – aml-s905x-cc-v2 GPIO & Peripheral Control

Related Articles