iwanders / OBD9141

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

Unable to initialize obd.init() #49

Open Ashok12698 opened 11 months ago

Ashok12698 commented 11 months ago

Hi @iwanders Thanks for your sharing. https://github.com/iwanders/OBD9141 I am trying example code 'reader_softserial' but unable to init the obd as defined here in obd.init(). Please suggest~ Thanks.

17:54:21.677 -> init_success:0 17:54:25.191 -> Looping 17:54:31.178 -> init_success:0 17:54:34.677 -> Looping 17:54:40.687 -> init_success:0 17:54:44.166 -> Looping 17:54:50.169 -> init_success:0 17:54:53.671 -> Looping

iwanders commented 11 months ago

Start by toggling on the debug printing here.

If possible and you have the hardware, attach a logic analyzer, compare with another OBD reader.

Ashok12698 commented 11 months ago

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

I am reading buffer[0] = 57 instead of 55 and buffer[1] = 0

iwanders commented 11 months ago

No, you're getting a timeout; this line returns false.

Are you sure this is the correct initialisation procedure for this ECU? Does it need the 5 baud init or KWP? Ideally confirm with another OBD reader what initialisation is necessary for this ECU.

Check if your software serial port actually works, can you receive anything on this serial port? Does it need pullup resistors?

Ashok12698 commented 11 months ago

Yes, I agree, [this line] returns false. basically my ECU is a simulator and I can set the modes using switches to KWP and ISO9141-2. So I am trying with init() and initKWPSlow(). both needs the 5 baud init. I tested it with another obd reader it detect the KWP and ISO9141-2. Also I compared the wakeup signal from obd reader and what I am getting. Its similar, but after that it doesn't show any data signals (like 1st byte which should be 0x55). I checked the serial port signal on Rx (its same as on K-line with voltage level 5v).

iwanders commented 11 months ago

Hmm, well that's an intriguing setup.

I wonder what the timing looks like with another OBD reader. A wild guess is that the simulator responds very quickly, effectively responding with the 0x55 in between these calls, so perhaps the 0x55 is sent while we are still in the delay(200) and the serial port is not yet enabled?

You could try to remove that last delay, it shouldn't affect the initialisation procedure since the line is already high, but it may just setup the bus fast enough to be able to catch the 0x55?

If at all possible, hook up a logic analyser and record a handshake from another OBD reader and compare it with what the handshake from your microcontroller & this library looks like, that is by far the easiest way to diagnose any issues around it.