From 6741f776156a63b20eac9be3bb45ee8b2db57099 Mon Sep 17 00:00:00 2001 From: YuruC3 <98943911+YuruC3@@users.noreply.github.com> Date: Sat, 10 May 2025 10:20:38 +0200 Subject: [PATCH] Working with it. --- PC_CONTROL_CODE/.gitignore | 1 + PC_CONTROL_CODE/main.dht22.py | 29 ++++++++++++++ PC_CONTROL_CODE/main.py | 67 ++++++++++++++++++++++++++++++++ PC_CONTROL_CODE/requirements.txt | 1 + 4 files changed, 98 insertions(+) create mode 100644 PC_CONTROL_CODE/.gitignore create mode 100644 PC_CONTROL_CODE/main.dht22.py create mode 100644 PC_CONTROL_CODE/main.py create mode 100644 PC_CONTROL_CODE/requirements.txt diff --git a/PC_CONTROL_CODE/.gitignore b/PC_CONTROL_CODE/.gitignore new file mode 100644 index 0000000..9a2c773 --- /dev/null +++ b/PC_CONTROL_CODE/.gitignore @@ -0,0 +1 @@ +testing \ No newline at end of file diff --git a/PC_CONTROL_CODE/main.dht22.py b/PC_CONTROL_CODE/main.dht22.py new file mode 100644 index 0000000..ce73ef5 --- /dev/null +++ b/PC_CONTROL_CODE/main.dht22.py @@ -0,0 +1,29 @@ +import time +import board +import adafruit_dht + +# https://randomnerdtutorials.com/raspberry-pi-dht11-dht22-python/ + +# Sensor data pin is connected to GPIO 4 +sensor = adafruit_dht.DHT22(board.D4) +# Uncomment for DHT11 +#sensor = adafruit_dht.DHT11(board.D4) + +while True: + try: + # Print the values to the serial port + temperature_c = sensor.temperature + temperature_f = temperature_c * (9 / 5) + 32 + humidity = sensor.humidity + print("Temp={0:0.1f}ºC, Temp={1:0.1f}ºF, Humidity={2:0.1f}%".format(temperature_c, temperature_f, humidity)) + + except RuntimeError as error: + # Errors happen fairly often, DHT's are hard to read, just keep going + print(error.args[0]) + time.sleep(2.0) + continue + except Exception as error: + sensor.exit() + raise error + + time.sleep(3.0) \ No newline at end of file diff --git a/PC_CONTROL_CODE/main.py b/PC_CONTROL_CODE/main.py new file mode 100644 index 0000000..a4df69b --- /dev/null +++ b/PC_CONTROL_CODE/main.py @@ -0,0 +1,67 @@ +import serial, time + +# CONST +MD1200BAUD = 38400 +SERIALADAPTER = "/dev/ttyUSB0" # In Windows it would be something like COM3 + +# init +MDserial = serial.Serial( + port=SERIALADAPTER,\ + baudrate=MD1200BAUD,\ + parity=serial.PARITY_NONE,\ + stopbits=serial.STOPBITS_ONE,\ + bytesize=serial.EIGHTBITS,\ + timeout=1) + + +# Check if UART is used +# Not neede because when defining MDserial it gets automatically opened +# try: +# MDserial.open() +# except serial.serialutil.SerialException: +# # MDserial.close() +# # MDserial.open() +# print("Port allready opened.\nTry closing it first") + + +def getTemp(): + print() + +def setSpeed(): + print() + +while True: + MDreturning = MDserial.read_until(" >").decode() + + # sleep(50) + MDfanspeed = getTemp(MDreturning) + + setSpeedrcode = setSpeed() + + if setSpeedrcode == 0: + continue + elif setSpeedrcode == -1: + continue + else: + print("o nyo") + exit() + + + + + +# https://stackoverflow.com/questions/52578122/not-able-to-send-the-enter-command-on-pyserial +# MDserial.write("_temp_rd\n\r".encode()) + +# getTemp() +# print(MDserial.read_until(" >")) + +# fanprct = 23 + +# MDserial.write(f"set_speed {fanprct}\n\r".encode()) + + + + +# print("closing port") +# MDserial.close() diff --git a/PC_CONTROL_CODE/requirements.txt b/PC_CONTROL_CODE/requirements.txt new file mode 100644 index 0000000..5a2d725 --- /dev/null +++ b/PC_CONTROL_CODE/requirements.txt @@ -0,0 +1 @@ +pySerial == 3.5 \ No newline at end of file