🛠 Controlling GPIOs on Banana Pi BPI-RT2
Objectives
This tutorial introduces physical interaction with the Banana Pi BPI-RT2. Although designed as a WiFi 6 router, it exposes GPIO and I2C extension interfaces for simple electronic components. You will learn to identify pins, install necessary tools, and light an LED via a simple script.
Required Hardware
- Banana Pi BPI-RT2 powered by 12V DC.
- Ethernet cable for WAN/LAN connection.
- Computer to access web interface or SSH.
- Red LED and 330 Ohm resistor.
- Male-to-female jumper wires.
- Internet access for package downloads.
Steps
- System Access: Connect the card to your network via the WAN port. Access the web interface (default 192.168.1.1) and enable the SSH server in the System menu.
- SSH Connection: Open a terminal on your computer and connect via
ssh root@192.168.1.1. Accept security keys and enter the defined password. - Tool Installation: The card uses OpenWrt. Update package lists with
opkg updatethen install GPIO tools withopkg install kmod-gpio-button-hotplug gpioctl. These tools allow manipulation of physical pins on the 5 and 9-pin headers. - Pin Identification: Consult technical documentation to identify available GPIO pins on the headers. GPIO and I2C signals are shared; ensure you do not use a pin already occupied by the system if configured as output.
- Wiring: Connect the long leg (anode) of the LED to an identified GPIO pin. Connect the short leg (cathode) to a 330 Ohm resistor, then connect the other end of the resistor to the GND (ground) pin of the card.
- Pin Activation: In the SSH terminal, activate the pin as output. For example, if GPIO 10 is free, use
echo 10 > /sys/class/gpio/exportto make it accessible. - Configuration and Test: Set direction to output with
echo out > /sys/class/gpio/gpio10/direction. To light the LED, send a high signal:echo 1 > /sys/class/gpio/gpio10/value. The LED should light up. - Turning Off: To turn off the LED, send a low signal:
echo 0 > /sys/class/gpio/gpio10/value.
Verification
Physically observe the LED. It should light up when executing echo 1 and turn off with echo 0. If nothing happens, check LED orientation, resistor connection, and ensure the selected pin is not conflicting. Use cat /sys/class/gpio/gpio10/value to check the current logical state.
Going Further
Explore the I2C interface exposed on the same connectors to connect a small OLED screen or temperature sensor. You will need to install kmod-i2c-core and kmod-i2c-dev. Note that the firmware is based on an older OpenWrt version; ensure drivers are available in official Banana Pi repositories to avoid conflicts.
Other tutorials for this board
- Configure a reliable WiFi 6 network with BPI-RT2
- First Boot and Initial Setup of Banana Pi BPI-RT2
- Interfacing a DHT11 Sensor with BPI-RT2 GPIO
- Configure BPI-RT2 as network gateway and light storage
- Advanced setup: First console access and firmware flashing for BPI-RT2
- Mastering GPIO on Banana Pi BPI-RT2