Connecting to Automotive CANBus

02 Jan 2010 . Edited: 02 Jan 2010

I was just curious if anyone had any experience connecting their MBED to the CANBus of a vehicle? I would really like to do just that. I currently have two vehicles that each support CAN, and I would like to connect to them to log information from the ECU. I have looked at the CANBus page here on the site and it appears that I just have to connect my mbed and CAN transeiver up to the OBD port and start listening/talking. Anyone know if this will not work, or have any other advice/pointers?

Thanks,

Matthew

04 Jan 2010

Matt,

I believe that is about all you should have to do to get at least the basic On Board Diagnostic II codes.  It sounds like you confirmed that your specific year and model of vehicle does support the CAN version of OBDII, as there are almost half a dozen different hardware layers (pulse code modulaiton and various other serial like schemes...)  I am interested in doing this as well, but haven't gotten all the parts together yet.  Here is my current plan:

  • Buy a Male J1962 connector (i've seen various ones for $5 - $20 or so online, some with db9 ends some with just pigtails...) (Here is one random example...)
  • Buy a CAN transciever (TI's SN65HVD232 is used on Stern Technologies AVR OBDII Schematic, the MCP2551 is used on page 58 of the ELM327 schematic and on the IAR LPC1768 Eval Board Schematic)
  • Hook in CANH to J1962 pin 6, hook CANL to j1962 pin 14, hook the MBED's ground to pin J1962 pin 5 (signal ground)
  • Maybe throw in a 120 ohm resistor between CANH and CANL right near the transciever...
  • I'd write a quick test program to use the existing CAN in/out to continually read and echo any bytes over the usb serial debugging port...
  • After I get some basic connectivity, I would read up on ODBII codes and perhaps do some query/report type stuff, or perhaps parse the codes on the MBED and log pre-cooked data etc...

For data logging, if you want to do just a couple megabytes or less, you can use the existing FLASH, otherwise I'd consider hooking up an external SPI based SD card or the like as described in some of the cookbooks...  I wrote a small app to log temperature data to the local flash, it could be modified to save the incoming CAN messages for future offline parsing etc...

Let me know your thoughts, as I'd like to try it out too... Another option would be to buy an ODBII device that implements all of the various protocols and outputs RS-232 and just hook that up to the MBED, but that wouldn't be quite as fun would it?!

Thanks!

-John

04 Jan 2010

John, this is exactly what I am thinking/planning!  I have the transevier, the MCP2551, and a J1962 connector.  I need to pick up an SD or micro SD board, waiting for Sparkfun's Free Day, then I will just test out snooping on the bus and logging to SD.

After that I believe I have the codes somewhere to request data from the ECU.

That is my plan, if I can get around to it.  I have a 1 year old, so my time is not my own!

Matthew

04 Jan 2010

Hi guys, I am working on a project like this also.  I'll be connecting to an aftermarket ECU called megasquirt.  I'm using the TI CAN transceiver.  I'm also using a motorola J1850 transceiver so I can connect to my J1850 VPW pickup.  Got both transceivers soldered to a sparkfun SOIC to DIP breakout but that's the extent of it so far.

--steve

05 Jan 2010

I think you should look at using the ELM327 chipset via serial, as it can obtain the ODB2 information from a variety of sources(CAN AUTOSYNC/K-LINE/ETC). And will make your device compatible with more different makes and models, and your code a-lot more simpler.

05 Jan 2010

The problem with the ELM chips is that they don't do the GM VPW 4X mode.  It's a high speed mode that is outside the J1850 spec.  Admittedly a corner case but that's why I'm going with just a line driver instead of an ELM.  Otherwise that ELM327 looks like a very good solution.  thanks for posting it.

--steve

20 Jan 2010

I ended up going the 'cheating' route and buying a ~$70 ELM327 based serial scantool from OBDPros.  I bought a DB9 w/ level transciever built in from sparkfun (as I'm even too lazy to hook up one of my dip max232s these days...), and a null modem and gender changer from ye olde radio shackee... Sort of bulky, but after loading the serial pass-through example from the handbook and running minicom on my linux box to /dev/ttyACM0 9600 8N1 it "just worked"!  yay!

So now I can put together a data logger and maybe do something as cool as this guy did with a GPS and google earth!

I had good luck with engine rpm and speed, but there is a lot of useful stuff that doesn't seem to be standard or work on my 2005 Hyundai Elantra (e.g. Odometer...)...

I'm still curious about the CAN transciever interface (though I don't think my car even uses it...) Keep us posted if you get it working!

-John

20 Jan 2010

That google earth thing is really cool -- exactly the kind of thing I had in mind to do.

--steve

23 Feb 2011

Interresting field. In principle it should be possible to connect to the bus and get a signal (message) for example to turn on the brake lights. Right? This is on a higher level protocol than canbus? Are these canbus messages public information? And are they the same from car-make to carmake? If you find the message for turning on brake lights and make a third brake light in your car, will it still function in another make? Or can this message mean something completely different in another car?

You should also be able to send messages, for example to turn on the windscreen wipers?

I once read about a guy that controlled the windows motors from his laptop from the backseat of his mercedes.

best regards Torfinn Sornes

12 Sep 2014

Hi guys, i'm working on a project that has to do with obtaining odometer by connecting a device to can L and can H to get odometer codes. I've been able to acquire for good number of vehicles but still have issues with vehicles like Toyota Hilux, Mistibushi Lancer, Mistibushi L200, Toyota Hiace. I really need help on how get these vehicles odometer protocol.