- CAN log page: ELM327 monitor-mode survey/capture of broadcast frames with marks, written to /canlog on the SD card; serial "ls"/"get" commands to download logs - sd_card: reference-counted SD_MMC mount shared by bg_store and the logger - heap_caps_malloc_extmem_enable(64): internal RAM was down to ~10 KB, SD mounts failed with ESP_ERR_NO_MEM (DMA); now ~23 KB free, 13.8 KB DMA block - docs/canlog: first test drive (Fiesta Mk8 2018) - no broadcast frames on the OBD port, only diagnostic replies (gateway) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
5.8 KiB
Markdown
76 lines
5.8 KiB
Markdown
# OBD Speed (JC3636W518)
|
||
|
||
Vehicle speed from an ELM327 over BLE, shown as a big number + arc gauge on top of an animated GIF.
|
||
Uses the shared board library and LVGL 9.6 (`../shared`), NimBLE-Arduino 2.5.1.
|
||
|
||
## Use
|
||
- **Speed page** — speed in km/h (`--` = no data: not connected, or ignition off), arc gauge 0–200 km/h,
|
||
status pill below the number (adapter name when running, otherwise what it is doing).
|
||
**Battery voltage** (`ATRV`, every 2 s) as a small arc in the bottom gap (11–15 V) + number; color:
|
||
red < 11.8 V, orange < 12.2 V, green < 13.0 V (resting OK), blue ≤ 14.8 V (charging), red above (overcharge).
|
||
- **Swipe left → adapter menu** — scans while open. OBD-like adapters (name OBD/ELM/…, or service FFF0/FFE0/18F0)
|
||
are listed first in green. **Tap one** to select it: it is remembered (NVS) and connected immediately.
|
||
**Forget** clears the remembered adapter, **Done** (or swipe right) returns to the speed page.
|
||
- **Swipe left again → settings** — screen rotation 0 / 90 / 180 / 270 degrees, and **screen off without data** Off / 2 / 5 / 10 min (default 2). Both remembered in NVS.
|
||
- **Swipe left once more → background** — `Built-in` plus every GIF in `/gifs` on the SD card (size and
|
||
dimensions shown; not 360×360 in orange). Tap one: it is copied into the device's flash (progress shown) and
|
||
played from there, so the SD card is not needed afterwards. At boot the device checks (in the background)
|
||
whether the chosen file on the SD card changed (size/date) and re-copies it. **Rescan** re-reads the card.
|
||
- **Swipe left once more → CAN log** (temporary, to find the cruise/ACC set speed and speed-sign messages, see below).
|
||
**Start/Stop** (remembered: logging resumes by itself after power-up), **Mark**, the last frame of the three Ford
|
||
candidate IDs, and the file on the SD card. While logging, the speed page shows a red `REC <marks>` pill and
|
||
**a tap on the speed page adds a mark** (pill flashes `MARK n`).
|
||
- **Idle** — after that time without speed data (ignition off, adapter gone) the screen goes dark, the GIF pauses and
|
||
OBD polling stops; only `ATRV` every 30 s (answered by the adapter itself, doesn't wake the car's bus).
|
||
Wakes on a touch (the touch is swallowed) or by itself when the voltage rises above 13.2 V (engine started).
|
||
Not used while no adapter is chosen.
|
||
- On power-up the remembered adapter is connected automatically; if the link drops or the adapter is not
|
||
there (car off), it retries every 3 s. With no adapter remembered, the device starts on the menu page.
|
||
|
||
## How it talks to the ELM327
|
||
Service `FFF0`, notifications + commands on `FFF1` (verified with the user's "OBDII" adapter, see
|
||
`docs/2026-10-23_ble_scanner_car_test.txt`, made with the BLE scanner tool that was removed afterwards — in git history); other adapters: first notify+write pair.
|
||
Init: `ATZ`, `ATE0`, `ATL0`, `ATS0`, `ATH0`, `ATSP0`, `0100`; then `010D` (speed) is polled continuously.
|
||
Serial (115200) prints status changes as `[obd] ...`.
|
||
|
||
## CAN logger (finding ACC set speed / speed sign)
|
||
Neither value is a standard OBD PID; on Fords they are broadcast CAN messages. Candidates from opendbc
|
||
(`ford_lincoln_base_pt.dbc`, made for newer Fords; **not yet confirmed on the Fiesta Mk8**):
|
||
`0x165` EngBrakeData `Veh_V_DsplyCcSet` (set speed as shown) + `CcStat_D_Actl`, `0x202` `Veh_V_RqCcSet` (0.5 km/h),
|
||
`0x3D9` IPMA_Data2 `IsaVLim_D_Rq` (speed limit, 254 = no data) + `IsaVLimUnit_D_Rq` (1 km/h, 2 mph).
|
||
|
||
While logging, the OBD task (after `ATCSM1` silent monitoring, `ATH1`, `ATCAF0`):
|
||
1. **Survey**: listens to the ID ranges `0XX`..`7XX` (`ATCRA` with wildcards + `ATMA`, 1.3 s each); a range that
|
||
overflows the adapter (`BUFFER FULL` / 300 lines) is split into 16 smaller ones. Repeated every 10 min.
|
||
2. **Capture**: one frame of every ID found, in turn; the three candidates after every 8 others.
|
||
3. Every 2 s `ATAR` + `ATCAF1` + `010D` (speed, so the display keeps working, a bit laggy) and `ATRV`.
|
||
If the adapter can't filter by wildcard it falls back to unfiltered 2 s windows.
|
||
|
||
Log: `/canlog/log_NNN.txt` (new file per session, appended every 2 s; kept in RAM while the card is missing).
|
||
Lines `<ms> <type> <data>`: `C` adapter, `P` protocol, `V` speed, `B` voltage, `M` mark, `F id data` frame,
|
||
`N id` no frame, `I` survey IDs, `E` adapter message/note. Test drive: change the set speed and pass signs, tap
|
||
for a mark each time (passenger, or only when safe).
|
||
|
||
## Files
|
||
| File | What |
|
||
|---|---|
|
||
| `src/main.cpp` | LVGL UI (tileview: speed, adapter menu, settings, background, CAN log) |
|
||
| `src/obd_link.cpp/.h` | BLE scan, connect/reconnect, ELM327 init and speed polling, CAN logging steps (background task on core 0) |
|
||
| `src/font_speed_120.c` | Montserrat Medium 120 px, digits and `-`, 4 bpp (generated with `lv_font_conv`, see header) |
|
||
| `src/can_log.cpp/.h` | CAN log buffer + SD writer (background task), marks, values shown on the log page |
|
||
| `src/sd_card.cpp/.h` | Shared, reference-counted SD_MMC mount (background store + logger) |
|
||
| `src/bg_store.cpp/.h` | Background GIF from the SD card: list `/gifs`, copy into the `bggif` flash partition (header written last), mmap for playback, change check at boot (background task) |
|
||
| `partitions.csv` | 4 MB app (no OTA) + 11.9 MB `bggif` raw area + NVS |
|
||
| `data/bg.gif` | Built-in background (`ezgif-5-cb56986bc7.gif`, 360×360), linked into the firmware via `board_build.embed_files` |
|
||
| `sd/gifs/` | (not in git) GIFs converted with `../tools/gif_to_360.py`, ready to copy to the SD card |
|
||
|
||
## GIFs for the SD card
|
||
Convert any GIF to 360×360 (scale to cover, center crop, frame timing kept) with
|
||
```
|
||
pip install pillow
|
||
python ../tools/gif_to_360.py <gif files or folders> -o sd/gifs
|
||
```
|
||
and copy the files into a folder `gifs` on the SD card. Max ~11.5 MB per GIF. GIFs are played from flash at their own
|
||
frame rate (360×360: ~10–12 ms decode per frame).
|
||
Replace `data/bg.gif` to change the built-in background.
|