commit 14d4cfb94389a9f77fd143b0f520bf507fd53052 Author: Padrino Date: Thu Jun 4 18:00:54 2026 +0200 Initial commit: mata avispas Arduino code and README diff --git a/README.md b/README.md new file mode 100644 index 0000000..4dade64 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# mata avispas + +Flyback high voltage generator (≈12 kV output) controlled by an ESP32‑C3. + +Features +- ESP32‑C3 runs as a Wi‑Fi Access Point (AP) so you can connect directly to it. +- A simple web server lets you adjust the PWM frequency/duty cycle that drives the XY‑MOS driver. +- PWM output is generated on a GPIO using the LEDC hardware (high‑resolution, glitch‑free). +- Safety: the PWM can be disabled via the web page. + +Hardware notes +- XY‑MOS driver expects a PWM signal (typically 5 V logic) on its INPUT pin. +- Connect ESP32‑C3 GPIO to XY‑MOS INPUT through a level‑shifter if needed (ESP32‑C3 is 3.3 V tolerant, most XY‑MOS accept 3.3 V). +- Flyback transformer secondary should be properly insulated and terminated with a high‑voltage diode/Cockcroft‑Walton multiplier if you need DC. +- Always use proper shielding, grounding, and never touch the output while powered. + +How to build +1. Install the ESP32 Arduino core (Boards Manager → esp32 by Espressif Systems). +2. Select "ESP32C3 Dev Module" (or your specific board). +3. Copy this folder to your Arduino sketchbook or open with PlatformIO/VSCode. +4. Compile and upload. +5. After upload, the ESP32‑C3 will start an AP named `MataAvispas_AP` (password `avispas123`). +6. Connect your phone/laptop to that AP, open a browser to `http://192.168.4.1` and adjust PWM. + +License: MIT – feel free to adapt. \ No newline at end of file diff --git a/mata_avispas.ino b/mata_avispas.ino new file mode 100644 index 0000000..26b213f --- /dev/null +++ b/mata_avispas.ino @@ -0,0 +1,229 @@ +/* + * mata avispas – Flyback high voltage generator controller + * ESP32‑C3 as Access Point + Web server to configure PWM driving an XY‑MOS driver + * + * PWM output: GPIO2 (adjustable via LEDC) + * Web page: http://192.168.4.1 + * AP SSID: MataAvispas_AP + * AP Password: avispas123 + * + * The page lets you set: + * - Frequency (Hz) : 100 – 20000 + * - Duty cycle (%) : 0 – 100 + * - Enable/Disable output + * + * Uses the ESP32 Arduino core (https://github.com/espressif/arduino-esp32) + */ + +#include +#include + +// ==== USER SETTINGS ==== +const char* AP_SSID = "MataAvispas_AP"; +const char* AP_PASSWORD = "avispas123"; +const uint8_t PWM_GPIO = 2; // XY‑MOS INPUT pin +const uint8_t PWM_CHANNEL = 0; // LEDC channel 0 +const uint8_t PWM_RESOLUTION = 10; // 10‑bit resolution => 0‑1023 +// ======================= + +WebServer server(80); + +// Current PWM state +uint32_t pwmFrequency = 1000; // default 1 kHz +uint32_t pwmDuty = 512; // 50 % of 1023 +bool pwmEnabled = false; + +// HTML page (stored in PROGMEM to save RAM) +const char INDEX_HTML[] PROGMEM = R"rawliteral( + + + + + Mata Avispas – PWM Config + + + +
+

Mata Avispas

+
PWM: OFF
+ + + + Range: 100 – 20000 Hz + + + + 50% + + + + + +
+ + + + +)rawliteral"; + +void handleRoot() { + server.send_P(200, "text/html", INDEX_HTML, strlen_P(INDEX_HTML)); +} + +void handleGet() { + String json = "{"; + json += "\"freq\":" + String(pwmFrequency) + ","; + json += "\"duty\":" + String(map(pwmDuty, 0, (1<= 0) { + String sub = body.substring(idx + 7); + freq = sub.substring(0, sub.indexOf(",")).toInt(); + } + idx = body.indexOf("\"duty\":"); + if (idx >= 0) { + String sub = body.substring(idx + 7); + duty = sub.substring(0, sub.indexOf(",")).toInt(); + } + idx = body.indexOf("\"en\":"); + if (idx >= 0) { + String sub = body.substring(idx + 5); + en = sub.substring(0, sub.indexOf("}")).toInt(); + } + + // Clamp values + if (freq < 100) freq = 100; + if (freq > 20000) freq = 20000; + if (duty < 0) duty = 0; + if (duty > 100) duty = 100; + + // Update PWM + pwmFrequency = freq; + pwmDuty = map(duty, 0, 100, 0, (1<