forked from tanchou/Verilog
Leds
This commit is contained in:
30
Semaine_7/DHT11_UART/tests/pyhton/readSerial.py
Normal file
30
Semaine_7/DHT11_UART/tests/pyhton/readSerial.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import serial
|
||||
import time
|
||||
|
||||
# Configuration du port série
|
||||
ser = serial.Serial(
|
||||
port='/dev/ttyUSB0', # Remplace par ton port (ex : COM3 sous Windows)
|
||||
baudrate=115200,
|
||||
timeout=1 # En secondes
|
||||
)
|
||||
|
||||
print("Lecture du port série... (Ctrl+C pour quitter)")
|
||||
|
||||
try:
|
||||
while True:
|
||||
# Lire 2 octets
|
||||
data = ser.read(2)
|
||||
|
||||
if len(data) == 2:
|
||||
temperature = data[0]
|
||||
humidite = data[1]
|
||||
print(f"Température: {temperature}°C, Humidité: {humidite}%")
|
||||
else:
|
||||
print("Pas assez de données reçues.")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\nArrêt du script.")
|
||||
finally:
|
||||
ser.close()
|
Reference in New Issue
Block a user