Compare commits
	
		
			No commits in common. "964236b6b5d962b72ed6804bd582d4e91ea23817" and "6741f776156a63b20eac9be3bb45ee8b2db57099" have entirely different histories.
		
	
	
		
			964236b6b5
			...
			6741f77615
		
	
		
							
								
								
									
										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) | ||||
| @ -2,11 +2,7 @@ import serial, time | ||||
| 
 | ||||
| # CONST | ||||
| MD1200BAUD = 38400 | ||||
| SERIALADAPTER = "/dev/ttyUSB0" | ||||
| GETTEMP = "_temp_rd" | ||||
| SETFANPRCNT = "set_speed" | ||||
| EPYSLEEPY = 300  # 5 minutes | ||||
| #EPYSLEEPY = 150  # 2,5 minutes | ||||
| SERIALADAPTER = "/dev/ttyUSB0"  # In Windows it would be something like COM3 | ||||
| 
 | ||||
| # init | ||||
| MDserial = serial.Serial( | ||||
| @ -18,81 +14,8 @@ MDserial = serial.Serial( | ||||
|     timeout=1) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| def getTemp(inpMDreturning): | ||||
|     MDict = {} | ||||
| 
 | ||||
|     # Sanitise output | ||||
|     MDsanit = inpMDreturning.splitlines() | ||||
| 
 | ||||
|     #if there is smth do smth | ||||
|     if inpMDreturning: | ||||
| 
 | ||||
|         for line in MDsanit: | ||||
|              | ||||
|             if ">" in line or "b'" in line: | ||||
|                 continue | ||||
| 
 | ||||
|             matchstm = line[2:6] | ||||
| 
 | ||||
|             match matchstm: | ||||
|                 case "BP_1": | ||||
|                     MDict["bp1"] = int(line[12:14]) | ||||
|                 case "BP_2": | ||||
|                     MDict["bp2"] = int(line[12:14]) | ||||
|                 case "SIM0": | ||||
|                     MDict["sim0"] = int(line[12:14]) | ||||
|                 case "SIM1": | ||||
|                     MDict["sim1"] = int(line[12:14]) | ||||
|                 case "EXP0": | ||||
|                     MDict["exp0"] = int(line[12:14]) | ||||
|                 case "EXP1": | ||||
|                     MDict["exp1"] = int(line[12:14]) | ||||
|                 case "AVG": | ||||
|                     MDict["avg"] = int(line[12:14]) | ||||
|                 case _: | ||||
|                     continue | ||||
| 
 | ||||
|         return MDict | ||||
| 
 | ||||
| 
 | ||||
| def setSpeed(inSpeeDict: dict): | ||||
| 
 | ||||
|     bpavrg = 0 | ||||
|     # Some safe fan speedvalue | ||||
|     defoutprntg = 27 | ||||
|     # default | ||||
|     outfanprcntg = 0 | ||||
| 
 | ||||
|     # Decide on fan speeds | ||||
|     LOW_FAN_TRSHD = 21 | ||||
|     HIGH_FAN_TRSHD = 40 | ||||
|     TEMP_FACTOR = 21 | ||||
| 
 | ||||
|     # get backplanbe average  | ||||
|     if inSpeeDict["bp1"] and inSpeeDict["bp2"]: | ||||
|         bpavrg = (inSpeeDict["bp1"] + inSpeeDict["bp2"]) /2 | ||||
| 
 | ||||
|         outfanprcntg = int((bpavrg / (HIGH_FAN_TRSHD - LOW_FAN_TRSHD)) * TEMP_FACTOR) | ||||
| 
 | ||||
|     # Set fan speed | ||||
|     if outfanprcntg >= 20: | ||||
|         MDserial.write(("set_speed " + str(outfanprcntg) + " \n\r").encode())   | ||||
|         print(f"setting {outfanprcntg}%") | ||||
|         return 0 | ||||
|     else: | ||||
|         # Set default value | ||||
|         MDserial.write(("set_speed " + str(defoutprntg) + " \n\r").encode())   | ||||
|         return 1 | ||||
|      | ||||
|     # If something goes super wrong | ||||
|     return -1 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # Check if UART is used | ||||
| # Not neede because when defining MDserial it gets automatically opened | ||||
| # Will leave it here anyway | ||||
| # try: | ||||
| #     MDserial.open() | ||||
| # except serial.serialutil.SerialException: | ||||
| @ -100,32 +23,45 @@ def setSpeed(inSpeeDict: dict): | ||||
| #     # MDserial.open() | ||||
| #     print("Port allready opened.\nTry closing it first") | ||||
| 
 | ||||
| 
 | ||||
| def getTemp(): | ||||
|     print() | ||||
| 
 | ||||
| def setSpeed(): | ||||
|     print() | ||||
| 
 | ||||
| while True: | ||||
|     # https://stackoverflow.com/questions/52578122/not-able-to-send-the-enter-command-on-pyserial | ||||
|     MDserial.write("_temp_rd\n\r".encode()) | ||||
|     time.sleep(1) | ||||
|     MDreturning = MDserial.read_until(" >").decode() | ||||
| 
 | ||||
|     MDtempDict = getTemp(MDreturning) | ||||
|     setSpeedrcode = setSpeed(MDtempDict) | ||||
|     # sleep(50) | ||||
|     MDfanspeed = getTemp(MDreturning) | ||||
| 
 | ||||
|     setSpeedrcode = setSpeed() | ||||
| 
 | ||||
|     # good | ||||
|     if setSpeedrcode == 0: | ||||
|         # print("Were mint") | ||||
|         time.sleep(EPYSLEEPY) | ||||
|     # not good | ||||
|     elif setSpeedrcode == 1: | ||||
|         print("Ambigous temperature readings.\nFalling back to safe values.") | ||||
|         time.sleep(EPYSLEEPY) | ||||
|     # very not good | ||||
|         continue | ||||
|     elif setSpeedrcode == -1: | ||||
|         continue | ||||
|     else: | ||||
|         print("o nyo") | ||||
|         exit() | ||||
|     # very very very not good | ||||
|     else: | ||||
|         print("idk") | ||||
|         exit() | ||||
| 
 | ||||
| 
 | ||||
| print("closing port") | ||||
| MDserial.close() | ||||
| 
 | ||||
|      | ||||
| 
 | ||||
| # 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,226 +0,0 @@ | ||||
| import serial, time | ||||
| 
 | ||||
| # CONST | ||||
| MD1200BAUD = 38400 | ||||
| SERIALADAPTER = "/dev/ttyUSB0" | ||||
| GETTEMP = "_temp_rd" | ||||
| SETFANPRCNT = "set_speed" | ||||
| EPYSLEEPY = 300  # 5 minutes | ||||
| #EPYSLEEPY = 150  # 2,5 minutes | ||||
| 
 | ||||
| # init | ||||
| # MDserial = serial.Serial( | ||||
| #     port=SERIALADAPTER,\ | ||||
| #     baudrate=MD1200BAUD,\ | ||||
| #     parity=serial.PARITY_NONE,\ | ||||
| #     stopbits=serial.STOPBITS_ONE,\ | ||||
| #     bytesize=serial.EIGHTBITS,\ | ||||
| #     timeout=1) | ||||
| 
 | ||||
| # After running .encode() on output | ||||
| MDreturn = "b'\r\nBlueDress.105.001 >_temp_rd\r\n\r\n  BP_1[2] = 24c\r\n  BP_2[3] = 24c\r\n  SIM0[0] = 26c\r\n  SIM1[1] = 29c\r\n  EXP0[4] = 43c\r\n  EXP1[5] = 47c\r\n\r\n  AVG = 32c\r\n\r\nBlueDress.105.001 >'" | ||||
| # before running .encode() on output | ||||
| TrueMDeturn = MDreturn.encode() | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| def getTemp(inpMDreturning): | ||||
|     # bp1 = 0 | ||||
|     # bp2 = 0 | ||||
|     # exp0 = 0 | ||||
|     # exp1 = 0 | ||||
|     # simm0 = 0 | ||||
|     # simm1 = 0 | ||||
|     # averr = 0 | ||||
|     MDict = {} | ||||
| 
 | ||||
|     # print("1") | ||||
| 
 | ||||
|     # Sanitise output | ||||
|     MDsanit = inpMDreturning.splitlines() | ||||
| 
 | ||||
|     #if there is smth do smth | ||||
|     if inpMDreturning: | ||||
|         # print("2") | ||||
| 
 | ||||
|         # print(MDsanit) | ||||
|         for line in MDsanit: | ||||
|             # print(line) | ||||
|              | ||||
|             if ">" in line or "b'" in line: | ||||
|                 continue | ||||
| 
 | ||||
|             # print(line[2:]) | ||||
|             # if "BP_1" in line[2:]: | ||||
|             #     print("yeeee") | ||||
| 
 | ||||
|             matchstm = line[2:6] | ||||
| 
 | ||||
|             # print(matchstm) | ||||
| 
 | ||||
|             match matchstm: | ||||
|                 case "BP_1": | ||||
|                     # print("BP_1 " + line[12:14]) | ||||
|                     # bp1 = line[12:14] | ||||
|                     MDict["bp1"] = int(line[12:14]) | ||||
|                 case "BP_2": | ||||
|                     # print("BP_2 " + line[12:14]) | ||||
|                     # bp2 = line[12:14] | ||||
|                     MDict["bp2"] = int(line[12:14]) | ||||
|                 case "SIM0": | ||||
|                     # print("SIM0 " + line[12:14]) | ||||
|                     # simm0 = line[12:14] | ||||
|                     MDict["sim0"] = int(line[12:14]) | ||||
|                 case "SIM1": | ||||
|                     # print("SIM1 " + line[12:14]) | ||||
|                     # simm1 = line[12:14] | ||||
|                     MDict["sim1"] = int(line[12:14]) | ||||
|                 case "EXP0": | ||||
|                     # print("EXP0 " + line[12:14]) | ||||
|                     # exp0 = line[12:14] | ||||
|                     MDict["exp0"] = int(line[12:14]) | ||||
|                 case "EXP1": | ||||
|                     # print("EXP1 " + line[12:14]) | ||||
|                     # exp1 = line[12:14] | ||||
|                     MDict["exp1"] = int(line[12:14]) | ||||
|                 case "AVG": | ||||
|                     # print("AVG " + line[12:14]) | ||||
|                     # averr = line[12:14] | ||||
|                     MDict["avg"] = int(line[12:14]) | ||||
|                 case _: | ||||
|                     print("ay men") | ||||
|                     # continue | ||||
| 
 | ||||
|             # for thing in line.split(" ")[2:]: | ||||
|             #     print(thing) | ||||
|             # print(line[12:14]) | ||||
|         # print(MDsanit.split("\n")) | ||||
| 
 | ||||
|         return MDict | ||||
|         # print(MDict) | ||||
| 
 | ||||
| 
 | ||||
| # for key, thing in getTemp(MDreturn).items(): | ||||
| #     print(key, thing) | ||||
| 
 | ||||
| def setSpeed(inSpeeDict: dict): | ||||
|     print("skibidi") | ||||
| 
 | ||||
|     bpavrg = 0 | ||||
|     # Some safe fan speedvalue | ||||
|     defoutprntg = 27 | ||||
|     # default | ||||
|     outfanprcntg = 0 | ||||
| 
 | ||||
|     # Decide on fan speeds | ||||
|     LOW_FAN_TRSHD = 21 | ||||
|     HIGH_FAN_TRSHD = 40 | ||||
|     TEMP_FACTOR = 21 | ||||
| 
 | ||||
|     # DEBUG | ||||
|     # for key, thing in inSpeeDict.items(): | ||||
|     #     print(key, thing) | ||||
| 
 | ||||
|     # get backplanbe average  | ||||
|     if inSpeeDict["bp1"] and inSpeeDict["bp2"]: | ||||
|         bpavrg = (inSpeeDict["bp1"] + inSpeeDict["bp2"]) /2 | ||||
| 
 | ||||
| 
 | ||||
|         outfanprcntg = int((bpavrg / (HIGH_FAN_TRSHD - LOW_FAN_TRSHD)) * TEMP_FACTOR) | ||||
|         print(f"outfanprcntg is {outfanprcntg}") | ||||
| 
 | ||||
|     # Set fan speed | ||||
|     if outfanprcntg >= 20: | ||||
|         # MDserial.write(("set_speed " + str(outfanprcntg) + " \n\r").encode())   | ||||
|         return 0 | ||||
|     else: | ||||
|         # Set default value | ||||
|         # MDserial.write(("set_speed " + str(defoutprntg) + " \n\r").encode())   | ||||
|         return 1 | ||||
|      | ||||
|     # If something goes super wrong | ||||
|     return -1 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| while True: | ||||
| # if True: | ||||
|     # MDserial.write("_temp_rd\n\r".encode()) | ||||
| 
 | ||||
|     # CHANGE AFTER TESTING  | ||||
|     # MDreturning = MDserial.read_until(" >").decode() | ||||
|     MDreturning = MDreturn | ||||
| 
 | ||||
|     # sleep(50) | ||||
| 
 | ||||
|     MDtempDict = getTemp(MDreturning) | ||||
| 
 | ||||
|     # setSpeed(MDtempDict) | ||||
| 
 | ||||
|     setSpeedrcode = setSpeed(MDtempDict) | ||||
| 
 | ||||
|     # good | ||||
|     if setSpeedrcode == 0: | ||||
|         print("Were mint") | ||||
|         time.sleep(EPYSLEEPY) | ||||
|     # not good | ||||
|     elif setSpeedrcode == 1: | ||||
|         print("Ambigous temperature readings.\nFalling back to safe values.") | ||||
|         time.sleep(EPYSLEEPY) | ||||
|     # very not good | ||||
|     elif setSpeedrcode == -1: | ||||
|         print("o nyo") | ||||
|         exit() | ||||
|     # very very very not good | ||||
|     else: | ||||
|         print("idk") | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| # def getTemp(): | ||||
| #     bp1 = 0 | ||||
| #     bp2 = 0 | ||||
| #     #exp0 = 0 | ||||
| #     #exp1 = 0 | ||||
| #     #simm0 = 0 | ||||
| #     #simm1 = 0 | ||||
| #     getMD1200tempReturn = "" | ||||
| 
 | ||||
| #     MDserial.write(GETTEMP.encode()) | ||||
|      | ||||
| #     print(MDserial.readlines()) | ||||
| 
 | ||||
| #     MDreturning = MDserial.readlines().decode() | ||||
| #     #if there is smth do smth | ||||
| #     if len(MDreturning) >= 1: | ||||
| #         print("skibidi") | ||||
| #         return MDreturning | ||||
| 
 | ||||
| # try: | ||||
| #     MDserial.open() | ||||
| # except serial.serialutil.SerialException: | ||||
| #     print("Port allready opened.\nTry closing it first") | ||||
|      | ||||
| 
 | ||||
| # # https://stackoverflow.com/questions/52578122/not-able-to-send-the-enter-command-on-pyserial | ||||
| # MDserial.write("_temp_rd\n\r".encode()) | ||||
| 
 | ||||
| 
 | ||||
| # print(MDserial.read_until(" >")) | ||||
| 
 | ||||
| # fanprct = 23 | ||||
| 
 | ||||
| # MDserial.write(f"set_speed {fanprct}\n\r".encode()) | ||||
| 
 | ||||
| # MDserial.close() | ||||
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								README.md
									
									
									
									
									
								
							| @ -1,24 +1,8 @@ | ||||
| # MD1200 fan noise reduction  | ||||
| # Python scripts for changing fan speed on MD1200 | ||||
| 
 | ||||
| A set of scripts that automagically set fan speed on a MD1200 (probably MD1220 as well) based on internal temperature readings. | ||||
| This adjusts fan speed "dynamically" based on average backplane temperature reading. | ||||
| 
 | ||||
| ## PC | ||||
| 
 | ||||
| Working working working.  | ||||
| 
 | ||||
| So far seems to work. | ||||
| 
 | ||||
| ## STM32F103C6T6 | ||||
| 
 | ||||
| I think it needs a MAX2323 between MD1200. | ||||
| 
 | ||||
| Will look into that. | ||||
| 
 | ||||
| ## Arduino Nano | ||||
| 
 | ||||
| Same here | ||||
| 
 | ||||
| 
 | ||||
| ### FAQ | ||||
| 
 | ||||
| dc: yuruc3 | ||||
| ## STM32F103C6T6 | ||||
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 12 MiB | 
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user