From 015ae5c286fff520c0e7a5e390648b29d79fcdd2 Mon Sep 17 00:00:00 2001 From: KubMakCZ Date: Fri, 9 Jan 2026 09:24:31 +0100 Subject: [PATCH] arduino dht11 python --- .../arduino_dht11_simple.ino | 19 +++++++++++++++++++ 01_arduino_dht_python/main.py | 18 ++++++++++++++++++ 01_arduino_dht_python/plot.py | 18 ++++++++++++++++++ 01_arduino_dht_python/prikazy.txt | 12 ++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 01_arduino_dht_python/arduino_dht11_simple/arduino_dht11_simple.ino create mode 100644 01_arduino_dht_python/main.py create mode 100644 01_arduino_dht_python/plot.py create mode 100644 01_arduino_dht_python/prikazy.txt diff --git a/01_arduino_dht_python/arduino_dht11_simple/arduino_dht11_simple.ino b/01_arduino_dht_python/arduino_dht11_simple/arduino_dht11_simple.ino new file mode 100644 index 0000000..a53d822 --- /dev/null +++ b/01_arduino_dht_python/arduino_dht11_simple/arduino_dht11_simple.ino @@ -0,0 +1,19 @@ +#include + +DHT11 dht11(2); + +void setup() { + Serial.begin(9600); +} +void loop() { + int temperature = dht11.readTemperature(); + + if (temperature != DHT11::ERROR_CHECKSUM && temperature != DHT11::ERROR_TIMEOUT){ + Serial.print("DHT11:"); + Serial.println(temperature); + } else{ + Serial.print("ERROR:"); + Serial.println(DHT11::getErrorString(temperature)); + } + delay(2000); +} diff --git a/01_arduino_dht_python/main.py b/01_arduino_dht_python/main.py new file mode 100644 index 0000000..94342b0 --- /dev/null +++ b/01_arduino_dht_python/main.py @@ -0,0 +1,18 @@ +import serial #pip intall pyserial +import time +from datetime import datetime + +ser = serial.Serial("COM3",9600) + +while True: + line = ser.readline().decode("utf-8").strip() + + sensor_name, sensor_value = line.split(":") + + now = datetime.now() + current_time = now.strftime("%H:%M:%S") + print(f"Čas: {current_time}") + print(f"Název senzoru: {sensor_name}") + print(f"Hodnota senzoru: {sensor_value}") + print("------------------") + time.sleep(1) \ No newline at end of file diff --git a/01_arduino_dht_python/plot.py b/01_arduino_dht_python/plot.py new file mode 100644 index 0000000..d54d1ec --- /dev/null +++ b/01_arduino_dht_python/plot.py @@ -0,0 +1,18 @@ +import serial +import matplotlib.pyplot as plt + +ser = serial.Serial("COM3",9600) +num_values = int(input("KOlik dat načíst?:")) +values = [] + +while True: + for i in range(num_values): + line = ser.readline().decode("utf-8").strip() + name, value = line.split(":") + values.append(int(value)) + print(i) + plt.plot(values) + plt.show() + values = [] + if input("q?").lower() == "q": + break \ No newline at end of file diff --git a/01_arduino_dht_python/prikazy.txt b/01_arduino_dht_python/prikazy.txt new file mode 100644 index 0000000..e8b832a --- /dev/null +++ b/01_arduino_dht_python/prikazy.txt @@ -0,0 +1,12 @@ +#vytvoření venv +python -m venv .venv + +#aktivace venv +.venv\Scripts\activate + +#instalace knihoven +pip install pyserial +pip install matplotlib + +#výpis knihoven ve venv +pip list \ No newline at end of file