CANbus Shield + Uno

Hey all, I am a bit of a newbie to Ardunio but I checked through all the forum posts that I could and I am unable to find a solution to my problem and I am hoping that someone here has a bright idea.

I have an Uno with this shield :

http://www.sparkfun.com/products/10039

and I loaded the latest ECU polling software from here :

http://www.skpang.co.uk/catalog/arduino-canbus-shield-with-usd-card-holder-p-706.html

I have another node that I want to log raw CAN data from that is terminated correctly. I have tested this node with a CAN to USB adapter and verified that it correctly sending CAN data. However, when I run any version of this software, or the CAN software described by this post :

http://modelrail.otenko.com/arduino/arduino-controller-area-network-can

no messages are received and no data is added to the buffer.

I have tested the loopback software described by the "otenko" post and that works perfectly. Additionally, I placed a 120 ohm resistor on the test points between the CAN-H and CAN-L pins which should terminate the network on the Arduino side.

Any help would be appreciated.

You should describe your wiring in a bit more detail. From what I understand you have connected the UNO with this shield to your car's ECU. Correct? And you don't get any data from your car? What car is it? Which connector are you using?

Also you seem to have connected some unspecified "other node" to this setup which seem to have an USB connector. What are you doing with this device, what is it's intended use?

Please describe what you wanna achieve. It may be clear to you what your goals are, we don't know them.

and I loaded the latest ECU polling software from here :

Which "sketch" are you trying to use (and from which version)

Are you trying to connecto to a CAN bus that is already made (example: a vehicle). If so, then note that the bus is properly terminated and you should not add any resistor to the network. But from what I understand, you have 2 nodes; Arduino and 'other node'...in which you need the terminator resistor.

What is the baud-rate of the other node you wish to data-log? And check your baud-rate you are using in your code. Could you post the arduino sketch?

Hi all, I have a Sparkfun CAN-BUS (http://www.sparkfun.com/products/10039) and an Arduino UNO. I have a problem with all libraries that I dowloaded. The messages that I try to send remains in the queue and so the arduino buffer became full (I use the monitor to see that). I guess that is not a problem related to the libraries.

Anyone can help me? Anyone use Sparkfun canbus and an Arduino UNO???

Any help would be appreciated.

Thanks a lot! :)

Hi androrossi,

What library are you using? and what exactly are you trying to use the library for (provide your sketch, whether or not you are using the SDcard/LCD functions etc.)

Hi johnnyonthespot,

the library that I use is http://code.google.com/p/skpang/downloads/detail?name=Canbus_v4.zip&can=2&q=
I want to use the library only to send a message by Can-bus protocol; below the code that I use:

#include <Canbus.h>
#include "mcp2515.h"

#define CANSPEED_125 	7		// CAN speed at 125 kbps
#define CANSPEED_250  	3		// CAN speed at 250 kbps
#define CANSPEED_500	        1		// CAN speed at 500 kbps

int CANCS = 53;  /* SPI Enable for CAN */

int D10 = 10;

int LED2 = 8;
int LED3 = 7;

void setup() {
  Serial.begin(9600);
  Serial.println("CAN BUS test start");

  if(mcp2515_init(CANSPEED_250))
  {
    Serial.println("CAN init OK");
  } 
  else
  {
    Serial.println("CAN init KO");
  }

  pinMode(LED3, OUTPUT); 
  pinMode(CANCS,OUTPUT);

  delay(4000); 
}

void loop() 
{
  digitalWrite(CANCS,LOW);

  if (mcp2515_check_free_buffer())
    Serial.println("Free buffer");     
  else
    Serial.println("Full buffer");

  tCAN message;	
  message.id = 254;//0x7DF;
  message.header.rtr = 0;
  message.header.extended = 1;
  message.header.length = 8;
  message.data[0] = 0x02;
  message.data[1] = 0x01;
  message.data[2] = 0x05;
  message.data[3] = 0x00;
  message.data[4] = 0x00;
  message.data[5] = 0x00;
  message.data[6] = 0x00;
  message.data[7] = 0x00;						

  mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);

  if (mcp2515_send_message(&message))
    Serial.println("Send ok");     
  else
    Serial.println("Send ko");

  delay(10);  

  if (mcp2515_check_message())
  {
    Serial.println("Message waiting");     
    if (mcp2515_get_message(&message))
      Serial.println("Read OK");
    else
      Serial.println("Read KO"); 
  }     
  else
    Serial.println("No message waiting");

  digitalWrite(LED3, HIGH); 
  delay(500); 
  digitalWrite(LED3, LOW);
  delay(500);

  delay(4000); 

  Serial.println("");


  digitalWrite(CANCS,HIGH);
}

Anyone use this library: http://code.google.com/p/skpang/downloads/detail?name=Canbus_v4.zip&can=2&q= ??? Is my code correct?

Witch other library I could use? Any code example?

Thanks a lot!

I started out with this library (strictly CAN): CANduino

