Browse Source

arduino dht11 python

master
Jakub Škrabánek 7 days ago
parent
commit
015ae5c286
  1. 19
      01_arduino_dht_python/arduino_dht11_simple/arduino_dht11_simple.ino
  2. 18
      01_arduino_dht_python/main.py
  3. 18
      01_arduino_dht_python/plot.py
  4. 12
      01_arduino_dht_python/prikazy.txt

19
01_arduino_dht_python/arduino_dht11_simple/arduino_dht11_simple.ino

@ -0,0 +1,19 @@
#include <DHT11.h>
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);
}

18
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)

18
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

12
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
Loading…
Cancel
Save