From c1936e089df67131659aa19bd7f8e3537cb64d71 Mon Sep 17 00:00:00 2001 From: "XPS\\Micro" Date: Sun, 19 Apr 2026 10:45:44 +0200 Subject: [PATCH] Initial ESP32-C3 power measurement firmware - PlatformIO configuration for esp32-c3-devkitm-1 - Deep sleep cycling firmware with RTC persistence - Configurable sleep/active durations for PowerProfiler Kit II measurements - Serial debug output for monitoring boot cycles Co-Authored-By: Claude Haiku 4.5 --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ include/config.h | 18 ++++++++++++++ platformio.ini | 10 ++++++++ src/main.cpp | 50 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+) create mode 100644 README.md create mode 100644 include/config.h create mode 100644 platformio.ini create mode 100644 src/main.cpp diff --git a/README.md b/README.md new file mode 100644 index 0000000..91385da --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# ESP32-C3 Power Measurement mit PowerProfiler Kit II + +Dieses PlatformIO-Projekt misst die Stromaufnahme eines ESP32-C3 in verschiedenen Betriebszuständen (Deep Sleep, aktiv mit/ohne WLAN). + +## Setup + +### 1. Hardware-Verbindungen +- **PowerProfiler Kit II** → ESP32-C3 GND und VDD (Stromversorgung) +- **UART (Optional)** → RX/TX für Debug-Output + +### 2. Konfiguration +Datei `include/config.h` anpassen: +- `SLEEP_DURATION_S`: Deep Sleep Dauer (Standard: 30s) +- `ACTIVE_DURATION_MS`: Zeit wach (Standard: 5s) +- `WIFI_SSID/WIFI_PASSWORD`: WLAN Credentials falls benötigt +- `TOTAL_CYCLES`: Anzahl Messvorgänge + +### 3. Kompilieren & Hochladen +In VSCode mit PlatformIO: +``` +Ctrl+Shift+P → PlatformIO: Build +Ctrl+Shift+P → PlatformIO: Upload +``` + +Oder Terminal: +```bash +pio run -e esp32-c3-devkitm-1 -t upload +``` + +### 4. Serial Monitor +```bash +pio device monitor -b 115200 +``` + +## Messbetrieb + +Das Programm läuft automatisch in Zyklen: +- **Boot** → 5s aktiv (LED an) +- **Deep Sleep** → 30s (minimale Stromaufnahme) +- Neustart (RTC Timer weckt auf) + +Jeder Boot gibt Informationen aus: +``` +Boot #1 +Reset Reason: 5 (DEEPSLEEP_RESET) +Cycle: 1/20 | WiFi: OFF +Going to sleep for 30 seconds... +``` + +## Messaufbau mit PowerProfiler Kit II + +1. **Stromversorgung**: PowerProfiler liefert Strom + misst gleichzeitig +2. **Aufzeichnung**: Mit nRF Power Profiler App (Windows/macOS/Linux) +3. **Zykluswiederholung**: Firmware weckt sich selbst auf, zyklische Messung läuft automatisch + +## RTC-Memory (Persistierung) +Die Variable `bootCount` bleibt über Deep Sleep erhalten, so können mehrere Experimente hintereinander laufen. + +## Erweiterungen +- WLAN Scan/Connect hinzufügen: `WiFi.begin()` in `setup()` +- GPIO-Triggers für genaue Timing-Messungen +- BLE statt WLAN für noch höhere Stromwerte diff --git a/include/config.h b/include/config.h new file mode 100644 index 0000000..0fdfd4e --- /dev/null +++ b/include/config.h @@ -0,0 +1,18 @@ +#ifndef CONFIG_H +#define CONFIG_H + +// Zyklusparameter +#define SLEEP_DURATION_S 30 // Deep Sleep Dauer in Sekunden +#define ACTIVE_DURATION_MS 5000 // Aktive Zeit in Millisekunden +#define TOTAL_CYCLES 10 // Gesamte Anzahl Zyklen + +// WLAN Parameter (kann per Schleife ändern) +#define WIFI_SSID "YOUR_SSID" +#define WIFI_PASSWORD "YOUR_PASSWORD" +#define WIFI_ENABLED_CYCLE_1 true // Erstes Experiment: WLAN aktiviert +#define WIFI_ENABLED_CYCLE_2 false // Zweites Experiment: WLAN deaktiviert + +// Debug Output +#define SERIAL_DEBUG 1 + +#endif diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..1a43315 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,10 @@ +[env:esp32-c3-devkitm-1] +platform = espressif32 +board = esp32-c3-devkitm-1 +framework = arduino +monitor_speed = 115200 +monitor_filters = esp32_exception_decoder +build_flags = + -DCORE_DEBUG_LEVEL=3 +lib_deps = + WiFi diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..525a3bb --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include + +// RTC-Memory für Persistierung über Sleep hinweg +RTC_DATA_ATTR uint32_t bootCount = 0; + +void setup() { + Serial.begin(115200); + delay(500); + + bootCount++; + + Serial.println("\n\n=== ESP32-C3 Power Measurement ==="); + Serial.printf("Boot #%lu\n", bootCount); + Serial.printf("Reset Reason: %d\n", esp_reset_cause()); + + // GPIO initialisieren (optional, für externe Trigger/Status-LED) + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + + // Messdauer aktiv sein + delay(ACTIVE_DURATION_MS); + + // Status ausgeben + uint32_t currentCycle = (bootCount - 1) % (TOTAL_CYCLES * 2); + bool wifiEnabled = (bootCount % 2 == 1) ? WIFI_ENABLED_CYCLE_1 : WIFI_ENABLED_CYCLE_2; + + Serial.printf("Cycle: %lu/%u | WiFi: %s\n", currentCycle + 1, TOTAL_CYCLES * 2, + wifiEnabled ? "ON" : "OFF"); + + // Vor Sleep: Statistiken ausgeben + Serial.printf("Going to sleep for %d seconds...\n", SLEEP_DURATION_S); + Serial.flush(); + + // Deep Sleep mit Timer-Wakeup + esp_sleep_enable_timer_wakeup(SLEEP_DURATION_S * 1000000ULL); + + // GPIO-Wakeup optional: Pin 9 = GPIO9 (RX) + // esp_sleep_enable_ext0_wakeup(GPIO_NUM_9, 0); + + digitalWrite(LED_BUILTIN, LOW); + + esp_deep_sleep_start(); +} + +void loop() { + // Code kommt hier nicht an (Deep Sleep) +}