i2c-sensor-dht11-python.py

Banana Pi BPI-RT2: AX3000 WiFi 6 Router Board · File : i2c-sensor-dht11-python.py · Language : python · Use case : Lire un capteur de température/humidité DHT11 connecté via GPIO (bit-banging).

Python example to read a DHT11 sensor, requiring a library adapted to MIPS/OpenWrt architecture.

Connect the DHT11 to a GPIO with a pull-up resistor. On OpenWrt, install Python3 and necessary GPIO libraries. GPIO support may require kernel modifications or use of 'gpiod'. Test Python library compatibility on MIPS.

i2c-sensor-dht11-python.py

import time
import sys

# Note: Le BPI-RT2 n'a pas de bibliothèque DHT native standard sur OpenWrt minimal.
# Cette approche utilise le GPIO via sysfs pour le bit-banging.
# Assurez-vous que le module 'gpio' est disponible ou utilisez 'gpiod'.
# Pour cet exemple, nous simulons la structure ou utilisons un wrapper si disponible.
# Alternativement, pour un vrai DHT11 sur GPIO, une implémentation C ou un wrapper Python 'dht11' compilé est requis.
# Voici un exemple de structure d'appel si une bibliothèque 'dht11' python est installée via pip/opkg.

try:
    import dht11
    import RPi.GPIO as GPIO # Note: RPi.GPIO peut nécessiter un portage pour MIPS/OpenWrt
    
    DHTPIN = 10
    
    print("Initialisation du capteur DHT11...")
    
    while True:
        try:
            humidity, temperature = dht11.read(DHTPIN)
            print(f"Température: {temperature} °C, Humidité: {humidity} %")
        except Exception as e:
            print(f"Erreur de lecture: {e}")
        time.sleep(2)

except ImportError:
    print("Bibliothèque dht11 non trouvée. Installez-la via opkg ou compilez-la.")
    print("Exemple d'installation: opkg install python3-dht11 (si disponible)")

← Back to the board