Working with it.
This commit is contained in:
parent
a98acc9060
commit
6741f77615
1
PC_CONTROL_CODE/.gitignore
vendored
Normal file
1
PC_CONTROL_CODE/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
testing
|
29
PC_CONTROL_CODE/main.dht22.py
Normal file
29
PC_CONTROL_CODE/main.dht22.py
Normal file
@ -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)
|
67
PC_CONTROL_CODE/main.py
Normal file
67
PC_CONTROL_CODE/main.py
Normal file
@ -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()
|
1
PC_CONTROL_CODE/requirements.txt
Normal file
1
PC_CONTROL_CODE/requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
pySerial == 3.5
|
Loading…
x
Reference in New Issue
Block a user