Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/******************************************************* * 4-CYLINDER ESP32 ECU SYSTEM * * Professional Features: * - 4 injectors and 4 ignition channels * - Dynamic fuel AND ignition maps with customizable RPM range * - Professional web-based tuning interface with dual map editors * - Complete lighting controls (headlights, turns, brakes) * - Real-time sensor monitoring and fail-safes * - Advanced fuel & ignition map editors with 0-RPM to limit range * - Multiple fuel & ignition map support with selection interface * - WORKING 3D visualization and graph views for both maps *******************************************************/ #include
#include
#include
#include
#include
// ==================== CONFIGURATION ==================== const char* ssid = "ESP32_ECU"; const char* password = "tune12345"; // ==================== PIN DEFINITIONS ==================== // Fuel Injectors #define PIN_INJECTOR_1 12 #define PIN_INJECTOR_2 14 #define PIN_INJECTOR_3 27 #define PIN_INJECTOR_4 26 // Ignition Coils #define PIN_IGNITION_1 9 #define PIN_IGNITION_2 13 #define PIN_IGNITION_3 11 #define PIN_IGNITION_4 10 // Lighting Outputs #define PIN_HEADLIGHT 17 #define PIN_HIGHBEAM 16 #define PIN_LEFT_TURN 5 #define PIN_RIGHT_TURN 4 #define PIN_BRAKE_LIGHT 8 // Sensor Inputs #define PIN_O2_SENSOR 32 #define PIN_TPS 33 #define PIN_MAP_SENSOR 34 #define PIN_ENGINE_TEMP 35 #define PIN_RPM 17 // ==================== GLOBAL VARIABLES ==================== AsyncWebServer server(80); // Engine State volatile unsigned long rpmPulseTime = 0; volatile unsigned long lastRpmPulse = 0; float currentRPM = 0; float o2Value = 14.7; float tpsValue = 0; float mapValue = 0; float engineTemp = 20; float batteryVoltage = 12.5; // System State bool systemEnabled = false; bool fuelPumpRunning = false; bool criticalFault = false; String faultMessage = ""; // Injection Tracking unsigned long lastInjectorPulse[4] = {0, 0, 0, 0}; int currentPulseWidth[4] = {0, 0, 0, 0}; unsigned long engineRunTime = 0; // Lighting State bool headlightState = false; bool highbeamState = false; bool leftTurnState = false; bool rightTurnState = false; bool brakeLightState = false; bool hazardState = false; unsigned long turnSignalPreviousMillis = 0; bool turnSignalBlinkState = false; const long turnSignalInterval = 500; // Tuning Parameters struct TuningParams { float fuelMultiplier = 1.0; float ignitionAdvance = 12.0; float targetAFR = 14.7; int rpmLimit = 8000; int tempLimit = 105; int minRPM = 0; int maxRPM = 8000; int rpmStep = 250; int loadStep = 10; String currentTune = "performance"; String fuelType = "gasoline"; }; TuningParams tuning; // Advanced Fuel & Ignition Map Structures #define MAX_RPM_POINTS 100 // Support up to 100 RPM points (0-10000 RPM) #define MAX_LOAD_POINTS 11 // 0-100% in 10% steps + 0% struct FuelMapCell { int pulseWidth; bool learned; float correction; }; struct IgnitionMapCell { float advance; bool learned; float correction; }; struct FuelMap { String name; String description; String fuelType; int rpmPoints[MAX_RPM_POINTS]; int loadPoints[MAX_LOAD_POINTS]; FuelMapCell cells[MAX_RPM_POINTS][MAX_LOAD_POINTS]; int rpmPointCount; int loadPointCount; }; struct IgnitionMap { String name; String description; int rpmPoints[MAX_RPM_POINTS]; int loadPoints[MAX_LOAD_POINTS]; IgnitionMapCell cells[MAX_RPM_POINTS][MAX_LOAD_POINTS]; int rpmPointCount; int loadPointCount; }; FuelMap fuelMap; IgnitionMap ignitionMap; bool isFlashing = false; unsigned long flashStartTime = 0; // Multiple fuel & ignition maps storage #define MAX_FUEL_MAPS 10 #define MAX_IGNITION_MAPS 10 FuelMap fuelMaps[MAX_FUEL_MAPS]; IgnitionMap ignitionMaps[MAX_IGNITION_MAPS]; int currentFuelMapIndex = 0; int currentIgnitionMapIndex = 0; int fuelMapCount = 0; int ignitionMapCount = 0; // Firing order (1-3-4-2 typical for inline-4) const int firingOrder[4] = {0, 2, 3, 1}; // Injector order const int ignitionOrder[4] = {0, 2, 3, 1}; // Ignition order int currentCylinder = 0; unsigned long lastCylinderTime = 0; // ==================== EMBEDDED WEBPAGE ==================== const char index_html[] PROGMEM = R"rawliteral(
Professional 4-Cylinder ECU Tuner
Professional 4-Cylinder ECU Tuner
Advanced Engine Management & Lighting Control
CRITICAL FAULT:
Live Engine Data
Engine RPM
0
RPM
Air/Fuel Ratio
0.00
AFR
Throttle Position
0%
Percentage
Engine Load
0%
MAP
Engine Temp
0°C
Celsius
Battery Voltage
0.0
Volts
System:
OFF
Active Cylinder:
-
Fuel:
gasoline
Tune:
performance
Cylinder Status
Cylinder 1
Pulse:
0
µs
Timing:
0
°
Cylinder 2
Pulse:
0
µs
Timing:
0
°
Cylinder 3
Pulse:
0
µs
Timing:
0
°
Cylinder 4
Pulse:
0
µs
Timing:
0
°
System Controls
Power:
OFF
Fuel Pump:
OFF
Active Tune:
Performance
Balanced performance for street use
Preset Tunes
Economy
Performance
Race
Methanol
Gasoline
Lighting Controls
Headlights
OFF
Toggle
High Beams
OFF
Toggle
Left Turn
OFF
Toggle
Right Turn
OFF
Toggle
Brake Lights
OFF
Toggle
Hazard Lights
OFF
Toggle
Quick Tuning
Fuel Multiplier:
1.00
Ignition Advance:
12.0
Target AFR:
14.7
RPM Limit:
8000
Save Tuning
Load Tuning
Reset Defaults
Map Selection
Fuel Maps
Ignition Maps
Active Fuel Map:
Base Fuel Map
|
Status:
Loaded
Active Ignition Map:
Base Ignition Map
|
Status:
Loaded
Upload Custom Map
Create New Map
Flash Selected to ECU
Professional Map Editor
Fuel Map Editor
Ignition Map Editor
Editing:
Base Fuel Map
Table View
3D View
Graph View
Save Fuel Map
Export Fuel Map
Reset View
Wireframe
Update Fuel Map
Auto-Tune Fuel
Smooth Fuel Map
Reset Fuel Map
Flash Fuel to ECU
Add RPM Point
Remove RPM Point
Export Fuel Map
Import Fuel Map
Editing:
Base Ignition Map
Table View
3D View
Graph View
Save Ignition Map
Export Ignition Map
Reset View
Wireframe
Update Ignition Map
Auto-Tune Ignition
Smooth Ignition Map
Reset Ignition Map
Flash Ignition to ECU
Add RPM Point
Remove RPM Point
Export Ignition Map
Import Ignition Map
Upload Custom Map
Map Type:
Fuel Map
Ignition Map
Map Name:
Description:
Upload
Cancel