K-line serial printing does not show anything on an oscilloscope



I’ve bought myself an oscilloscope to troubleshoot my problem with the K-line. When I used the oscilloscope to measure the K-line signal levels when triggering the LIN_KTX pin high and low I was able to read the traffic on the K-line pin with an oscilloscope. So I was able to create the initialization start with it, but then I found out that writing through Serial1.print seemed to do nothing. Has anyone confirmed the connection between the Serial1 and LIN_KTX works? I have selected Macchina M2 board in the set up and created an example code for troubleshooting my problem. I’m not really an expert on programming nor on serial ports so I can’t really say the connection with Serial1 and K-line is broken but to me it seems like it is.

Am I right that if I printed 0x00 in hexadecimals it’d look like being grounded all the time if it’s in a loop? I’m currently printing 0x00, HEX to the Serial1 and all I see in the oscilloscope is an almost straight 5 volt line. I will be testing as much as I can but I’d like to know if someone recognized the same problem. I’m very sorry for asking such dumb stuff but I’d like to be able helping create such great open source stuff as this project. I’d like to be as much help as I can even though I believe even my working code isn’t too perfect and ready-to-use as it is.

I can post my code if someone needs it, but it isn’t much use. Also, I’ve never done it nor really know how to do it. But the code is simply setting LIN_KRX, LIN_KTX, LIN_KSLP and PS_J1850_9141 pins on (output except for LIN_KRX) and high. Then beginning Serial1 at 10400 and printing 0x00, HEX there. I receive no sign of any activity. But when I wrote LIN_KTX high and low I was able to read it on the oscilloscope.

Best regards,


Inspecting schematics and finding out LIN_KTX pin (or actually the K TX pin on the left connector of the processor), I’ve found out it does nothing on the event of serial print. It does not go low as it’s supposed to or anything. So there might be the problem.


When trouble shooting such things I normally would use not just 0 but also FF and possibly mixes… I know nothing about K-line at this time but when looking you want to try all cases as you may be missing something.


Well. I’ve done some research on the K-line and it idles high and is driven low, so a logical 0 equals 0 volts, a logical 1 equals 12 volts (in this case 5 volts because it’s powered through USB) and the idle state is 12 volts (5 volts). So printing out a 0xFF would result in the same as idling the line, just the same as having no communication. I also tried 0x55 and other cases where there’d be some change between the bits. Still no effect.


I haven’t messed with the K-line stuff yet but have you tried powering the M2 from an ODBII port while testing it? It may require the 12 volts to work. You can have both the USB and the 12 volts from the ODBII port. I do this on my workbench now.

When you didn’t say you tried other values I assumed you only tried the 0x00 value. Sometimes you can tell if a device isn’t doing what you think it should by sending other values and seeing something happen.

Since I haven’t tinkered with the K-line stuff yet I am more or less shooting in the dark here trying to insure you tried everything I would try. I know a device I have sitting here that I use to develop with has to have 12 volts for some functions to work although others work fine just off USB but that’s not an M2.


I now know what is the problem. I tried writing serial directly to the K-line and it worked. But when I had sent initialization sequence it made it impossible to use Serial1 for ouptut at least. Perhaps for input as well? So driving the LIN_KTX pin as output and high makes it unusable for Serial communications. How can this be fixed?

I will try to drive the K-line with only serial communication in order to keep it up and serial communication doesn’t require any sort of setting the RX and TX pins I suppose. Now my problem is though that I have to send 0x33 to the car (also to begin it with a 200ms low and end with a 200ms high) at 5 bits per second. Is serial able to do that?

Also I have to receive 0x55 at the speed X for determining the speed. (10.4 kilobauds quite often, only it can’t be relied on) This would make it comply with the ISO standards if I’m correct. I’ve gathered the ISO 14230 documents but haven’t found any ISO 9141 documents yet.

And thank you redheadedrod for your help on my problem. I’m very glad to receive some interest in this subject even though you don’t have all the information required. Do you have a solution for the problem of serial communication becoming unavailable after driving the LIN_KTX pin high and low? Can it be reset somehow back to serial?


Best I can offer is there IS a K-line library out there that works already. Check out the “Project spotlight” and you may be able to find it. Even if not fully compatible with your vehicle you should be able to see how they do what they are doing and use that. It MAY be another protocol than what your looking for but should answer most of your questions.


And more specifically:


Well, I haven’t looked into the OBD9141 library too much anymore. I did try to access my car with the library. I even used it as a base for building my own software for accessing the K-line. Only it seems that it does not work for some reason. It didn’t get through to the car at all. I didn’t get any response, no matter how I tried. I even had serial monitor print me out some debugging data. I received no information on serial as I’d expect it to do now, not even with the OBD 9141 library. I’m quite sure it’s the Serial1 that’s broken out by LIN_KTX and LIN_KRX, or the fact that changing them to do anything will result in a broken Serial1 connection. I’m not sure if the SAM datasheet would answer my question better but the problem is probably the serial connection after using TX and RX pins for something else than Serial…

And one of the reasons for building my own K-line library is that the OBD 9141 isn’t fully compatible with K-line. It is ISO 9141 compatible, but not compatible with all the cars using the K-line. Also it isn’t Macchina M2 made, it’s Arduino made. And for a person who does not wish to program their own readers it’d be helpful to have a library already fully compatible with the K-line made for the M2 so that they wouldn’t need to do anything more than to upload the code and plug in the M2.


Thank you redheadedrod, I’ve solved my problem. Looking again in the OBD 9141’s code I found out what I was looking for all along. It is the SAM’s problem, that the registers for the pin had to be set, and after that I have my code working. I’ll be looking further into how I can get my car work with my code, but it seems to be possible after all.


Glad I could help. I am in the process of writing a new firmware package for the M2 which is intended to be more modular. I have the SWCAN, CAN and J1850VPW stuff to work from now but will be looking to add support for the K-Line stuff and J1850PMW stuff once I get this stuff running so certainly will be interested in incorporating anything that people come up with.


I would love to take a look at your code I’m about to start working on a new project and I think it would be a big help



Could you please share the code fix that you made to make this work ?? Thanks in advance.