sensor-temp-humidity-display.py

Raspberry Pi Smart Display Module · File : sensor-temp-humidity-display.py · Language : Python · Use case : Lire un capteur DHT22 et afficher les données sur l'écran SDM via le framebuffer.

Example of reading environmental sensors and sending data to the Smart Display Module's display.

Uses the Compute Module 5 with the Smart Display Module. Install sensor libraries (e.g., adafruit-circuitpython-dht) and ensure the framebuffer is active (fbcp). The code simulates reading for portability. For real display, configure the system to use the SDM panel as the main video output.

sensor-temp-humidity-display.py

import time
import subprocess
import os

# Simulation de la lecture DHT22 (nécessite bibliothèque adafruit-circuitpython-dht)
# import adafruit_dht
# import board
# dhtDevice = adafruit_dht.DHT22(board.D4)

def get_sensor_data():
    # Remplacer par la lecture réelle si la lib est installée
    return 22.5, 45.0 

def display_text(text):
    # Utilise fbcp-ili9341 ou le framebuffer standard si configuré
    # Pour l'exemple, on imprime sur stdout, mais sur le SDM, cela irait au display
    print(f"Affichage: {text}")
    # Exemple d'écriture dans le framebuffer (nécessite pyfbd ou équivalent)
    # import numpy as np
    # import pyfbd
    # fb = pyfbd.Framebuffer()
    # ... logique de rendu ...

if __name__ == '__main__':
    while True:
        temp, hum = get_sensor_data()
        message = f"Temp: {temp:.1f}C | Hum: {hum:.1f}%"
        display_text(message)
        time.sleep(5)

← Back to the board