jardin_bmp280_script
Ceci est une ancienne révision du document !
Modification du script meteo_dht22.py
#Importation
import adafruit_dht
import adafruit_bmp280
import board
import busio
import time
import math
from datetime import datetime
#Déclaration du capteur
dhtDevice = adafruit_dht.DHT22(board.D4)
i2c = busio.I2C(board.SCL, board.SDA)
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76)
#Couleurs
RED = "\033[91m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
BLUE = "\033[94m"
MAGENTA = "\033[95m"
CYAN = "\033[96m"
RESET = "\033[0m"
#Calcul du point de rosée
def calculer_point_de_rosee(temperature, humidity):
# Formule pour calculer le point de rosée
alpha = 17.27
beta = 237.7
gamma = (alpha * temperature) / (beta + temperature) + math.log(humidity / 100.0)
point_de_rosee = (beta * gamma) / (alpha - gamma)
return point_de_rosee
#Calcul de l'humidex
def calculer_humidex(temperature, point_de_rosee):
# Formule pour calculer l'humidex
humidex = temperature + (5/9) * (6.11 * math.exp(5417.7530 * ((1/273.16) - (1/273.15 + point_de_rosee))) - 10)
return humidex
#Boucle et affichage
while True:
humidity = dhtDevice.humidity
temperature = dhtDevice.temperature
pression = bmp280.pressure
if humidity is not None and temperature is not None:
now = datetime.now()
date_heure = now.strftime("%d-%m-%Y %H:%M:%S")
point_de_rosee = calculer_point_de_rosee(temperature, humidity)
humidex = calculer_humidex(temperature, point_de_rosee)
print(f"{BLUE}Date et heure:{RESET} {date_heure}")
print(f"{GREEN}Température:{RESET} {round(temperature, 1)}°C")
print(f"{YELLOW}Humidité:{RESET} {round(humidity, 1)}%")
print(f"{RED}Point de rosée:{RESET} {round(point_de_rosee, 1)}°C")
print(f"{MAGENTA}Humidex:{RESET} {round(humidex, 1)}")
print(f"{CYAN}Pression atmosphérique:{RESET} {round(pression, 2)}hpa")
print("----")
else:
print("Échec de la lecture du capteur")
#Pause de 20 secondes
time.sleep(20)
jardin_bmp280_script.1751025147.txt.gz · Dernière modification : de admin
