Related to this question I'm learning to use the Pi GPIO and Python serial to communicate through an IC (L9637D) to interrogate PIDs for alarms etc. I can't get past the slow initiation sequence!

The ISO 9141-2 slow init method used with Arduino and other MCs with L9637D and similar) is as follows:-

  1. wait a minimum of 2600ms after car is turned on (ECU init).
  2. Send byte 0x33 to the K-Line at 5 baud, serial communication (18N1).
  3. Initialize UART (18N1) to 10.4K baud, Receive byte 0x55 from the vehicle.
  4. Receive two key bytes (08 08 or 94 94)
  5. Wait for about 40ms
  6. Invert key byte 2 and send back to ECU i.e 0x08 becomes 0xF7.
  7. Wait another 40 milliseconds.
  8. Receive inverted address byte 0x33 i.e. 0xCC.

I realise I'm reinventing the wheel and could buy/download a solution but I'm trying to learn Python and GPIO on the Pi.

I've done minicom loopback tests etc but cannot get past slow init step 2. minicom returns stream of characters like '%' or series of 0x00 with some 0xFF. To test I used variants of this code using sleep 0.2 etc :-

    #!/usr/bin/env python3
import time
import serial

ser = serial.Serial(  
   baudrate = 5 # not 4800,
ser.write(serial.to_bytes([0x33]))  # try to_bytes  

To debug I tried attaching a digivoltmeter to UARTS and saw only tiny fluctation in 3.3v. So I'm guessing UART cannot make necessary rapid low/hi waveform @ 5 baud.

I started to use pigpio to switch mode IN / ALT0 and baudrate but realised this might be wrong way too. So my questions:

a. Should I create a slow init waveform using pigpio, maybe using other GPIOs then use UARTs to receive slow inti at 5baud then 10k4 baud ?

EDIT 1 : below is output of piscope at 5 baud and minicom when running test_write.py . As I understand this byte 0x33 at 5 baud should take about 2 seconds (200ms low, 400ms hi/low/hi/lo, 227ms hi) so something seems wrong with baudrate enter image description here

It seems minimum baudrate for pigpio is 50 so I may have to use some other trick - I see some people lowering base frequency but this may cause an issue when I need to step back to standard 10k4 baud.

Any guidance welcomed. Andrew.

  • Depending on your digital volt meter, it will not show what you are looking for. The correct instrument would be an oscilloscope (also called an o'scope). Using an o'scope show what the UART is outputting. Also a schematic of how you are connected, and your code of how you are performing the steps.
    – Wendall
    May 16, 2019 at 13:23
  • I saw that pigpio has a piscope, so as you suggested I ran it whilst shorting GPIO 14 Tx and 15 Rx. This revealed immediate error my code baud = 5000 instead of 5. So I adjusted to 5 but I'm now doubting the Pi, pyserial and pigpio can actually drop to 5 baud. I added this as edit to the question. May 16, 2019 at 16:00

1 Answer 1


Since you only "send" one byte at 5 baud, you might consider writing a hard coded "send 0x33 at 5 baud" routine out the TX pin, once done you can reconfigure the pin.

  • I'm unsure what 'hard coded' means, could you expand on this? I was thinking of sending timed sequence (200ms low, 400ms hi/low/hi/lo, 227ms) to mimick the pattern I think I can use pigpio to switch a GPIO low/hi. May 16, 2019 at 16:38
  • That is exactly correct. "Mimick" the bit patterns that would be sent with timers and GPIO low/hi.
    – Wendall
    May 16, 2019 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.