OBD car trip telemetry tracker

Status
Phase 1 complete
Vehicle
Toyota Yaris sedan, 2011
Live demo
mycar-telemetry.netlify.app
Github
Repo Link
Tags
  • Raspberry Pi
  • ELM327
  • OBD-II
  • Python
  • SQLite
Trip dashboard overview
Trip dashboard overview 2

Overview

This is a personal car telemetry system built around a Raspberry Pi, which acts as the data collection device. The Pi connects to my car through a Bluetooth ELM327 OBD-II adapter and polls the car's ECU for live sensor data over the CAN bus. Everything is written to a local SQLite database on the Pi, so each trip is recorded like a small black box, with no internet connection needed.

Phase 1 is deliberately narrow: reliable local capture of tiered trip data to SQLite.

The problem

My car is older, and I wanted to track its health over time instead of waiting for a warning light. Then I found out about the OBD port, and my car (a 2011 Toyota Yaris sedan) is new enough to support it. Nearly every car exposes live sensor data through OBD-II, so the data was already there. I just needed a way to capture it.

Phone apps that connect to OBD-II adapters can show live gauges, but none of them fit what I wanted:

So I built my own logger: one I fully control, that stores every trip, and that polls each sensor at a rate matching how quickly its value changes.

What it does

At the start of each trip, I connect the Raspberry Pi to the Bluetooth OBD-II adapter and run the logger script. Data is captured in three tiers:

  1. Once per trip: static and diagnostic values such as VIN, distance since DTC clear, MIL status and stored fault codes.
  2. Every second: the core live driving metrics: speed, RPM, engine load, throttle position, coolant temperature, MAF (mass air flow), intake air temperature and short-term fuel trim.
  3. Every 30 seconds: slower-moving context values: long-term fuel trim, control module voltage, ambient air temperature, barometric pressure, post-catalyst O2 sensor reading and catalyst temperature.

Every reading is timestamped and stored in a SQLite database, linked to the trip it belongs to.

Architecture

System Architecture Image
  • Vehicle ECU system: the car's onboard computer exposes vehicle metrics through the OBD-II diagnostic port. An ELM327 Bluetooth adapter plugs into this port and sends the data out wirelessly.
  • Raspberry Pi (datalogger): at the start of each trip, the logger script starts and connects to the adapter over Bluetooth. It then runs two scheduled loops: a 1-second loop for the core performance metrics and a 30-second loop for the secondary diagnostics.
  • Local storage: the Python script parses and formats each reading, then writes it with a timestamp into a local SQLite database (obd_data.db).

Why three tiers?

The Bluetooth link to the adapter is slow, and every query uses up some of that bandwidth. If I polled everything every second, the values I care most about would be read less often. So I sorted each sensor by how fast its value actually changes.

Every ~1 second: the live story of the trip

CommandWhy it earns a spot
SPEEDCore trip metric
RPMCore trip metric. Pairs with speed for shift and driving-behavior analysis
ENGINE_LOADShows how hard the engine is working: hills, acceleration, towing
THROTTLE_POSDriver input, useful for judging how smooth the driving is
COOLANT_TEMPTracks warm-up and flags overheating
MAFThe basis for a live fuel-consumption estimate
INTAKE_TEMPCheap to read, changes with conditions, feeds efficiency analysis
SHORT_FUEL_TRIM_1Combustion health trend. Noisy, but useful once aggregated

Every ~30 seconds: slow-moving context

These values don't change fast enough to justify 1 Hz polling. Reading them every second would just eat Bluetooth bandwidth that the 1-second list needs.

CommandWhy
LONG_FUEL_TRIM_1A learned value that drifts slowly. Good for long-term health trends, pointless at 1 Hz
CONTROL_MODULE_VOLTAGEBattery and alternator health, which changes slowly
AMBIANT_AIR_TEMPOutside temperature doesn't change second to second
BAROMETRIC_PRESSUREOnly really changes on long drives with a big change in elevation
O2_B1S2Post-catalyst sensor. I care about the trend over the trip (it should stay steady), not a jittery live chart
CATALYST_TEMP_B1S1Slow thermal mass, so it doesn't swing from second to second

