Skip to content

Dashcam ​

A dashcam firmware for the LILYGO T-CameraPlus-S3 development board. Records camera video and microphone audio into standard AVI files saved to a microSD card, with real-time preview on the LCD.

Hardware Requirements ​

ComponentSpecification
BoardLILYGO T-CameraPlus-S3 V1.2
MCUESP32-S3, 240 MHz, 16 MB Flash, 8 MB PSRAM
Display240×240 ST7789V LCD
CameraOV2640 / OV5640 (auto-detected)
MicrophoneMP34DT05TR digital microphone (PDM)
StoragemicroSD card (Class 10 / U3 recommended, 32 GB+)
PMUSY6970 power management
TouchCST816S touchscreen

Note: The pin definitions in board_pins.h correspond to V1.2. V1.0 / V1.1 have different SPI, I2C, camera, and microphone pins — refer to the actual board silkscreen to make adjustments.

Features ​

  • Loop recording: Automatically records video as AVI files (Motion-JPEG video + 16-bit PCM mono audio), with each clip defaulting to 60 seconds, stored in the /dashcam directory on the SD card.
  • Loop overwrite: Automatically deletes the oldest clips when free SD card space drops below 150 MB, ensuring uninterrupted recording.
  • Live preview: The recording is displayed in real time on the 240×240 LCD with an overlaid status bar (recording duration, free space, battery level, frame rate).
  • Photo snapshot: Touch the screen or press KEY2 to save a JPEG photo to the /photos directory on the SD card at any time.
  • Auto-start: Recording begins automatically on power-up (can be disabled in config.h).
  • Audio recording: I2S digital microphone simultaneously captures 16 kHz mono audio and mixes it into the AVI file.

Flash Firmware ​

ESP32 烧录工具 (官方API)

⚪未连接

选择固件

操作日志

Operation ​

ActionFunction
Power onRecording starts automatically (AUTO_START_RECORDING=1)
Press KEY1 (GPIO 17)Take a snapshot, saved to /photos, plays a confirmation tone
Press KEY2 (GPIO 0)Toggle recording start / stop, plays a confirmation tone
Touch screenTake a snapshot

LCD Status Overlay ​

Icon / FieldMeaning
REC red dotCurrently recording
00:01:23Elapsed time of the current clip
1234 MBRemaining SD card space
85%Battery level
⚡Charging
24 fpsCurrent recording frame rate

File Structure ​

SD card
├── dashcam/
│   ├── CLIP_0001.avi
│   ├── CLIP_0002.avi
│   └── ...
└── photos/
    ├── IMG_0001.jpg
    └── ...

Key Configuration ​

All recording parameters are centralised in config.h — no source code changes required:

ParameterDefaultDescription
REC_SEGMENT_SECONDS60Clip duration (seconds)
REC_MIN_FREE_MB150Minimum free SD space; triggers loop deletion when exceeded
CAM_JPEG_QUALITY14JPEG quality (lower value = higher quality, larger file)
CAM_FRAMESIZE_OV2640SVGA 800×600OV2640 resolution
CAM_FRAMESIZE_OV5640HD 1280×720OV5640 resolution, ~15fps (ESP32-S3 limited)
AUDIO_ENABLE1Whether to record audio
AUDIO_SAMPLE_RATE16000Audio sample rate (Hz)
PREVIEW_EVERY_N_FRAMES6Update LCD preview every N frames
AUTO_START_RECORDING1Whether to start recording automatically on power-up

Build & Flash ​

Requirements:

Steps:

bash
# 1. Enter the example directory
cd examples/Dashcam

# 2. Build
pio run

# 3. Flash (connect the board first)
pio run -t upload

# 4. Open serial monitor (115200 baud)
pio device monitor

# One-shot: build + flash + monitor
pio run -t upload && pio device monitor

After a successful build, the merge_bin.py post-processing script automatically merges the bootloader, partition table, and application firmware into a single flashable file:

firmware_out/T-CameraPlus-S3_Dashcam.bin

Flash the merged firmware directly (no build environment required):

bash
esptool.py --chip esp32s3 --baud 921600 write_flash 0x0 firmware_out/T-CameraPlus-S3_Dashcam.bin

Arduino IDE ​

Requirements:

Install required libraries (search in Library Manager):

LibraryVersion
LovyanGFX^1.1.16
JPEGDEC^1.6.2
XPowersLib^0.2.6
OneButton^2.5.0

Board settings (Tools menu):

OptionValue
BoardESP32S3 Dev Module
Flash Size16MB (128Mb)
Partition SchemeCustom (manually import partitions.csv)
PSRAMOPI PSRAM
Flash ModeQIO 80MHz
USB ModeHardware CDC and JTAG
CPU Frequency240MHz (WiFi)
Upload Speed921600

Steps:

  1. Open Dashcam.ino.
  2. Configure the board options as shown above.
  3. Click Upload to build and flash.
  4. Open the Serial Monitor and set the baud rate to 115200.

Tip: Arduino IDE does not support directly importing a custom partition table file. It is recommended to add the partition scheme from partitions.csv to the Arduino core's boards.txt in advance, or use PlatformIO to avoid partition configuration issues.


Architecture ​

The firmware uses FreeRTOS dual-core parallelism:

TaskCorePriorityResponsibility
recordTaskCore 15Camera capture, AVI muxing, SD write
uiTaskCore 03LCD preview rendering, touch detection, button polling, PMU status
mic task (internal)Core 0—I2S capture → FreeRTOS Stream Buffer

The LCD and microSD share the same SPI bus; a mutex (spibus::Guard) ensures safe concurrent access.

Unit Tests (AVI Writer, Host-only) ​

The AVI writer module can be tested independently without hardware:

bash
g++ -std=c++14 -I../../src test/host/test_avi.cpp avi_writer.cpp -o test_avi
./test_avi

Troubleshooting ​

Recording does not start / LCD shows "NO SD CARD"

  • Check that the SD card is inserted and formatted as FAT32 or exFAT.
  • Recommended: 32 GB or larger, Class 10 / U3.

No audio

  • Check that AUDIO_ENABLE is set to 1 in config.h.
  • Check that AUDIO_I2S_CHANNEL matches the microphone channel on your board.

Low frame rate

  • Increasing CAM_JPEG_QUALITY (higher numeric value) reduces file size and improves frame rate.
  • Increasing PREVIEW_EVERY_N_FRAMES reduces the time the LCD occupies the SPI bus, freeing more bandwidth for SD writes.

V1.0 / V1.1 board not working correctly

  • The pin definitions in board_pins.h are based on V1.2. Refer to the official schematic and update the pin numbers accordingly.