Skip to content

Latest commit

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ESP32 Body Controller

GitHub: Carputer-project/esp32_body_controller

TCP command server for body control — HVAC relays, door locks, windows, fan speed, remote start, and Kenwood radio I2C sniffer. Runs on Adafruit Feather ESP32.

Role

Creates the Carputer_ECU WiFi access point (192.168.4.1) and listens for TCP commands on port 5000. Controls all body electronics via ULN2003A relay drivers. Sniffs the Kenwood radio's I2C bus to capture volume knob changes.

Network

ParameterValue
WiFi ModeAP (Access Point)
AP SSIDCarputer_ECU
AP Password12345678
AP IP / Gateway192.168.4.1
Subnet255.255.255.0
TCP server port5000 (commands from carputer app)
Mesh UDP port5010 (V2V mesh broadcast)
Status push interval2000ms

Relay Wiring (via ULN2003A Darlington Arrays)

Two ULN2003A driver ICs handle all relay switching. ULN2003A provides open-collector outputs with built-in flyback diodes for inductive loads.

ULN2003A #1 — Body Relays

ESP32 GPIOFunctionRelayWire ToNotes
GPIO 25Door LockLOCK relayCoil+ to ULN2003A #1 pin 1HIGH = locked
GPIO 26Window UpWIN_UP relayCoil+ to ULN2003A #1 pin 2Pulse 500ms HIGH then LOW
GPIO 27Window DownWIN_DN relayCoil+ to ULN2003A #1 pin 3Pulse 500ms HIGH then LOW
GPIO 32Extra 1EXTRA1 relayCoil+ to ULN2003A #1 pin 4Generic (interior light bridge)
GPIO 33Extra 2EXTRA2 relayCoil+ to ULN2003A #1 pin 5Door chime buzzer (pulse 200ms) / Siren

ULN2003A #2 — HVAC & Fan Relays

ESP32 GPIOFunctionRelayWire ToNotes
GPIO 2HVAC RelayHVAC relayCoil+ to ULN2003A #2 pin 1HIGH = HVAC on
GPIO 4AC RelayAC relayCoil+ to ULN2003A #2 pin 2HIGH = AC on
GPIO 5Remote StartRSTART relayCoil+ to ULN2003A #2 pin 3HIGH = remote start active
GPIO 18Fan 1 RelayFAN1 relayCoil+ to ULN2003A #2 pin 4Speed 1 = HIGH
GPIO 12Fan 2 RelayFAN2 relayCoil+ to ULN2003A #2 pin 5Speed 2 = HIGH

Fan speed logic:

SpeedGPIO 18 (FAN1)GPIO 12 (FAN2)
0 (off)LOWLOW
1HIGHLOW
2HIGHHIGH

ULN2003A Wiring

ULN2003A Pin 1-7 (IN1-IN7) ← ESP32 GPIO (via 1KΩ series resistor recommended)
ULN2003A Pin 8 (GND) → Common GND
ULN2003A Pin 9 (COM) → +12V (relay coil supply)
ULN2003A Pin 10-16 (OUT1-OUT7) → Relay coil negative side
Relay coil positive side → +12V

Kenwood Radio (TEA6320T) — I2C Sniffer

ESP32 PinWire ToFunction
GPIO 21TEA6320T SDA (pin 22 on TEA6320T)I2C data — sniffer mode
GPIO 19TEA6320T SCL (pin 21 on TEA6320T)I2C clock — sniffer mode
GNDRadio chassis GNDCommon ground

I2C Configuration:

  • Address: 0x40 (7-bit), 0x80 (8-bit write)
  • Bus speed (hybrid master): 50 kHz
  • Sniffer: GPIO interrupt-driven, monitors MICOM writes to TEA6320T

TEA6320T Register Map

RegAddressFunctionRange
VOLUME0x00Volume + LoudnessdB+43: -31dB(12) to +20dB(63). Bit 6: LOFF
FFR0x01Front-Right fader0-15 (0=off)
FFL0x02Front-Left fader0-15 (0=off)
FRR0x03Rear-Right fader0-15 (0=off)
FRL0x04Rear-Left fader0-15 (0=off)
BASS0x05Bass0-31 (16=flat)
TREBLE0x06Treble0-31 (16=flat)
SWITCH0x07Source + Mute[GMU][X][X][X][X][SC2][SC1][SC0]

