Also propably needs a MAX2323 to work.

This commit is contained in:
YuruC3 2025-05-10 10:19:10 +02:00
parent 8525da4004
commit a17eb70ce0
5 changed files with 67 additions and 19 deletions

10
STM32_CONTROL/.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

View File

@ -13,6 +13,8 @@ platform = ststm32
board = genericSTM32F103C6 board = genericSTM32F103C6
framework = arduino framework = arduino
lib_deps = adafruit/DHT sensor library@^1.4.6 lib_deps = adafruit/DHT sensor library@^1.4.6
debug_tool = stlink
upload_protocol = stlink upload_protocol = stlink
; Enable RX and TX 3 ; Enable RX and TX 3
; build_flags = -D SERIAL_USB -D ENABLE_HWSERIAL3 ; build_flags = -D SERIAL_USB -D ENABLE_HWSERIAL1 -D ENABLE_HWSERIAL2
; build_flags = -DENABLE_HWSERIAL1

View File

@ -0,0 +1,22 @@
#include <Arduino.h>
// UART2 (PA3 = RX, PA2 = TX)
HardwareSerial mdSerial(PA10, PA9);
// HardwareSerial sigma(PA9, )
void setup() {
mdSerial.begin(38400);
}
void loop() {
mdSerial.write("skibidi");
delay(5000); // wait before next loop
}

View File

@ -6,7 +6,9 @@ const int MD1200BAUDS = 38400; // From what I've read it is always 38400
//const int EPYSLEEPY = 600000; / 10 minutes //const int EPYSLEEPY = 600000; / 10 minutes
const int EPYSLEEPY = 300000; // 5 minutes const int EPYSLEEPY = 300000; // 5 minutes
//const int EPYSLEEPY = 150000; // 2,5 minutes //const int EPYSLEEPY = 150000; // 2,5 minutes
HardwareSerial Serial1(31, 30); HardwareSerial MDSerial(PA3, PA2); // Rx Tx
HardwareSerial DeBug(PA10, PA9); // Rx Tx
// HardwareSerial DeBug(USART1); // use USART1
// declarations // declarations
int getTemp(); int getTemp();
@ -14,19 +16,23 @@ int setFanTrsh(int);
void setup() { void setup() {
// Setup connection to MD1200 // Setup connection to MD1200
// Serial1 because we're using RX/TX pins // MDSerial because we're using RX/TX pins
Serial1.begin(MD1200BAUDS); MDSerial.begin(MD1200BAUDS);
// Just debug // Just debug
Serial.begin(9600); DeBug.begin(9600);
Serial.print("skibidi"); DeBug.println("skibidi");
delay(15000);
} }
void loop() { void loop() {
DeBug.println("Starting loop");
int fanPercnt = getTemp(); int fanPercnt = getTemp();
if (fanPercnt < 10) { if (fanPercnt < 10) {
DeBug.println("Executing setFanTrsh");
setFanTrsh(fanPercnt); setFanTrsh(fanPercnt);
} }
@ -35,11 +41,12 @@ void loop() {
set fan speed every X minutes set fan speed every X minutes
*/ */
delay(EPYSLEEPY); delay(EPYSLEEPY);
DeBug.println("Ending loop");
} }
// Get current temperature // Get current temperature
int getTemp() { int getTemp() {
DeBug.println("Getting Temperature");
int bp1 = 0; int bp1 = 0;
int bp2 = 0; int bp2 = 0;
@ -49,13 +56,13 @@ int getTemp() {
int simm1 = 0; int simm1 = 0;
String MD1200output; String MD1200output;
Serial1.println("_temp_rd"); MDSerial.println("_temp_rd");
// wait for MD1200 to answer // wait for MD1200 to answer
delay(30); delay(30);
DeBug.println("getTemp logic start");
while (Serial1.available()) { while (MDSerial.available()) {
MD1200output = Serial1.readStringUntil('\n'); MD1200output = MDSerial.readStringUntil('\n');
// Check backplane 1 // Check backplane 1
if (MD1200output.startsWith("BP_1")) { if (MD1200output.startsWith("BP_1")) {
@ -126,6 +133,7 @@ int getTemp() {
// Stop when prompt returns // Stop when prompt returns
if (MD1200output.endsWith(">")) { if (MD1200output.endsWith(">")) {
DeBug.println("getTemp got all temp info");
break; break;
} }
} }
@ -138,6 +146,7 @@ int getTemp() {
int outPrcntg = 21; int outPrcntg = 21;
// a // a
DeBug.println("getTemp choosing fan speed");
switch (bpAvg) { switch (bpAvg) {
case 23: case 23:
outPrcntg = 21; outPrcntg = 21;
@ -170,8 +179,11 @@ int getTemp() {
default: default:
return -1; return -1;
DeBug.println("getTemp error returning -1");
} }
DeBug.println("getTemp return " + String(outPrcntg));
return outPrcntg; return outPrcntg;
@ -195,9 +207,9 @@ int getTemp() {
int setFanTrsh(int fanTrshInp) { int setFanTrsh(int fanTrshInp) {
String outputStatement = "set_speed " + String(fanTrshInp); String outputStatement = "set_speed " + String(fanTrshInp);
Serial.println("Sending " + outputStatement + " to MD1200"); DeBug.println("Sending " + outputStatement + " to MD1200");
if (Serial1.println(outputStatement)) { if (MDSerial.println(outputStatement)) {
return 1; return 1;
} }
else { else {

View File

@ -2,6 +2,7 @@
#include <Adafruit_Sensor.h> #include <Adafruit_Sensor.h>
#include <DHT.h> #include <DHT.h>
#include <DHT_U.h> #include <DHT_U.h>
#include <HardwareSerial.h>
// ------------------------------------------------------------- // -------------------------------------------------------------
// DHT PreConfiguration // DHT PreConfiguration
@ -22,6 +23,7 @@ const int MD1200BAUDS = 38400; // From what I've read it is always 38400
//const int EPYSLEEPY = 600000; / 10 minutes //const int EPYSLEEPY = 600000; / 10 minutes
const int EPYSLEEPY = 300000; // 5 minutes const int EPYSLEEPY = 300000; // 5 minutes
//const int EPYSLEEPY = 150000; // 2,5 minutes //const int EPYSLEEPY = 150000; // 2,5 minutes
HardwareSerial MDSerial(PA3, PA2); // Rx Tx
// declarations // declarations
int getTemp(); int getTemp();
@ -30,8 +32,8 @@ float dhtRead();
void setup() { void setup() {
// Setup connection to MD1200 // Setup connection to MD1200
// Serial1 because we're using RX/TX pins // MDSerial because we're using RX/TX pins
Serial1.begin(MD1200BAUDS); MDSerial.begin(MD1200BAUDS);
// Just debug // Just debug
Serial.begin(9600); Serial.begin(9600);
@ -66,13 +68,13 @@ int getTemp() {
int simm1 = 0; int simm1 = 0;
String MD1200output; String MD1200output;
Serial1.println("_temp_rd"); MDSerial.println("_temp_rd");
// wait for MD1200 to answer // wait for MD1200 to answer
delay(30); delay(30);
while (Serial1.available()) { while (MDSerial.available()) {
MD1200output = Serial1.readStringUntil('\n'); MD1200output = MDSerial.readStringUntil('\n');
// Check backplane 1 // Check backplane 1
if (MD1200output.startsWith("BP_1")) { if (MD1200output.startsWith("BP_1")) {
@ -221,7 +223,7 @@ int setFanTrsh(int fanTrshInp) {
Serial.println("Sending " + outputStatement + " to MD1200"); Serial.println("Sending " + outputStatement + " to MD1200");
if (Serial1.println(outputStatement)) { if (MDSerial.println(outputStatement)) {
return 1; return 1;
} }
else { else {