iwanders / OBD9141

A class to read an ISO 9141-2 port found in OBD-II ports.
MIT License
232 stars 72 forks source link

What to do when it doesn't work immediately? #3

Closed iwanders closed 6 years ago

iwanders commented 8 years ago

This issue comes from a comment on 9448f7542a6dd32b5aa89d5b1002cc537003e2a6 by @callmeice.

I'm trying to use this library with Arduino Nano(v3) and SN65HVDA100 but i didn't had any luck. When you use it with Arduino UNO , did you use the same schema that was described? or did you used something else?

I tested it with the diagram as described, without R1 and D2 as they are unnecessary in my situation, be sure to set the Enable pin of the SN65HVDA100 high to enable the chip.

If your wiring is correct and the above does not help: Check the voltages; the K-line should be approximately the battery voltage most of the time, the Rx pin follows the K-line but at logic level.

I measured voltage of K-line, and was aproximately the same with batery voltage, but if I measured it again with everything connected ,voltage drop to aprox 7V. And also if I measure the SN65HVDA LIN pin without k-line connected , voltage was about 12V. Also the voltage of Rx pin , range from 0 to 3.5 V. Do you think I might fried the chip?

The K-line that drops to 7V is quite low in my opinion, you should really use R1 and D2 in order to provide sufficient pullup to the K-line. The SN65HVDA100 datasheet recommends 1k, but some other sources use ~500 ohm.

What is the output of the example sketch? If it says init_success:0 the initialization handshake with the ECU fails. In this case, go the the OBD9141.h file and uncomment this line:

#define OBD9141_DEBUG

And check the output on the serial terminal, it should look like:

Looping Before magic 5 baud. Before setting port. After setting port. First read is: 85 read v1: 8 read v2: 8 v1: 8 v2: 8 init_success:1

If the output is different, it might provide a clue what goes wrong in the OBD9141::init() method. If the handshake fails debugging this is not straightforward, you are best of by hooking up a logic analyzer and investigating what is actually happening on the K-line and on the Tx and Rx pins.

iacobcatalin commented 8 years ago

Hello again, I've done again the circuit and also change the tranceiver(just in case), but also the init_success was 0. I had uncommented debug line, and the response was:

"Looping Before magic 5 baud. Before setting port. After setting port. Timeout on read 0x55. init_success:0 "

Unfortunately I dont have a portable logic analyzer, and at my University I can't find one ( i'll try in weekend in front of my university, with a plugged in one, when aren't a lot of students :) ). From the code I tried to expand/short the timeout(just in case) but with no luck. Have you been in the same situation? Thank you very much for all your help.

iwanders commented 8 years ago

During the initialization the following happens: The 'slow' handshake is started by sending a byte to the ECU at a baudrate of 5, after that the baudrate becomes 10400 and the ECU should send a 0x55 byte back, which is followed by two more bytes v1 and v2, these should be identical and the reader (the device trying to handshake with the ECU) should respond by sending the inverted value of v2, after this the ECU should answer with 0xCC to finish the initialization.

Based on the debug output you provided, this 0x55 byte is never received from the ECU. There are several things you can try:

The last two steps are by far the most insightful to investigate what the problem is, because if you can see what is happening you can probably see what is going wrong. Especially the last step is insightful, as you can record what the correct handshake is. It might be the case that your ECU requires the 'fast' initialization, whereas the one implemented in this library is the 'slow' one.

Have you been in the same situation?

Not exactly the same, but I encountered plenty of issues when I first started this project. With these sort of problems a logic analyzer (or second microcontroller) really helps, and comparing the signal to a working OBD reader also helps. I hope the steps above help solving the issue for you, please let us / me know if it does.

wanthalf commented 6 years ago

Hi. I have a similar problem with Macchina M2 and Škoda Octavia I 1.9TDI (1999). I wonder why the initialization sequence is '11001100', i.e. 51 backwards. According to https://www.blafusel.de/obd/obd2_kw1281.html it should be the address of the unit (ECU is 1), i.e. '10000000'. Even the rest of the init process seems to be different. Is this code supposed to be compatible with KW1281?

iwanders commented 6 years ago

Hi Wanthalf,

This library is not expected or supposed to be compatible with KW1281, that seems to be a proprietary protocol by VW. Unfortunately there are many OBD signal protocols, this library only handles OBD9141-2, which is one of them (ISO 14230 KWP2000 could be added relatively easily; only the handshake is different).

KW1281 seems to be a whole different protocol, not only the initialisation, but also the checksums appear to be different than OBD9141. So I don't see any easy way to adapt this library to suit your requirements.

I'm closing this issue as the discussion of whether or not this library implements a specific protocol is unrelated to the original issue. I hope my reply answers your question.