Tuesday, June 3, 2014

On 6:54 PM by Alexander Hiam   9 comments

Overview

Logic Supply's CBB-Serial cape includes an isolated CAN interface, which makes it easy to snoop on your vehicle's OBD-II bus.

What You Will Need

Wiring the Connector

The first step is to cut the OBD-II cable so you can wire it to the serial cape. You'll need the male end (with the pins inside) to connect to a vehicle, so cut the cable close to the female end to keep as much length as you can. Only three of the wires are needed to connect to the serial capes CAN interface: GND, CANH and CANL.


The color coding in my cable was GND -> solid yellow, CANH -> solid green, and CANL -> orange with a black stripe. You should check your cable with a continuity meter to be sure. Strip the wires and connect them to the screw terminals (I also connected the chassis pin to ground, which was solid orange):


Find the OBD-II connector in your vehicle; it was right under the steering column in my Chevy Colorado. Just to be safe, it is recommended that you plug the cable in while both the vehicle and the BeagleBone are powered off, then power the BeagleBone first. In reality the isolated transceiver on the serial cape should be just fine if you turn the vehicle on first. You will need to power the BeagleBone from the DC barrel jack, as not enough current can be supplied through the USB port to power it and the CAN transceiver.


Software

SSH into the BeagleBone and start by setting up the CAN interface:
  # ip link set can0 type can bitrate 500000 listen-only on
  # ifconfig can0 up

Next, install the can-utils package:
  # apt-get update && apt-get install git
  # cd /tmp
  # git clone git://gitorious.org/linux-can/can-utils.git
  # cd can-utils/
  # make
  # make install
  # cd ~

Now run the candump tool to start logging can packets to the terminal:
  # candump -cae can0,0:0,#FFFFFFFF
The above candump command will log all data and error packets to the terminal, reporting known error packets in human readable form, use color coding (if supported by your terminal), and will include ascii decoding. Run # candump --help' to see all the available options.

At this point if you turn your vehicle's ignition you should start to see CAN packets appear in the terminal like this:
  can0  0F9   [8]  02 0F 40 00 00 00 00 1B   '..@.....'
  can0  199   [8]  CF FF 0F FF EF FE 00 FF   '........'
  can0  0F9   [8]  02 0F 40 00 00 00 00 1B   '..@.....'
  can0  199   [8]  0F FF 0F FF F0 01 00 FF   '........'
  can0  19D   [8]  80 00 3F FE 00 00 00 FF   '..?.....'
  can0  1F5   [7]  0F 0F 00 01 00 00 03      '.......'
  can0  299   [2]  00 FF                     '..'
  can0  0F9   [8]  02 0F 40 00 00 00 00 1B   '..@.....'
  can0  199   [8]  4F FF 0F FF F0 00 00 FF   'O.......'
  can0  0F9   [8]  02 0F 40 00 00 00 00 1B   '..@.....'
  can0  199   [8]  8F FF 0F FF EF FF 00 FF   '........'
  can0  19D   [8]  C0 00 3F FD 00 00 00 FF   '..?.....'
  can0  1F5   [7]  0F 0F 00 01 00 00 03      '.......'
  can0  299   [2]  00 FF                     '..'
  can0  0F9   [8]  02 0F 40 00 00 00 00 1B   '..@.....'
  can0  199   [8]  CF FF 0F FF EF FE 00 FF   '........'
  can0  0F9   [8]  02 0F 40 00 00 00 00 1B   '..@.....'
  can0  199   [8]  0F FF 0F FF F0 01 00 FF   '........'
  can0  19D   [8]  00 00 00 00 00 00 00 FF   '........'
  can0  1F5   [7]  0F 0F 00 01 00 00 03      '.......'
  can0  299   [2]  00 FF                     '..'
  can0  0F9   [8]  02 0F 40 00 00 00 00 1B   '..@.....'
  can0  199   [8]  4F FF 0F FF F0 00 00 FF   'O.......'
  can0  0F9   [8]  02 0F 40 00 00 00 00 1B   '..@.....'
  can0  199   [8]  8F FF 0F FF EF FF 00 FF   '........'
  can0  19D   [8]  40 00 3F FF 00 00 00 FF   '@.?.....'
  can0  1F5   [7]  0F 0F 00 01 00 00 03      '.......'
  can0  299   [2]  00 FF                     '..'
If you don't see any output you'll need to stop candump by pressing , then change the bitrate for the CAN interface:
  # ifconfig can0 down
  # ip link set can0 type can bitrate 125000 listen-only on
  # ifconfig can0 up

and restart candump. You may need to try a few different bitrates before you find the right one for your vehicle. Standard rates include 125000, 250000, 500000 and 1000000. A Google search may also turn up the correct bitrate for you make and model.

9 comments:

  1. I'm just now looking at using a BeagleBone to connect to my car's CAN interface. I've never used a BeagleBone, so I'm trying to research its capabilities, and I hoped the author of this could clear up some of my confusion.

    Since the BeagleBone has two CAN interfaces (DCAN0 and DCAN1), why isn't it possible to simply use a breakout for the pins on the board itself and connect these wires to the car's OBDII? Why is a board like the CBB needed? Is it possible to send CAN data with this type of board, or is this why there are CAN transceiver capes on the market?

    Thanks for your help!

    ReplyDelete
    Replies
    1. The CAN module in the BeagleBone's processor can transmit and receive single-ended CAN packets at 0-3.3V levels. This requires an external CAN transceiver to convert between the single-ended 0-3.3V signals and the larger differential signals used on CAN buses like OBD-II. If you were to plug the DCAN pins directly to the OBD-II signals it would most likely destroy your BeagleBone because there would be large positive and negative voltages present.

      The other benefit of the CBB-Serial cape for automotive use is that the on-board CAN transceiver is isolated, which means that the BeagleBone is protected against the large voltage spikes that can be generated by the alternator.

      Delete
  2. Hello and thanks for the tutorial. I'm interested in this cape for interfacing with the CAN-BUS in my car. This cape will allow me to receive the CAN messages but will it also allow me to send messages to the CAN-BUS?

    ReplyDelete
  3. Hi Alex, great tutorial and cape. Received this cape last week and was reading CAN messages from my car in no time at all. Frankly, I didn't think it would that easy to setup but it was.

    ReplyDelete
  4. Hi, do you how I can use the beaglebone CANbus to connect to NMEA2000?

    ReplyDelete
  5. The NMEA 2000 standard was defined by, and is controlled by, the US-based National Marine Electronics Association (NMEA). Although the NMEA divulges some information regarding the standard, it claims copyright over the standard and the contents thereof are thus not publicly available.- wikipedia

    ReplyDelete
  6. Some additional information can be found here:
    http://www.nmea.org/Assets/2000-explained-white-paper.pdf

    ReplyDelete
    Replies
    1. Hi Richard,
      Thank you for you assistance. I have an Airmar Weather Station (200WX) sensor that uses NMEA2000 and I want to read its data using an arduino or a beaglebone black.
      The paper you provided is pretty good at explaining the communication protocol details.

      Delete