Source select (SC bits): 0=CD(A), 1=B, 2=AUX(C), 3=D, 4=E, 5=Mono

AUX Input C Wiring

Audio Source ──[1µF]──┬── TEA6320T pin 13 (L) / pin 20 (R)
│
[47kΩ]
│
GND

Hybrid Write Mode

ESP32 normally sniffs I2C via GPIO interrupts. When app sends radio command:

  1. Disable ISR
  2. Wire.begin(50kHz) — switch to master mode
  3. Write register to TEA6320T (~20ms)
  4. Wire.end() — release bus
  5. Reconfigure GPIO as input with pullup
  6. Re-enable ISR — resume sniffing

Knob Behavior

Knob ActionESP32 OutputCarputer Effect
Turn right (vol up)J:R + VOL:<dB>Navigate right + media volume up
Turn left (vol down)J:L + VOL:<dB>Navigate left + media volume down
Push (select)J:SSelect/enter (requires solder wire to GPIO13)

Joypad Inputs

ESP32 GPIOFunctionTypeNotes
GPIO 36Joystick YAnalog (ADC)<1200=down, >2800=up, 250ms debounce
GPIO 39Joystick XAnalog (ADC)<1200=left, >2800=right, 250ms debounce
GPIO 22SELECT buttonINPUT_PULLUPActive LOW
GPIO 23EXIT buttonINPUT_PULLUPActive LOW
GPIO 13Radio Knob PushINPUT_PULLUPActive LOW, sends J:S (solder wire required)

Available Free Pins

For future expansion (5-button joypad, sensors, etc.):

GPIOTypeNotes
GPIO 14INPUT_PULLUPBest for buttons
GPIO 16INPUT_PULLUPBest for buttons
GPIO 17INPUT_PULLUPBest for buttons
GPIO 34Input onlyNeeds external 10K pull-up to 3.3V
GPIO 35Input onlyNeeds external 10K pull-up to 3.3V
GPIO 0INPUT_PULLUPStrapping pin (LOW at boot = download mode)

Command Protocol (TCP text)

CommandActionPin Used
H0/H1HVAC off/onGPIO 2
S0-S2Fan speedGPIO 18 + GPIO 12
A0/A1AC off/onGPIO 4
L0/L1Unlock/lockGPIO 25
W1Window up (500ms pulse)GPIO 26
W0Window down (500ms pulse)GPIO 27
R0/R1Remote start off/onGPIO 5
P10/P11Extra 1 off/onGPIO 32
P20/P21Extra 2 off/onGPIO 33
CChime (200ms pulse)GPIO 33
K0-K4Radio sourceI2C → TEA6320T
V-31..V20Radio volume (dB)I2C → TEA6320T
M0/M1Radio unmute/muteI2C → TEA6320T
B0-B31Bass (16=flat)I2C → TEA6320T
T0-T31Treble (16=flat)I2C → TEA6320T
D-15..D15FaderI2C → TEA6320T
O0/O1Loudness off/onI2C → TEA6320T

JSON Commands (TCP)

{"cmd": "bind", "vin": "..."} // Bind module to VIN
{"cmd": "unbind"} // Unbind module
{"cmd": "arm"} // Arm alarm
{"cmd": "disarm"} // Disarm alarm
{"cmd": "remote_start"} // Remote start engine
{"cmd": "remote_stop"} // Remote stop engine
{"cmd": "lock"} // Lock doors
{"cmd": "unlock"} // Unlock doors

Status Response

H:0 S:0 A:0 L:0 R:0 F:0 P:0,0 K:0 V:0 M:1 B:16 T:16 D:0 O:0

Build & Flash

cd esp32_body_controller
pio run # Build
pio run --target upload # Upload via USB
pio device monitor -b 115200 # Serial monitor

Dependencies

  • ESP32 Arduino core
  • ArduinoJson — JSON (v7)
  • Wire (I2C, built-in) — TEA6320T communication

Related Repositories

RepoRole
carputerQt5 head unit — sends TCP commands
esp32_sensor_moduleConnects to this module's WiFi AP
esp32_clusterTFT display — connects to this module's WiFi AP
esp32_keyfobESP-NOW remote — sends lock/start commands
esp32_mesh_moduleV2V mesh — talks to this module via TCP

About

ESP32 firmware — TCP command server for relays (HVAC, locks, windows, fans), joypad input, Kenwood radio I2C sniffer

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages