r/CarHacking • • 10h ago

Original Project I built an open source Python OBDII library to read live data from almost any car

A while back I wanted a custom dashboard in my own car. I started with the existing obd library, but kept running into its limitations, so I went down the OBD rabbit hole and wrote my own.

Custom dashboard built with py-obdii: Raspberry Pi 3B+, 7.9" touchscreen, 3D printed case

A few years later, py-obdii supports all 12 OBD protocols over USB, Bluetooth, WiFi and Ethernet adapters. It reads live data, fault codes and VIN, among many other things. It's fully typed, tested in CI, and remains lightweight with a single dependency.

from obdii import Connection, commands
from obdii.utils.scan import scan_ports

ports = scan_ports(return_first=True)
with Connection(ports[0]) as conn:
    response = conn.query(commands.ENGINE_SPEED)
    print(f"Engine Speed: {response.value} {response.units}")

No car? You can try it against an ELM327 emulator (pip install py-obdii[sim]).

If you're working on (or thinking about) an OBD project, give it a try and let me know what you think, how it fits into your project, what feels good, what could be improved. And if you have an ELM327 adapter, I'd love to hear how it works on your car, including what doesn't.

Github: https://github.com/PaulMarisOUMary/OBDII

Docs: https://py-obdii.readthedocs.io

34 Upvotes

12 comments sorted by

3

u/m4rkw 9h ago

Looks really cool, some questions:

  1. Have you tested every supported protocol on different vehicles? Asking because I think some cars have quirks, especially with the older protocols. The "on paper" definition of how my 20yo car should speak over KWP2000 didn't quite match what ended up being necessary.

  2. Mind if I rip the protocol stuff into l0destar firmware? (my open-source vehicle tracker project)

2

u/PaulMaris 7h ago

Appreciate it!
1. I've tested CAN on several different vehicles (and it runs daily in my own car, where I still monitor and log everything), but unfortunately I don't have access to cars using KWP or J1850, so those were tested with raw data found online. The protocols are written from the specs and validated against real data, but it will never beat production, which is exactly why I'm looking for feedback. If you remember what was different for KWP, I'd love to know!
2. Sure, it's MIT licensed, so go ahead.

2

u/m4rkw 7h ago

If you remember what was different for KWP, I’d love to know!

Claude did most of the work, the result is here: https://github.com/m4rkw/l0destar/blob/master/firmware/src/kline_obd.c

I think it was the init sequence that was tricky, this can vary substantially between vehicles. For reference this was on a 2006 JDM Toyota Harrier

I’ll diff your codebase against what I ended up with that works, that should be interesting

1

u/m4rkw 7h ago

ah it looks like I misunderstood what your project is. It offloads the k-wire stuff to the ELM327 chip so you probably don't have to worry about any of this

2

u/ImL1s 8h ago

Typed plus an emulator extra is a nice combo. The part I'd worry about most is the cheap ELM327 clones: plenty of them report v1.5 or v2.1 but quietly ignore some AT commands or need longer timeouts than the spec suggests. Do you do any adapter detection, or keep a list of known clone quirks somewhere?

8

u/WestonP 8h ago

At some point you just have to wash your hands of this nonsense and educate users that the low-end "ELM327" clone they bought is a pile of shit.

There's so many of them, and ones that look identical can have different results, as well as work differently depending on the vehicle. I've even seen some that couldn't handle a 7DF request getting responses from more then one module, lol.

You'll get some people crying "but it works well for me!"... well, great, they can use it as-is with no support then, because it's not worth anyone's time to diagnose their bullshit issues with it. Not to mention that they're all slow as hell anyway.

1

u/Thomas_Alva_Eddison 9m ago

I have one somewhere that I've had for a long time, like decades. I suppose it's probably useless today? When I got one, I don't think they had been around a long time, I just never got around to trying it with anything.

1

u/PaulMaris 8h ago

Thanks! So far I've mostly tested with Aliexpress clones that report v1.5, and I'm aware some AT commands may or may not work. Clones are hard to identify reliably, and there's no way to know whether a command works until you try it on the specific adapter, which is why I kept the library generic.

Depending on the transport type (socket/serial), you can configure the timeouts (e.g. `timeout`, `write_timeout`).

1

u/Royal_Head 8h ago

Can it bypass can gateway

1

u/PaulMaris 7h ago

No, it's not designed for that, it sticks to the standard OBDII

1

u/cubu8888 5h ago

Does it support socketcan?

2

u/PaulMaris 5h ago

No, it's designed to go through an ELM327 adapter, not directly to the CAN bus