Introduction: DIY Beaglebone CAN Bus Cape

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

Comments

author
rocksram93 (author)2017-03-02

i have tried ,but log file is empty

author
JohnFL (author)2015-06-15

Can you send messages back to the bus with this implementation?

author
SagarB16 (author)JohnFL2015-08-24

Remember to ground Rs of the SN65HVD231 (pin 8) in case you wish to send messages back to the bus.

author
obrien28 (author)JohnFL2015-06-15

Hi John,

Technically yes, I haven't tried that on my car as of yet but the TI chip is a transceiver so two-way communication shouldn't be an issue. One thing you would want to change is the connect line from "ip link set can0 type can bitrate 500000 listen-only on" to "ip link set can0 type can bitrate 500000" removing the listen only flag. The only other issue is overriding the message that is already on the bus, if you wanted to alter say the speedometer, you would have to see how often that message gets sent and send yours slightly faster so it would overwrite it.

Let me know how it goes if you get it working.

author
SagarB16 (author)2015-08-24

Remember to ground pin 8 of the SN65HVD231 in case you also wish to transmit. From the datasheet of the SN65HVD231,

"The SN65HVD230 enters a low current standby mode (listen only) during which the driver is switched off and the receiver remains active if a high logic level is applied to the RS pin. This mode provides a lower power consumption mode than normal mode while still allowing the CAN controller to monitor the bus for activity indicating it should return the transceiver to normal mode or slope control mode. The host controller (MCU, DSP) returns the device to a transmitting mode (high speed or slope control) when it wants to transmit a message to the bus or if during standby mode it received bus traffic indicating the need to once again be ready to transmit."

The bbb apparently does not "return the device to transmit mode" and consequently, any attempts to send a can message result in a bus off error. Grounding Rs enables "high speed mode" and also lets you send messages :)

About This Instructable

24,361views

25favorites

License:

Bio: Liam O'Brien is a mechanical engineer and astronomer. Who, when not battling poorly directed streetlights and dew forming on lenses, likes to build things ... More »
More by obrien28:DIY Beaglebone CAN Bus CapeExploring the Tesla Model S CAN Bus
Add instructable to: