Cheap OBD2 Communications on K-line (ISO 9141-2 and ISO 14230-4)

94,378

168

77

Introduction: Cheap OBD2 Communications on K-line (ISO 9141-2 and ISO 14230-4)

About: idea + energy = instructable

This is just another OBD2 solution for monitoring the sensors in a verhicle. It supports the K-line OBD2 serial communication between a verhicle and a microcontroller. This K-line communication is also known as ISO 9141-2 or ISO 14230-4 (also known as Keyword Protocol 2000 or KWP). Both ISO's are almost similar. This solution differs from the rest that is low cost (for less than 10 euro!!). It is low cost in the way that you don't need an arduino, raspberry pi or smart phone. Just a microcontroller and LCD display so you can use your smartphone for other purposes.

Main features:

  • Shows verhicle engine load, temperature, speed and RPM on a LCD display
  • Optically displaying the engine load via a LED by changing the intensity using the microcontroller PWM module
  • When temperature exceeds 93 degrees a buzzer will be triggered
  • A watchdog will quard communication problems between microcontroller and verhicle ECU

To do:

  • Display stored diagnostic trouble codes in mode 0x03 (routine is included but I have to wait till my car gets troubles)
  • Clear trouble codes / Malfunction indicator lamp (MIL) / Check engine light (routine is included but untested)
  • Support "fast init"

It is tested with a Citroen C1 gasoline (2013) and VW Touran gasoline (2003). Probably it will work for a Peugeot 107 and Toyota Aygo of 2013 as well since they are technically identical. From what I read on the internet there are many flavours on K-line around so there is a possibility it will not suit your car. Maybe some changes are needed to make it work. The source code is provided so you can investigate and change when needed. Maybe you can help extending this list of cars to help others!

Have fun!



Found this site where you can check if your car supports K-line:

http://www.outilsobdfacile.com/vehicle-list-compatible-obd2/citroen

Step 1: Parts

1 x OBD2 Connector 16 Pin Male

1 x Microchip 16f886 microcontroller

1 x 16x2 LCD HD44780 or compatible

1 x BC547 or 2N3940 transistor

1 x LM7805 1A regulator

1 x 330nF ceramic capacitor

1 x 100nF ceramic capacitor

1 x 510 Ohm resistor

1 x 2.2K Ohm resistor

1 x 47K Ohm resistor

1 x 33K Ohm resistor

1 x 100 Ohm resistor, optional (for blue led, please use appropriate resistor for other colors)

1 x LED, optional

2 x 10K Ohm trim resistor

1 x Buzzer 5 volt (< 20mA), optional

Step 2: K-line Initialization and Response

Both ISO's 9141 and 14230 knows a 5 baud initialization sequence. The microcontroller must start this init by transmitting byte 0x33 to the verhicle at 5 bits per second. The total transmit time for transmitting byte 0x33 takes about 2 seconds. After this initialization it is expected to continue communicating at 10k4 baud.

ISO 9141-2 initialization response:

For ISO 9141-2 the verhicle ECU will respond with synchronization byte 0x55. After this, the verhicle will respond with key bytes 0x08 and 0x08 or 0x96 and 0x96. The sync byte with key bytes of the verhicle must be acknowledged by the microcontroller by inverting the second key byte. This will end the initialization part of ISO 9141-2.

ISO 14230 initialization response:

The response of ISO 14230 is slightly different. The verhicle ECU will also respond with synchronization byte 0x55. Only the key bytes are different. In case of a VW Touran of 2003 the key bytes are 0xef and 0x8f. Also here the second key byte must be acknowledged by the microcontroller by inverting it.

Step 3: Stimulus Response

After the initialization process it is possible to submit a request to the verhicle ECU. A request is a sequence of bytes where adressing, a mode, a PID and a checksum is present. The following are example requests:

For ISO 9141-2 this sequence of bytes is 0x68, 0x6a, 0xf1, 0x01, 0x0d and 0xd1.

For ISO 14230 this sequence of bytes is 0xc2, 0x33, 0xf1, 0x01, 0x0d and 0xf4.

The first three bytes are for addressing. The fourth is the mode field. The fifth byte is the data field with the PID and the last byte is the checksum.

In this example mode 1 is used. This mode will show "current data" as how it is at this moment. This mode is perfect for displaying actual information. The data field contains the PID. In this case 0x0d which is the verhicle speed. The checksum is the sum of the bytes with mod 256. See this link for a list of PIDs:

