BananaPro/Pi: GPIO library
Summary
GPIO access on Banana Pi and Banana Pro boards requires understanding pin numbering schemes, choosing appropriate userspace access methods, and ensuring correct voltage levels to avoid hardware damage. This page provides a practical workflow: identify your board's GPIO capabilities, select a library or interface method, verify pin mapping, test with simple I/O operations, and debug common permission and configuration issues. Most GPIO problems stem from pin numbering confusion between different schemes (WiringPi vs BCM vs physical), voltage mismatch (3.3V GPIO vs 5V signals), or missing permissions for /dev/gpiochip* access.
Who this is for
Makers building GPIO-based projects (sensors, LEDs, motors), developers integrating hardware peripherals, and anyone migrating from WiringPi or other deprecated GPIO libraries who needs modern access patterns for Banana Pi hardware.
What you'll do
- Identify available GPIO pins and their numbering on your Banana Pi/Pro board.
- Choose between modern libgpiod, kernel sysfs ABI, or legacy WiringPi (if available).
- Configure permissions for GPIO device access without root privileges.
- Test GPIO output with LED and input with button or sensor.
- Troubleshoot pin numbering mismatches and permission errors.
- Implement safe practices to avoid damaging GPIO pins.
Requirements
- Pinout documentation: Know your board revision (Banana Pi M1, M1+, Banana Pro). Pinouts vary slightly.
- Voltage awareness: Banana Pi GPIO operates at 3.3V logic levels. Do NOT connect 5V signals directly without level shifter.
- Test hardware: LED with 220O resistor for output test; push button with pull-up/pull-down resistor for input test.
- Software tools: libgpiod package (gpiod-tools) for modern GPIO access.
- Permissions: User must be in gpio group or have udev rules for /dev/gpiochip* access.
- Documentation: Board schematic or pinout diagram showing GPIO numbers, physical pin positions, and alternate functions.
GPIO overview for Banana Pi/Pro
Banana Pi (M1): Allwinner A20 SoC with multiple GPIO banks (PA, PB, PC, PD, PE, PF, PG, PH, PI). Expansion header exposes ~40 GPIO pins. Not all pins are available; some reserved for I2C, SPI, UART, or other functions.
Banana Pro: Same A20 SoC as Banana Pi with identical GPIO layout. Additional onboard WiFi/Bluetooth does not affect expansion header GPIO availability.
Voltage levels: All GPIO pins are 3.3V. Maximum current per pin: ~6mA safe, 10mA absolute maximum. Use external driver for loads >5mA (relays, motors).
Pin numbering confusion: Three common schemes exist:
- Physical pin numbers: Pin 1-40 on expansion header (easiest for wiring).
- BCM GPIO numbers: Raspberry Pi compatibility layer (not native to A20).
- Allwinner port/pin notation: PH0, PH1 (bank + offset). Native to A20 hardware.
- WiringPi numbers: Deprecated abstraction layer (avoid in new projects).
Step-by-step GPIO setup
1. Install GPIO tools
# Debian/Ubuntu (Armbian, Raspbian-based images)
sudo apt update
sudo apt install gpiod libgpiod-dev python3-libgpiod
# Verify installation
gpiodetect
# Should show gpiochip0, gpiochip1, etc.
2. Identify GPIO chips and available lines
# List GPIO chips
ls -l /dev/gpiochip*
# Output: /dev/gpiochip0, /dev/gpiochip1 (number varies by kernel)
# Get detailed info
gpioinfo 2>/dev/null | head -n 60
# Shows chip name, line numbers, names, and current usage
# Example output interpretation:
# gpiochip0 - 192 lines:
# line 0: \"PA0\" unused input active-high
# line 1: \"PA1\" \"led-green\" output active-high [used]
3. Configure permissions
Add user to gpio group (if it exists) or create udev rule:
# Check if gpio group exists
getent group gpio
# Add user to gpio group
sudo usermod -aG gpio $USER
# Log out and back in for group change to take effect
# If gpio group doesn't exist, create udev rule
sudo tee /etc/udev/rules.d/99-gpio.rules <
4. Test GPIO output (LED blink)
Physical setup: Connect LED anode (long leg) to GPIO pin via 220O resistor, cathode to GND.
# Find GPIO line number for your pin
# Example: Physical pin 7 is often PH2 (varies by board)
gpioinfo | grep PH2
# Set pin as output and turn on (replace gpiochip0 and line number)
gpioset gpiochip0 98=1 # Turn on (line 98 example, verify your board!)
sleep 1
gpioset gpiochip0 98=0 # Turn off
Simple blink script:
#!/bin/bash
CHIP=\"gpiochip0\"
LINE=\"98\" # Change to your GPIO line number
for i in {1..10}; do
gpioset $CHIP $LINE=1
sleep 0.5
gpioset $CHIP $LINE=0
sleep 0.5
done
5. Test GPIO input (button read)
Physical setup: Connect one side of push button to GPIO pin, other side to GND. Enable internal pull-up or use external pull-up resistor (10kO to 3.3V).
# Read pin state (returns 0 or 1)
gpioget gpiochip0 98
# Monitor pin changes in real-time
gpiomon --num-events=10 gpiochip0 98
# Press button, watch for \"event\" lines
# Read with pull-up enabled (if kernel supports)
# Note: Not all kernels expose bias settings to gpioset
# May require Python gpiod library or kernel configuration
6. Python GPIO example
#!/usr/bin/env python3
import gpiod
import time
# Open GPIO chip
chip = gpiod.Chip('gpiochip0')
# Get GPIO line (change line number for your pin)
line = chip.get_line(98)
# Configure as output
line.request(consumer=\"led-blink\", type=gpiod.LINE_REQ_DIR_OUT)
# Blink 10 times
for _ in range(10):
line.set_value(1)
time.sleep(0.5)
line.set_value(0)
time.sleep(0.5)
# Release line
line.release()
Concrete example (identify GPIO chips)
ls -l /dev/gpiochip*
gpioinfo 2>/dev/null | head -n 60
# Test specific pin (PH2 example - line 98 on many A20 boards)
gpioset gpiochip0 98=1 # LED on
sleep 1
gpioset gpiochip0 98=0 # LED off
Troubleshooting
Wrong pin toggles; unexpected behavior
- Symptoms: LED on wrong pin lights up; button input reads from different pin; multiple pins toggle together.
- Steps:
- Verify pin numbering scheme. Physical pin 7 ? GPIO 7 ? WiringPi pin 7. Use
gpioinfo | grep PHto map Allwinner names to line numbers. - Check board schematic or pinout diagram. Some pins have alternate functions (I2C, SPI) that may be active.
- Test with known-good pin: PH2 (often line 98) is usually safe for testing on Banana Pi/Pro.
- Disable conflicting services:
systemctl statusand check for SPI, I2C drivers claiming pins. - Use
gpioinfoto see which lines are marked \"used\" by kernel drivers.
- Verify pin numbering scheme. Physical pin 7 ? GPIO 7 ? WiringPi pin 7. Use
Permission denied when accessing GPIO
- Symptoms:
gpiodetectrequires sudo;gpiosetfails with \"Permission denied\"; /dev/gpiochip* owned by root. - Steps:
- Check group membership:
groups. Should include gpio or users. - Add user to gpio group:
sudo usermod -aG gpio $USER, then log out/in. - Verify udev rules exist:
ls /etc/udev/rules.d/*gpio*. Create 99-gpio.rules if missing (see step 3 above). - Check /dev/gpiochip* permissions:
ls -l /dev/gpiochip*. Should be crw-rw---- gpio or users group. - Reload udev:
sudo udevadm control --reload-rules && sudo udevadm trigger.
- Check group membership:
Pin conflicts with other services
- Symptoms:
gpioinfoshows line \"used\";gpiosetfails with \"Device or resource busy\"; I2C/SPI not working after GPIO use. - Steps:
- Check which driver is using the line:
gpioinfo | grep usedshows consumer name. - Disable conflicting service:
sudo systemctl stop i2cor blacklist kernel module. - Choose different GPIO pin that's not claimed by hardware drivers.
- Check device tree overlays: Some images use overlays that pre-claim GPIO for specific functions.
- Check which driver is using the line:
No /dev/gpiochip* devices found
- Symptoms:
ls /dev/gpiochip*returns \"No such file\";gpiodetectshows nothing. - Steps:
- Check kernel GPIO support:
zcat /proc/config.gz | grep GPIO. Need CONFIG_GPIOLIB=y, CONFIG_GPIO_SYSFS=y or CONFIG_GPIO_CDEV=y. - Verify kernel modules loaded:
lsmod | grep gpio. Should see gpio_sunxi or similar. - Try legacy sysfs interface:
ls /sys/class/gpio. If present, kernel uses old interface (not recommended). - Update kernel or switch to image with GPIO support enabled.
- Check kernel GPIO support:
FAQ
Can I use 5V signals with Banana Pi GPIO?
No. Banana Pi GPIO pins are 3.3V only. Connecting 5V signal will damage the SoC. Use level shifter (bidirectional logic level converter) or voltage divider for 5V devices. Many I2C/SPI devices tolerate 3.3V even if powered by 5V.
What's the maximum current I can draw from a GPIO pin?
Safe continuous current: 4-6mA per pin. Absolute maximum: 10mA. Total for all GPIO pins: ~100mA. For loads >5mA (relays, motors, high-power LEDs), use transistor or MOSFET driver circuit powered from external 5V rail.
Which GPIO library should I use for new projects?
Use libgpiod (modern, kernel-supported). Avoid WiringPi (deprecated since 2019, unmaintained). Kernel sysfs interface (/sys/class/gpio) is deprecated but still works on older kernels. Python: python3-libgpiod. C/C++: libgpiod-dev.
How do I find GPIO line number for a physical pin?
Use board pinout diagram to find Allwinner port/pin (e.g., PH2), then gpioinfo | grep PH2 to get line number. No universal mapping; varies by kernel and device tree. Test with LED before connecting real hardware.
Can I use hardware PWM on GPIO pins?
Some A20 pins support hardware PWM (PWM0, PWM1 on specific pins). Check board schematic. Software PWM possible on any GPIO but has timing jitter (not suitable for precise motor control or servo). Use hardware PWM via /sys/class/pwm interface.
Why does WiringPi not work on my image?
WiringPi was deprecated in 2019 and removed from many modern distributions. If your image includes it, consider migrating to libgpiod. WiringPi may have incorrect pin mappings for newer kernels or board revisions.
How do I enable internal pull-up/pull-down resistors?
Depends on kernel and device tree configuration. libgpiod v2+ supports bias flags (LINE_REQ_FLAG_BIAS_PULL_UP). Older kernels require device tree modification. For reliability, use external pull-up/pull-down resistors (10kO).
Can I use interrupts to detect button presses?
Yes. Use gpiomon for command-line monitoring, or Python libgpiod with event_wait() for edge detection (rising, falling, both). More efficient than polling. Requires kernel interrupt support for GPIO lines.
External reference
- libgpiod documentation
- Linux Kernel GPIO documentation
- linux-sunxi GPIO documentation (Allwinner-specific)
Related pages
- WiringPi (deprecated, archival)
- LeMaker Banana Pro / Pi (board hub)
- Main Page
Author: LeMaker Documentation Team
Last updated: 2026-01-11