http://code.google.com/p/canduino/source/browse/trunk/Library/CAN/?r=16

My sketch is below, it is functional. Perhaps you can start with this library as well? I don’t like the libraries that cram all CAN/LCD/SD-card in one messy file.

//Simple CAN sketch. Outputs 2 different CAN-Messages @ 100Hz
//Johnnyonthespot

#include <CAN.h>
#include <SPI.h>

#define BUS_SPEED 500

//global variable used to determine whether loop should
//be in Tx or Rx mode.
int state;
//global variable used to toggle pin
int pin;

void setup() {                

  
  Serial.begin(9600);
  
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  
  // initialize CAN bus class
  // this class initializes SPI communications with MCP2515
  CAN.begin();
  CAN.baudConfig(BUS_SPEED);
  CAN.setMode(NORMAL);
  //CAN.setMode(LOOPBACK);  // set to "NORMAL" for standard com
  
  //Wait 10 seconds so that I can still upload even
  //if the previous iteration spams the serial port
  delay(100);
  
  state = 0;

  pin = LOW;  
}
byte val = 0;
void loop() {
  
  byte length,rx_status,i;
  unsigned short frame_id;
  byte frame_data[8];

      frame_data[0] = val;
      frame_data[1] = 0xAA;
      frame_data[2] = 0x00;
      frame_data[3] = 0xFF;
      frame_data[4] = 0x1A;
      frame_data[5] = 0xCF;
      frame_data[6] = 0xFC;
      frame_data[7] = 0x1D;
  
      frame_id = 0x1d4;
      length = 8;
  
      CAN.load_ff_0(length,frame_id,frame_data);
      CAN.load_ff_1(1,0x1d5,frame_data);
      CAN.send_0();
      CAN.send_1();
      //CAN.load_ff_2(1,0x1d6,frame_data);
      //CAN.send_2();
      
 
       val++; 
  delay(10);

}

I am also having trouble using my CAN shield with the arduino and have tried to implement your code that you supllied and the CAN librarey from the canduino project but i get this error...

In file included from sketch_jul18a.cpp:4: C:\Documents and Settings\Shuttle\Desktop\arduino-1.0.1-windows\arduino-1.0.1\libraries\CAN/CAN.h:102:22: error: WProgram.h: No such file or directory

do you know what i have done wrong or is there another file i need to download?

thanks in advanced.

do you know what i have done wrong?

Tried to use a pre 1.0 library in 1.0+.

is there another file i need to download?

Fix that one. Change WProgram.h to Arduino.h.

I suppose I should have mentioned that the arduino version I used was version 022.

The code has now compilied and writen to my Aruino uno, if i now look at the output pins on the CANBUS shield should I see the data being transmited. I am just doing sum research on bus systems and how there data is transfered and what the signals look like.

Cheers. :)

You could always tap into pins 6/14 on your vehicle OBDII connector to view the traffic on an oscilloscope *if the vehicle was made in/after 2008

Hi all,

anyone know NMEA2000 bus( http://en.wikipedia.org/wiki/NMEA_2000 ) ??? Shall I use some CAN library to send data in a NMEA2000 bus?

Thanks a lot!

Jonneyonthespot,

i do not have my shield connected to anything at the moment i just assumed the board would just send its data out on CANH and CANL regardless of if anything is there to recieve the messages. am i incorrect in assuming this because what i can see on the scope is certainly not a data signal…

if i connected it with my other arduino and CAN shield could i just prog that one to recieve the Data?

thanks for your help

solved the problem by the way just me bieng stupid :slight_smile:

Excellent...Feel free to ask any more questions. I've done alot with CAN and would be happy to help out.

Johnnyonthespot,

Here's what I'm trying to do. I bought an Arduino r3, the 100039 Can-bus shield, and obd2 to db9 cable. I have a k40 RL360 radar detector that has 2 led's that flash when either the front or rear detector goes off. I want to display some sort of a radar strength graph on my dashboard display of my VW 2007 Passat. Ideally I just tap into the can bus network without the obd2 cable but I got that for starters...

I know c++ very well and have done a ton of research about this topic. This pdf has a lot of info about what my car's canbus network is like...http://www.volkspage.net/technik/ssp/ssp/SSP_340_d2.pdf

My plan as of now would be to read the hot of the individual led's with the arduino and then use that info to display the graph on my display.

Any help would be greatly appreciated.

This might help out...

https://docs.google.com/spreadsheet/ccc?key=0AkdcRjaPK8bSdGdZOG9uWWtsQkk0dUlfTUNySGlTVEE&hl=en#gid=0

what is this ‘display’ you are trying to use? if you are attempting to hi-jack the dashboard in your vehicle while it is still on the vehicle CAN network bus, you’ll find this very challenging because you will be competing with the vehicle at using the dashboard…and neither of you will win in this case. If you have a dash which is not on a vehicle network bus that you are using, you’ll need to know what CAN messages are required to perform the functions you want.

It’s still abit unclear what you are aiming to do.