Once per trip: health checks

CommandWhy
STATUSMIL on/off and fault code count. My "all clear" badge
GET_DTCOnly pulled if STATUS says there are stored codes
RUN_TIMEEngine run time at the start of the trip
DISTANCE_SINCE_DTC_CLEARA context stat rather than a trend line
VINIdentifies which car the trip belongs to, in case I add a second vehicle later

SQLite schema

Each trip gets one row in trips, one row in trip_start_data, and many rows in the two sample tables.

trips
ColumnTypeKey
idintegerPK
started_atinteger
ended_atinteger
trip_start_data

The once-per-trip values, which act as a kind of pre-drive inspection. I plan to build a separate inspection page or script on top of this table.

ColumnTypeKey
trip_idintegerPK
vintext
distance_since_dtc_clrinteger
run_time_sinteger
mil_oninteger
dtc_countinteger
stored_dtcstext
samples_1s
ColumnTypeKey
idintegerPK
trip_idintegerFK
tsinteger
speed_kmhreal
rpmreal
engine_loadreal
throttle_posreal
coolant_temp_creal
maf_gpsreal
intake_temp_creal
short_fuel_trimreal
samples_30s
ColumnTypeKey
idintegerPK
trip_idintegerFK
tsinteger
long_fuel_trimreal
module_voltage_vreal
ambient_temp_creal
baro_pressure_kpareal
o2_post_cat_vreal
catalyst_temp_creal

Tech stack

  • Hardware: Raspberry Pi with a small attached screen, ELM327 Bluetooth OBD-II adapter
  • Protocol: OBD-II over CAN bus
  • Language: Python
  • Storage: SQLite

Challenges and what I learned

Unreliable connections and messy data

The Bluetooth link to the adapter isn't always stable. Dropped connections left gaps and occasionally bad readings in the data, and I had to clean up some of it in SQLite by hand. This taught me that a logger needs to expect failure: retry connections, handle empty responses, and never assume that every query returns a value.

OBD is request-response, and I have to ask for everything

The car doesn't stream sensor data to me. For each value I want, the Pi sends a request for one specific sensor (a PID), the ECU replies with that single reading, and the exchange is over. Setup happens once at the start of a trip: the Pi connects to the adapter over Bluetooth, the adapter is initialised, and it detects which protocol the car speaks. After that, each live-data query is independent and no session needs to be kept alive.

This shaped the whole design. Every query takes time on a slow Bluetooth link, and the readings arrive one at a time. Polling every sensor every second would crowd out the ones I care about most, so I split the sensors into polling tiers by how fast their values change. I also can't assume a reply will always come back. A sensor can return "no data", or the adapter can stall, so the logger has to handle empty and failed responses.

What's next

The next phase will focus on two things:

  1. A separate vehicle health check page. This would run occasionally rather than every trip, and would build on the data in trip_start_data.
  2. A better data pipeline. Right now, getting data from the car to the UI takes too many manual steps:
    • I set up the Pi and start the script by tapping its small attached screen.
    • After the drive, I copy the SQLite database over SSH.
    • I convert the tables to JSON files with the SQLite command line and drop them in the UI's public folder.
    I'd like a proper backend, with the UI fetching only the specific trip it needs.

There's a further question about what to show. A trip on its own isn't very useful unless something went wrong, so rather than listing every trip, the system should surface the ones where a fault or anomaly was detected. Syncing the data into a time-series store like TimescaleDB, visualizing it with Grafana, and possibly adding GPS and IMU data are on the longer-term list too.

Setup

OBD Device Image
Rasberry Pi Image
Rasberry Pi Script Image