https://en.wikipedia.org/wiki/OBD-II_PIDs

The response is almost similar. The data field reflects actual data which will probably change every request. The following are example responses with 0x00 as data (which is verhicle speed 0).

For ISO 9141-2 : 0x48, 0x6b, 0x10, 0x41, 0x0d, 0x00, 0x11.

For ISO 14230 : 0x83, 0xf1, 0x10, 0x41, 0x0d, 0x00, 0xd2.

This OBD2 solution displays the calculated engine load (PID 0x04), engine
coolant temperature (PID 0x05), verhicle speed (PID 0x0d) and engine RPM (PID 0x0c) on a LCD display.

Step 4: Schematic

The verhicle will supply the circuit with 12 volt via pins 5 and 16 of the ODB2 connector. The voltage regulator will create 5 volt out of this for the microcontroller and LCD.

K-line signals of pin 7 will be converted to appropriate levels via an interface of resistors and a transistor.

The two trimm resistors are used to control the contrast and backlight of the LCD.

On port RC1 you can connect a LED (optional). With help of the PWM module of the microcontroller the intensity of the LED will be controlled by the calculated engine load (PID 0x04).

On port RC7 you can connect a buzzer (optional). When the engine coolant temperature (PID 0x05) exceeds the 93 degrees this port will be enabled.

Step 5: Code

The Microchip XLCD peripheral routines with some small changes are used for the external LCD module (less blurry result with fast changing data compared with other LCD routines).

A routine for displaying and clearing stored diagnostic trouble codes is included. This can be initiated by pressing the switch for 2 seconds. This routine is untested and will most probably not work. Feel free to try if you have a car with trouble codes.

The 5 baud init is also called "slow init". There is also a "fast init". The fast init does not use the 5 baud init as descibed above but starts directly at 10.4 kbps. A StartCommunication request 0xc1, 0x33, 0xf1, 0x81, 0x66 must be submitted prior submitting requests. I don't have a car which supports this fast init so maybe someone can help including it in this code to help others.

You can easily change the code if you want to have miles instead of km.

For simplicity no checksum is checked.

The code can be imported in Microchip MPLAB X IDE v3.20 with compiler XC8 v1.36. For programming the 16f886 microcontroller you need a programmer like pickit2 or pickit3.

A hex file is included in case you want to program the 16f886 with your own programming software/device.

Step 6: Have Fun

I hope you like this project. Have lots of fun building it and monitoring your verhicle!

If you are interested but not able to buid yourself just contact me. Maybe I can help with a programmed microcontroller or complete kit.

"This most beautiful system of the sun, planets and comets,
could only proceed from the counsel and dominion
of an intelligent and powerful Being."

~ Isaac Newton, Principia
First Time Author Contest 2016

Participated in the
First Time Author Contest 2016

Sensors Contest 2016

Participated in the
Sensors Contest 2016

3 People Made This Project!

Recommendations

  • Hide It Challenge

    Hide It Challenge
  • Unusual Uses Contest

    Unusual Uses Contest
  • Paint Challenge

    Paint Challenge

77 Comments

0
kiil889
kiil889

1 year ago on Step 5

cannot see the code, the only thing which is viewable is the schematic. But none of the c code sources. Why? Otherwise seems interesting project. Tried with Vivaldi and Brave browser the situation is the same. zero.

0
imlucaniop1
imlucaniop1

Reply 4 weeks ago

I was also wondering.
Using my phone and chrome.
When I went down to see more questions, suddenly the page reloaded and showed the code.

0
renahn1990
renahn1990

9 months ago on Step 6

Man thanks for your step to step explanation, I was having a lot of problems to communicate with the car and your pictures with the data transfer help me to figure it out what I was doing wrong! Thank you very much! Regards from Brazil!

0
Ed-avlis
Ed-avlis

Reply 4 months ago

Good Morning!
A good article and good work.
I have a question about initialization and about the bytes sent.
In this case I must perform the initialization sending the byte 0x33 at 5 bits per second correct.
The vehicle will respond with byte 0x55.
How should the key byte be inverted in the microcontroller this part of the process I didn't understand.
And in the case of requests, after initialization and only send the byte sequence, for example.
request 0xc2, 0x33, 0xf1, 0x01, 0x0d and 0xf4 and the answer would be this 0x83, 0xf1, 0x10, 0x41, 0x0d, 0x00, 0xd2 with the addition of one more byte.

