Introduction: DIY Beaglebone CAN Bus Cape

About: Liam O'Brien is an electronics engineer and astronomer. Who, when not battling poorly directed streetlights and dew forming on lenses, likes to build things for both the physical and digital world. He also has…

This is an addendum to my other tutorial exploring the Tesla Model S CAN bus, for that tutorial I needed some way to connect and send messages over the CAN system, but didn't want to pay and arm and a leg for a fancy Serial "Cape". So I opted to make my own using some cheap, off the self IC's and some other electronic paraphernalia. The build is pretty simple and nothing to look at, but it works well and is fairly inexpensive.

Step 1: Parts List

Here are the following things you will need:

The Essentials

  • 1x Texas Instruments SN65HVD231 CAN Transceiver - Digikey
  • 1x SMT Breakout PCB for SOIC-8 - Adafruit (similar product available from Sparkfun, but Adafruit gives you a pack of 6 for a better price)

  • 1x Serial DE-9 breakout board - Sparkfun
  • 1x OBD-II to DE-9 Cable - Sparkfun

Parts and tools you may already have:

  • Male Breakaway headers - Adafruit
  • Hookup wire - Adafruit
  • Soldering Iron
  • Solder Wire
  • Some helping hands, mechanical or otherwise
  • Flush cutters (nail clippers also work in a pinch)
  • Wire strippers
  • A multimeter to test your connections
  • Patience and a can do attitude - No online vendors

Step 2: Building the CAN Transceiver for Fun and Profit

My build was fairly quick and dirty as you can probably tell from the soldering job, but it works.

The third photo shows you a schematic of the whole layout which is fairly simple so I won't spell it all out here. Basically you are hooking up the Beaglebone RX/TX lines to the TI CAN transceiver, then from there you go out to the vehicle bus, which is usually on pins 6 and 14 of the OBD-II port, located somewhere underneath the drivers side dash/steering wheel. If you have trouble finding it, try a quick google search, some are hidden behind flaps or panels.

Datasheet:SN65HVD231

Step 3: Blending the Hardware and Software

In order to interface with the CAN bus on the Beaglebone you need to install can-utils, they are a set of the helpers written in C to make talking to a can system dead simple.

To install this you will need a Beaglebone Black running the latest version of Debian, (which comes stock on all new boards you might buy) some kind of internet connection (wifi dongle, ethernet, USB sharing) and a way to power your BB, I used my USB cable.

Step 1 is to SSH into your BB, do this by typing (on a Mac)

ssh root@192.168.7.2 

into your terminal, this IP will only work if you are connected via USB and have the drivers installed.

Step 2: Then run this set of commands, each line begins with a #, don't type that in your terminal though.

# apt-get update && apt-get install git   
# cd /tmp   
# git clone https://github.com/linux-can/can-utils.git   
# cd can-utils/   
# make   
# make install
# cd ~

At this point if there are no errors then you should have can-utils installed. Try running the command "candump" if you see a help guide come up, then you are ready to roll.

Step 4: Communication Is Key

Before you start the CAN interface you will have to enable the device tree overlay for it, since my simple cape doesn’t have EPROM to pass the Beaglebone any settings. For details on that please see this tutorial.

To start the CAN interface and set the communication speed, type the following commands

ip link set can0 type can bitrate 500000 listen-only on
ifconfig can0 up

The first sets your CAN interface as can0 and your transmission rate at 500Kb/s, the second brings it online.

Note: to take your interface down just type down instead of up for the second command.

Step 5: Logging Your Hard Earned Data

To start seeing some data just enter the following command in your terminal after following the previous step.

candump -cae can0,0:0,#FFFFFFFF

This will output all of the CAN messages (including errors) to your terminal window.

If you see something like this scroll across your screen, you can pat yourself on the back, everything is working normally.

(1423606588.555165) can0 00E#1E563FFF08FFA066
(1423606588.555434) can0 102#CA98F8FFEEFF (1423606588.555881) can0 202#845E6B9D00007102 (1423606588.556169) can0 6F2#1634B40D1D43C3D0 (1423606588.556193) can0 212#5800227400 (1423606588.556455) can0 23A#000B001200050000 (1423606588.556678) can0 21A#FE0000FE000000B7 (1423606588.556902) can0 222#0000DA98F01070 (1423606588.557139) can0 29A#0000FE0000000000 (1423606588.557481) can0 27A#292903DC092600

This displays all the CAN messages in real time, on most systems this is too fast to do an kind of decoding, so when you are done just hit Ctrl+C.

Next lets type the same command but change a few parameters:

candump -l any,0:0,#FFFFFFFF

This will log out all the data to a file in your current working directory, with a name that looks something like this candump-2015-02-10_221628 2.log Once you have that, it's time to start decoding what's happening in your vehicle.

Step 6: What Does It All Mean?

Once you have the data logged you are only halfway there, decoding it is the real challenge.

Every car is different, manufacturers have proprietary codes and data schemes, they output CAN buses on various connectors and generally don't publish any kind of Roseta Stone for decoding any of this, so most of the time the only way to find out is good old trial and error.

Since I can't anticipate what kind of car you might have, I am including a list of resources for some of the more popular makes out there, but this is only scratching the surface. If yours isn't listed here, then a few minutes worth of cursory searching should turn up lots related information.

For those of you interested in the Tesla Model S please see my other Instructable

A more general overview of the CAN bus system from security experts Charlie Miller and Chris Valasek.

Car Hacking

Makes/Models:

Toyota Prius

Chevy Volt

Jeep Wrangler

Mini Cooper

BMW

Audi