Go Down

Topic: New MCP2515 CAN Library Available (Read 17463 times) previous topic - next topic


Last month I bought a CAN shield from Sparkfun in order to display gas mileage statistics in realtime for my OBD2-compatible car.  I could not find a CAN library the did what I needed written in English, so I decided to write my own from scratch.  I thought I would share it, in case it might be useful to anyone else.

The library has the following functions:
static boolean initCAN(int baudConst);
static boolean setCANNormalMode();
static boolean setCANReceiveonlyMode();
static boolean receiveCANMessage(CANMSG *msg, unsigned long timeout);
static boolean transmitCANMessage(CANMSG msg, unsigned long timeout);
static byte getCANTxErrCnt();
static byte getCANRxErrCnt();
static long queryOBD(byte code);

It includes a tested example to display miles per gallon on an LCD display (I have been using this in my car for the past several weeks).




I offered my MCP2515 library to Sparkfun, but they never posted it.

Mines strictly CAN though, no OBDII.  Going to take a peek at yours to see what you've done on the OBDII side.


Dec 07, 2010, 11:54 pm Last Edit: Dec 08, 2010, 12:07 am by igorreal Reason: 1
Cool franksmicro!!

I´ve been tinkering with CAN bus for a while.....


I´m sorry,it´s in spanish. It´s not a proper library, it´s an explanation how to use MCP2515 and the basic functions needed.
I´ve some links to code and hardware.... I´ve just added a link to your library!

DaveAK, if you also have a library, please let me know the link and I could add. There are no many projects with CAN bus and Arduino.

I did this...



Igor, I like your LCD display!  Bet its expensive though.  I have the Sparkfun Nokia knockoff as well, but it is too small to display multiple parameters at a time so have not used it with OBD.


Dec 08, 2010, 05:05 pm Last Edit: Dec 08, 2010, 05:08 pm by igorreal Reason: 1
I've used a NewHaven Display => www.newhavendisplay.com/
It's very big and cool!!!!  ;D  I don't remember, but something less 70 dollars.
I've choosen one based on T6963 controller. I bought directly from this web.

It's very cool!!




Igor, I don't have my code posted any where yet.  I'll see about getting it up on google code or something like that.


DaveAK, I'd be interested in your code too, I'm working on an CAN Arduino project and some code would be beneficial.


So as not to hijack Frank's thread, I've posted my code over on the thread I started a few weeks back:


Go Up