🛠 Interfacing a DHT11 Sensor with BPI-RT2 GPIO

Banana Pi BPI-RT2: AX3000 WiFi 6 Router Board · intermediaire · Apprenez à lire les données de température et d'humidité via l'en-tête GPIO de la BPI-RT2 sous OpenWrt.

Objectives

This tutorial guides you through interfacing a DHT11 sensor with the Banana Pi BPI-RT2 board. The goal is to understand GPIO usage on an embedded router running OpenWrt. We will configure a specific pinout, install necessary tools, and read raw data. This intermediate level assumes basic Linux command line knowledge. You will learn to manipulate system devices for simple IoT needs without networking.

Required Hardware

Steps

  1. Circuit Preparation: Power off the BPI-RT2. Connect the DHT11 VCC pin to the 3.3V available on the GPIO header. Connect GND to ground. Place the 10 kΩ resistor between VCC and the DATA pin. Connect the sensor's DATA pin to a free GPIO, e.g., GPIO 18 (verify with official schematic).
  2. SSH Connection: Reconnect power. SSH into the board's IP address (default 192.168.1.1). Update package lists:
opkg update
  1. Install GPIO Tools: Install packages for sysfs GPIO control:
opkg install kmod-gpio-button-hotplug kmod-gpio-nct-gpio

Note: Specific DHT modules may require kernel compilation if not natively present in the Realtek BSP. For this tutorial, we assume using a shell script for timing or a compatible third-party driver.

  1. Export GPIO: Identify the GPIO number for your physical pin. Export it:
echo 18 > /sys/class/gpio/export
  1. Read Data: If the DHT driver is loaded, read the value file. Otherwise, use gpioget if available:
gpioget gpiochip0 18

For standard DHT11, using an external MCU or dedicated Python script is often easier. In minimal OpenWrt, direct 1-Wire bit-banging via shell is hard. Ensure the dht11 kernel module is loaded:

modprobe dht11

If missing, compile the BSP. This tutorial focuses on GPIO configuration. Verify the GPIO is set to input:

echo in > /sys/class/gpio/gpio18/direction

Verification

Check that /sys/class/gpio/gpio18/value exists. If a compatible driver is loaded, reading this file should return a stable value or change with temperature. Use dmesg to check for module loading errors.

Further Reading

Explore I2C usage via the 9-pin header for complex sensors like BME280, offering better precision and robust digital interface than analog DHT11.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials