p[roject12 — ESP32 simulation

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by hichemsystem1.

Components

Sketch code

/* =============================================================================
 *  ATS-ESP32-IMPL-001
 *  ESP32 AUTOMATIC TRANSFER SWITCH CONTROLLER  -  STEG / GENERATOR
 *
 *  DESIGNER ENGINEER : Hichem Souki
 *
 *  ---------------------------------------------------------------------------
 *  ARDUINO IDE SETTINGS
 *  ---------------------------------------------------------------------------
 *    Board            : "ESP32 Dev Module"
 *    Partition scheme : "Huge APP (3MB No OTA / 1MB SPIFFS)"
 *                       (required: Wi-Fi + classic Bluetooth in one image)
 *    Flash size       : 4 MB
 *    Upload speed     : 921600 (drop to 115200 if uploads fail)
 *    Core Debug Level : None
 *
 *  LIBRARIES (Library Manager)
 *    - Adafruit SSD1306
 *    - Adafruit GFX Library
 *    - RTClib                (Adafruit)
 *
 *  All other headers come with the ESP32 Arduino core.
 *
 *  COMPILATION
 *    Put every file of this folder in one sketch directory named exactly
 *    ATS_ESP32_Controller. Open ATS_ESP32_Controller.ino and press Verify.
 *
 *  ---------------------------------------------------------------------------
 *  SAFETY - NON NEGOTIABLE
 *  ---------------------------------------------------------------------------
 *    - Mechanical interlock between KM1 and KM2 : MANDATORY.
 *    - Hardwired NC cross-interlock in both coil circuits : MANDATORY.
 *    - This firmware is NOT the protection against source paralleling.
 *    - No mains voltage on any ESP32 pin. Ever.
 *    - VERIFY THE COIL VOLTAGE PRINTED ON BOTH CONTACTORS BEFORE ENERGIZING.
 *    - Final mains connection and energization by a qualified electrician.
 * ===========================================================================*/

#include "Config.h"
#include "Types.h"
#include "Settings.h"
#include "Io.h"
#include "Faults.h"
#include "Transfer.h"
#include "GenIface.h"
#include "AtsCore.h"
#include "Clock.h"
#include "Ui.h"
#include "Net.h"

#include <Wire.h>
#include <esp_task_wdt.h>

static uint32_t s_lastScan = 0;

/* ---------------------------------------------------------------------------
 * Watchdog helper - compatible with ESP32 Arduino core 2.x and 3.x
 * -------------------------------------------------------------------------*/
static void watchdogBegin() {
#if defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 3)
  esp_task_wdt_config_t cfg = {
    .timeout_ms     = WDT_TIMEOUT_S * 1000U,
    .idle_core_mask = 0,
    .trigger_panic  = true
  };
  esp_task_wdt_reconfigure(&cfg);
#else
  esp_task_wdt_init(WDT_TIMEOUT_S, true);
#endif
  esp_task_wdt_add(NULL);
}

/* ===========================================================================
 *  SETUP
 * ===========================================================================*/
void setup() {
  Serial.begin(115200);
  delay(50);
  Serial.println();
  Serial.println(F("=============================================="));
  Serial.printf ("  %s  %s  (%s)\n", FW_NAME, FW_VERSION, FW_DOC