CAN-BUS sheild - can't get demo code to compile.

Ok, obviously I’m a noob because I can’t work this out.

The board I bought is this one:

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

I can’t get the demo code for the CAN-BUS shield to compile, let alone connect it to a car and start streaming CAN over OBDII. The demo code came from the board designer -SK Pang.

http://www.skpang.co.uk/catalog/arduino … p-706.html

I’ve tried on Arduino 0022, 0023 and the new version 1.0, including changing out all the…sLCD.print(COMMAND,BYTE); to ```
sLCD.write(COMMAND);


The errors I get now are probably related to some of the other driver calls. I can't work out why some of the ".h" includes get highlighted correctly and others do not. For example, in the code there is:

#include <SdFat.h> /* Library from Adafruit.com */
#include <SdFatUtil.h>
#include <NewSoftSerial.h>
#include <Canbus.h>

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;


Does that mean I need to track down some other drivers from yet another website? When I go to the Adafruit website, they say that their SD card drivers are now part of the official distribution of Arduino, so do I need to replace them or not? The canbus driver was easy enough. I extracted SK-Pangs can-bus library into the "libraries" folder, and the editor now sees "canbus" as a keyword ok, but where do I find the "SDFatUtil, SDFat and NewSoftSerial" includes?

Amongst the gazillions of errors I get during compling are:

ecu_reader_logger.cpp:15:58: error: SdFat.h: No such file or directory
ecu_reader_logger.cpp:16:23: error: SdFatUtil.h: No such file or directory
ecu_reader_logger.cpp:17:27: error: NewSoftSerial.h: No such file or directory
ecu_reader_logger.pde:-1: error: ‘Sd2Card’ does not name a type
ecu_reader_logger.pde:-1: error: ‘SdVolume’ does not name a type
ecu_reader_logger.pde:-1: error: ‘SdFile’ does not name a type
ecu_reader_logger.pde:-1: error: ‘SdFile’ does not name a type
ecu_reader_logger.pde:-1: error: ‘NewSoftSerial’ does not name a type


Grrr. I've spent hours trying to work this out. It's very frustrating. Anyone know what I'm missing, or why the example code straight from the manufacturers website would not work "out of the box"? I can understand why they might not work in version 1.0 as it is so new, but builds 0022 and 0023 have been around for some time now.

Any assistance appreciated.

Have you got the NewSoftSerial and SDFAT libraries installed? You will need to download them and save them to the libraries directory. I think if you search for NewSoftSerial on the Arduino playground you should find it. I am not sure where you can get the SDFat library, but probably from google.

The following will get it to compile with Arduino 1.0, whether it will work properly or not I can’t check. I will assume that you have downloaded the Canbus library and it is located in the Arduino folder under \libraries\Canbus\

First, copy the folder:

\libraries\SD\utility\

to the folder

\libraries\Canbus\utility\

Then replace:

#include <SdFat.h> /* Library from Adafruit.com */

#include <SdFatUtil.h>

#include <NewSoftSerial.h>

with:

#include <utility/SdFat.h> /* Library from Adafruit.com */

#include <utility/SdFatUtil.h>

#include <SoftwareSerial.h>

Third, goto Find (CTRL+F on windows, or Edit->Find), and replace all instances of:

NewSoftSerial

with:

SoftwareSerial

Fourth (which I think you have done), replace all calls of:

sLCD.print(… ,BYTE);

with:

sLCD.write(… );

Fifth, comment out the line:

file.writeError = 0;

(I think it is line 261?)

Finally, open these files in a text editor (e.g. Notepad):

\libraries\Canbus\Canbus.cpp

\libraries\Canbus\mcp2515.c

and replace:

#include “WConstants.h”

with:

#if defined(ARDUINO) && ARDUINO >= 100

#include “Arduino.h”

#else

#include “WConstants.h”

#endif

Crikey! It compiles. Thanks very much. Now to the garage!

BTW, after posting the question, I did have a guess that “NewSoftSerial” was probably superceded by “SoftwareSerial”, but there is no way I would have worked out the bit about copying the “utility” files from one driver folder to another, nor would have I ever guessed how to solve the “wconstants.h” issue!

As an aside, with the #includes for the utility files, I assume that means a relative path below the current working folder. How does it know which is the folder to start at? The sketch itself is located in a completely different folder so why would the compiler know to start in the libraries/can-bus folder and not a subfolder of one of the other drivers.

Other than that, thanks very much mystery internet person!

It starts from any folder in which you have #include <folder.h>, e.g. you have CanBus.h, so it will try to find it at Canbus\utility. If it exists in more than one folder, the first one found is used (not quite true). I have a sneaking suspicion that if you had called #include <SD.h>, you wouldn’t have needed to copy the folder, but then you would have also got a load of code from that library which you don’t need.

As for wconstants.h, if you search google for how to convert a library to version 1.0, you will find it (wprogram.h is the same, but there were no calls to it so nothing to change).

Hey guys,

I’m using an Arduino 1280 MEGA with the CAN Shield, I was just wondering could someone tell me what are neccessary to be wired up and what do the TX and RX lines do?.. Do I connect them to the Arduino 1280?.. Also What do I connect the CAN High and CAN low pins to (if any) on the actual board…

any help would be appreciated