Could you clarify these doubts for me.

0
JawadB2
JawadB2

1 year ago

I think you are using Saleae Logic Analyzer software.Can you tell me how you were able to decode the K-Line frames since there is no built-in decoder for that in Saleae logic.
In fact I couldn't find any decoder anywhere can you show me how you did that so I can debug mine

0
diniprop
diniprop

Question 1 year ago

Hello RichardvdK,

Can I change The display?
I'd like RPM, Temperature, Voltage
Thank you

0
fratink
fratink

1 year ago

Hello RichardvdK,

I've reproduced your example and it worked great, thanks so much for sharing this awesome work. I'm trying to get a scope that can be used to assist in development for ISO 9141 and I noticed it looked like you were using one for your project. Would you be able to share what equipment you used that was able to decode ISO 9141 so well?

Thanks!

0
fratink
fratink

Reply 1 year ago

In case anyone else is stuck, just use a regular scope with uart decoding and set the idle level to high rather than the standard low. That'll get ya going.

0
wyattearp187
wyattearp187

Question 1 year ago on Step 3

Can I contact you directly and purchase kit?

0
Diego Ianelli
Diego Ianelli

Question 1 year ago

Hey Richard I did this project and Works as It expected. I am not able to attach pictures here.
I did not understand a part of code when the PWM is turned on. Could you explain that part of code.
Thanks for advance!

0
RichardvdK
RichardvdK

Answer 1 year ago

Hi Diego, thanks for asking. It is about lines 322 till 333. Here a while loop is used to have smooth transition between different values of Calculated Engine Load. So if it goes from e.g 50 to 200 it will do 51, 52, 53 etc till 200. Not from 50 to 200 in one go.

0
Diego Ianelli
Diego Ianelli

Reply 1 year ago

Perfect! Thank you for respond my question!

0
batuhannarhin
batuhannarhin

Question 1 year ago on Step 5

2006 model nissan pathfinder r51 I have the tool accordingly, the LCD screen has a rpm connection but I do not know very well about it I will write code arduinoya and I need very close I'll be very glad I can present canbus shields 2.0 arduino uno obd2 db9 and have lcd screen

0
Boydsrisawad
Boydsrisawad

Question 2 years ago

Hi Richard,

Can I purchase the completed kit from you.

Regards,
Boyd

0
Vwtee
Vwtee

3 years ago on Introduction

hello richard,
ive recently got my hands on a golf mk3 gti engine with digifant 1 with a OBD port,i know its K-line kw1281 protocol. i was wondering if this would work on it and if so could i buy one off you?im also in NL so pick up and payment wouldnt be a problem :)

0
RichardvdK
RichardvdK

Reply 3 years ago

Hi, since there are about hundreds of different protocol flavours around it will most probably not work. It needs investigation. Probably it will work after making some small changes in timing and responses.

0
sumitgrover97
sumitgrover97

Question 3 years ago

Hi
thanks for your kind reply
I want to know if I don't want to inverse the data then can I use BC557 instead of BC547.

will it work same or will there any complication to achieve the baud rate of 10400 with BC557

Regards
Sumit

0
sumitgrover97
sumitgrover97

Question 3 years ago

Hi
I want to ask that as you are using BC547 to switch and if you send logic 1 it will push the K line to logic 0 that's why for initialization you have converted 0x33 to the inverse logic of it so that K line will get 0x33 but when you are transmitting commands you haven't inversed the logic and directly transmitting at 10400 baud. so will that thing work or at the K line we need inverse logic. i am confused with that. can you clerify?

thanks

0
RichardvdK
RichardvdK

Answer 3 years ago

Hi,

I'm not sure if I understand your question correctly. Let me try to answer.

The EUSART of the microcontroller is configured to invert the data. It is done here in the code:

BAUDCTLbits.SCKP = 1;

Kind regards,

Richard

0
santhun
santhun

Question 3 years ago on Introduction

ha sir

for ISO 9141-2 why fist byte is 0x68(in this line For ISO 9141-2 this sequence of bytes is 0x68, 0x6a, 0xf1, 0x01, 0x0d and 0xd1.) could you please give me clarity on this,if any document is available please send me a link.