Building a CAN-BUS Sniffer (Hardware)

Building a CAN-BUS Sniffer (Hardware)

Postby MartinViljoen » Wed Oct 08, 2014 5:27 pm

logo11.jpg

There is not much to it you just need to buy the hardware.

The two most important parts are.
Arduino UNO and CAN-BUS shield from SeeedStudio I bought mine here http://www.seeedstudio.com/depot/CANBUS ... -1240.html
Some more information on the shield http://www.seeedstudio.com/wiki/CAN-BUS_Shield

The Shield simply stacks onto the the Arduino UNO and is hooked up to your vehicle like this.
setup.jpg


You dont have to connect it to the Radio's CAN-BUS wires but for me it was easier.

Below is the code you need to dump all Data to the Serial port of the arduino, which can then be read to a serial client like hyper terminal,putty (I recommend putty.exe)
Code: Select all
//This Arduino UNO Sketch requires the Seeed CAN-BUS Shield Libraries
//https://github.com/yexiaobo-seeedstudio/CAN_BUS_Shield
#include <SPI.h>
#include "mcp_can.h"

INT32U canId = 0x000;

unsigned char len = 0;
unsigned char buf[8];
char str[20];


void setup()
{
    Serial.begin(38400);

START_INIT:

    if(CAN_OK == CAN.begin(CAN_125KBPS))
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }
}


void loop()
{
    if(CAN_MSGAVAIL == CAN.checkReceive()) 
    {
        CAN.readMsgBuf(&len, buf);
        canId = CAN.getCanId();
        Serial.print("<");Serial.print(canId);Serial.print(",");
        for(int i = 0; i<len; i++)
        {
            Serial.print(buf[i]);Serial.print(",");
        }
        Serial.print(">");
        Serial.println();
    }
}


In the above code take note of the speed of the Arduino Serial port as well as the serial speed between the vehicle and CAN-BUS shield.
Generally the interior bus runs at 125Kbps and the OBD2 port runs at 500kbps, dont get this wrong because the your vehicle's CAN-BUS system will not like it.
Also dont get the wires the wrong way round (I got both the wrong way round)

When I set the speed to 500Kbps the Jeep went bonkers , the dash light up like a Christmas tree , wipers went up and down and it was making a "Bing Bing Bing" noise.
When i swopped the wires the radio went dead, luckily nothing was damaged! Be carefull.

Code: Select all
if(CAN_OK == CAN.begin(CAN_125KBPS))
- Is where you set the communication speed between the Vehicle and CAN-BUS shield.
Code: Select all
 Serial.begin(38400);
- Is where you set the baud rate of the serial port on the arduino, make sure the speed is the same on the serial client I.E Putty
If not the data coming into putty will appear to be corrupt. (Weird characters)

Below is an example of data coming from my Jeep into putty.exe
putty.png


Important Note
Although when i built this for my Jeep it worked without having to do the following , some people reported that you need to de-solder the CAN-BUS terminator on the board.
viewtopic.php?f=14&t=18&start=20#p53 (Special thanks to Andy and his friend for finding this)
You do not have the required permissions to view the files attached to this post.
Image
User avatar
MartinViljoen
 
Posts: 109
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a CAN-BUS Sniffer (Hardware)

Postby syd4j13 » Sun Oct 26, 2014 1:16 pm

EDIT:i have solved the problem. i use a session of windows without admin privileges, so i tried to execute arduino.exe with admin privileges and the error disappears.


Hi Martin,

I am trying to use the Software superSniffer but I have this problem in compiling the code.

sketch_oct26a.ino: In function 'void setup ()':
sketch_oct26a: 19: error: 'CAN' was not declared in this scope
sketch_oct26a.ino: In function 'void loop ()':
sketch_oct26a: 35: error: 'CAN' was not declared in this scope

I attached a picture of the error.

How I can fix it?
Probably the solution is simple but I'm a beginner in arduino

Thank you and congratulations for the program.
You do not have the required permissions to view the files attached to this post.
syd4j13
 
Posts: 4
Joined: Fri Oct 24, 2014 10:53 pm

Re: Building a CAN-BUS Sniffer (Hardware)

Postby syd4j13 » Sat Nov 01, 2014 4:18 pm

Hi Martin,

Today I tried the shield but I have not gotten it to work.

I printed by the serial port the CAN_MSGAVAIL value and the CAN.checkReceive() value and I have obtained their value was 3 and 4 respectively.

