Can you guys recommend any libraries?
I'll bite; The most commonly known project which deals with the OBD port is to the best of my knowledge the opengauge / obduino project, the original project page is probably
obduino.ca (
OBDuino has a wikipedia page), source code ported from google code to
https://github.com/magister54/opengauge. However, one can hardly speak of a library, there is some code which deals with the raw K-line initialisation, for example around
these lines. But most people tend to use the
ELM327 style chips which deal with the initialisation and provide a serial interface to request data from the car.
Sparkfun's board for example also uses a ELM327 compatible IC (
stn1110) to deal with the low-level communication, they then provide a command list and
point you towards other programs for interfacing with this chip. I believe most people go down the ELM327 road, but there are few exceptions, for example
this post describes a project on reading the OBDII port with an Arduino, but I could not find his code, there is some in his slides though.
So, (to the best of my knowledge) there isn't (wasn't) really a stand-alone library around which deals with the low level communication of the 9141-2 bus. This has led me to write my own library;
OBD9141 it's a class which does exactly what I wanted
It only deals with the communication with the bus and does nothing else besides that, it's pretty barebones but works well for me. Although the bus specification states that you should wait between sending bytes my car happens to return the entire answer with the bytes consecutively without delay. Because you know the amount of bytes that will be returned when you request a PID I use the readBytes method in order to read them without delay. This allows me to query about 20 PID's per second on my car, but your results may vary of course. I also wrote a simulator to aid in debugging, but it's not all that well tested, especially the handshake simulator is still a bit buggy, but when you both the simulator and the reader to 'initalised' reading PID's works fine, so for debugging a gui or something it should work. If you happen to try my library and have to incorporate additional handshakes (the fast init for example) feel free to send a pull request. In order to aid debugging your hardware I
uploaded some recordings with a logic analyser of my K-line, both with a cheap Bluetooth OBD reader and with my library.
With the shameless plug done, if anyone else knows of another library to aid communication with the ISO9141-2 port, I'd love to hear about it. I hope both of you get your readers/loggers working!