This is the OBD II module or cable I have used for this project. I bought it from https://www.scantool.net/obdlink-sx/.It has in-built Serial to USB converter so that it will be easy to interface with Raspberry Pi through USB.I have used Raspberry Pi 2 for this project but any version of Pi will do.
Lets get started!!
First thing you need to do is to install obd ii python library in raspberry pi.Enter following commnd on terminal.
$ pip install obd
It install the python obd ii library in Raspberry Pi.You can get the source code from github as it is open source.And its detailed documentation here.
As older version of pyserial does not have in_waiting property of serial object made during serial communication.It may cause issue which can be solved by upgrading pyserial using following command in terminal,
$ pip install pyserial --upgrade
Now we are all set,
Sample Program to get Vehicle Speed using python 2.7.x,
import obd #importing obd library
connection = obd.OBD(baudrate=115200) #making obd connection object
command = obd.commands.SPEED #for getting vehicle speed
result = connection.query(command) #requesting vehicle speed through obd
print result.value #this will print the speed value in Km/Hr
command = obd.commands.RPM
.All commands for obd are listed in documentation here. One thing you need to make is that not every vehicle supports every command.Latest vehicle supports more commands while older (manufactured years ago ) may not support many commands.You can list the supported commands by using function
connection.print_commands()
You can get DTC(Diagnostic Trouble Code) using command GET_CURRENT_DTC or GET_DTC.
e.g.result = connection.query(obd.commands.GET_CURRENT_DTC)
print result.value
To clear DTC, there is command CLEAR_DTC. It will clear DTC if possible i.e. if there is no physical diagnosis to be applied.
Further, I will discuss in next post.Where I will send OBD data to server using GPRS module interfacing with Pi and using it as TCP client.See you in Part -2.
It really helps me doing my project.
ReplyDeleteThanks for your response.I will be publishing its second part very soon.Keep checking out this blog.
Delete