So they will not print any value because is not even read.

Could you say how can do tests to check it out?

I connected the canh and canl to the radio port.

Thank you
Regards
syd4j13
 
Posts: 4
Joined: Fri Oct 24, 2014 10:53 pm

Re: Building a CAN-BUS Sniffer (Hardware)

Postby Andy26 » Mon Nov 03, 2014 5:34 pm

syd4j13 wrote:Hi Martin,

Today I tried the shield but I have not gotten it to work.

I printed by the serial port the CAN_MSGAVAIL value and the CAN.checkReceive() value and I have obtained their value was 3 and 4 respectively.

So they will not print any value because is not even read.

Could you say how can do tests to check it out?

I connected the canh and canl to the radio port.

Thank you
Regards


Hi,
if you are using a seeedstudio can shield, you can take a look on my post viewtopic.php?f=14&t=18&start=20#p53 maybe it will help you
Andy26
 
Posts: 2
Joined: Mon Nov 03, 2014 5:16 pm

Re: Building a CAN-BUS Sniffer (Hardware)

Postby syd4j13 » Tue Nov 04, 2014 12:57 am

Thank you Andy26

I just now desoldered the Resistor R3 and the leds of shield are more brightness and now the supersniffer reads the data :D .

This solve the problem, now the problem is decrypt the codes. :roll: :roll: any advice?

Thank you again
syd4j13
 
Posts: 4
Joined: Fri Oct 24, 2014 10:53 pm

Re: Building a CAN-BUS Sniffer (Hardware)

Postby bringo » Fri Mar 06, 2015 7:39 am

Hello,

I am having the problem where I receive the error:

sketch_mar05h.ino: In function 'void setup()':
sketch_mar05h.ino:17:18: error: 'CAN' was not declared in this scope
sketch_mar05h.ino: In function 'void loop()':
sketch_mar05h.ino:33:24: error: 'CAN' was not declared in this scope
Error compiling.

I know another user asked this question earlier, but I still cannot get it to work even after running as an admin. can you or anyone else point me in the right direction?
bringo
 
Posts: 1
Joined: Fri Mar 06, 2015 7:35 am

Re: Building a CAN-BUS Sniffer (Hardware)

Postby gtaion » Tue Aug 11, 2015 2:12 am

Code: Select all
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN);                   // Set CS pin


I got a new v1.2 CAN-Bus shield and was having trouble with a bad init. Hopefully the above formats correctly because after changing the cs pin everything started working correctly.
gtaion
 
Posts: 7
Joined: Fri Jul 31, 2015 5:09 am

Re: Building a CAN-BUS Sniffer (Hardware)

Postby sunxemx » Mon Oct 19, 2015 2:54 pm

I just bought myself the Arduino uno and the CAN Bus shield to do the CAN-BUS sniffer project.
I am trying to compile the code but it stops at "'CAN' was not declared for this scope"
Can someone please tell me what is wrong and how to correct it please.

if(CAN_OK == CAN.begin(CAN_125KBPS)) This is the line that it is pointing at.

SOLVED

For some unknown reason pluging the Arduino to the computer and running the software as an administrator solved the problem.
sunxemx
 
Posts: 2
Joined: Fri Oct 09, 2015 5:21 pm

Re: Building a CAN-BUS Sniffer (Hardware)

Postby nlesko » Wed Oct 28, 2015 5:26 pm

sunxemx wrote:I just bought myself the Arduino uno and the CAN Bus shield to do the CAN-BUS sniffer project.
I am trying to compile the code but it stops at "'CAN' was not declared for this scope"
Can someone please tell me what is wrong and how to correct it please.

if(CAN_OK == CAN.begin(CAN_125KBPS)) This is the line that it is pointing at.

SOLVED

For some unknown reason pluging the Arduino to the computer and running the software as an administrator solved the problem.


I have exactly same issue but this solution doesn´t help. What else can I try?

SOLVED

I just added this two lines of code and it works!!! My shield is v1.2 and arduino 1.6.5 running as admin

Code: Select all
const int SPI_CS_PIN = 9;
MCP_CAN CAN(SPI_CS_PIN);
nlesko
 
Posts: 1
Joined: Tue Oct 13, 2015 8:12 pm


Return to OBD2 & CAN-BUS Projects

Who is online

Users browsing this forum: No registered users and 3 guests

cron