From 037bc2dcb2b53c4c0792375692ce3d75defb81d2 Mon Sep 17 00:00:00 2001 From: Benjamin Koch <bbbsnowball@gmail.com> Date: Sat, 6 May 2023 02:44:22 +0200 Subject: [PATCH] test ADC --- firmware/test1/heizung-test1/src/main.cpp | 71 ++++++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/firmware/test1/heizung-test1/src/main.cpp b/firmware/test1/heizung-test1/src/main.cpp index 2951bdd..126e7a9 100644 --- a/firmware/test1/heizung-test1/src/main.cpp +++ b/firmware/test1/heizung-test1/src/main.cpp @@ -246,13 +246,15 @@ void loop() { int displayModePrev = displayMode; static bool prevButton4 = 0; if (!prevButton4 && buttons[3]) { - displayMode = (displayMode + 1) % 5; + displayMode = (displayMode + 1) % 6; } prevButton4 = buttons[3]; if (rp2040.getCycleCount64() > 2 * 133*1000*1000 && displayMode == 0) { - if (displayModePrev != 0) + if (displayModePrev != 0) { + display.fillRect(67, 0, 128-67, 64, SSD1306_BLACK); display.drawBitmap(0, 0, logo_data, logo_width, logo_height, SSD1306_WHITE); + } display.fillRect(0, 0, 67, 64, SSD1306_BLACK); display.setTextSize(1); @@ -356,6 +358,71 @@ void loop() { display.drawFastHLine(0, y++, b/16, SSD1306_WHITE); display.drawFastHLine(0, y++, v/16, SSD1306_WHITE); } + display.display(); + } else if (displayMode == 5) { + display.fillRect(0, 0, 128, 64, SSD1306_BLACK); + display.setTextSize(1); + display.setTextColor(SSD1306_WHITE); + display.setCursor(0, 1); + display.println(F("ADC:")); + + analogReadResolution(12); + + auto v1 = analogRead(ANALOG_IN1); + display.print(F("AIN1: ")); + display.print(v1); + auto ain1 = 3.05*v1/4096 * (10+2*5.1)/5.1; + display.print(F(" -> ")); + display.println(ain1, 2); + + auto v2 = analogRead(CURRENT2); + display.print(F("CUR2: ")); + display.print(v2); + static int32_t avgCurrent2 = 0; + if (!buttons[1] && !buttons[2]) { + //avgCurrent2 = (avgCurrent2*31 + v2)/32; + avgCurrent2 = avgCurrent2*31/32 + v2; + display.print(", "); + display.println(avgCurrent2/32); + } else { + display.print(F(" -> ")); + float current2 = max(0, v2-avgCurrent2/32)*3.05/4096 / 0.1 * 1/56.0; + display.println(current2, 3); + + Serial.print(F("Current2: ")); + Serial.print(v2); + Serial.print(" - "); + Serial.print(avgCurrent2); + Serial.print("/32 -> "); + Serial.println(current2, 5); + } + + auto v3 = analogRead(CURRENT1); + display.print(F("CUR1: ")); + display.print(v3); + static int32_t avgCurrent1 = 0; + if (!buttons[0] && !buttons[2]) { + //avgCurrent1 = (avgCurrent1*31 + v3)/32; + avgCurrent1 = avgCurrent1*31/32 + v3; + display.print(", "); + display.println(avgCurrent1/32); + } else { + display.print(F(" -> ")); + float current1 = max(0, v3-avgCurrent1/32)*3.05/4096 / 0.1 * 1/56.0; + display.println(current1, 3); + } + + auto v4 = analogRead(MEASURE_VCC); + display.print(F("VCC: ")); + display.print(v4); + auto vcc = 3.05*v4/4096 * (100+10)/10; + display.print(F(" -> ")); + display.println(vcc, 2); + + auto v5 = analogReadTemp(3.0); + display.print(F("TEMP: ")); + display.println(v5); + display.display(); } -- GitLab