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 <noreply@anthropic.com>
This commit is contained in:
commit
c1936e089d
62
README.md
Normal file
62
README.md
Normal file
|
|
@ -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
|
||||
18
include/config.h
Normal file
18
include/config.h
Normal file
|
|
@ -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
|
||||
10
platformio.ini
Normal file
10
platformio.ini
Normal file
|
|
@ -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
|
||||
50
src/main.cpp
Normal file
50
src/main.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_sleep.h>
|
||||
#include <config.h>
|
||||
|
||||
// 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)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user