Hey everyone,
I just finished putting together a CAN library to use with MCP2515 CAN controller. It's a mix of most of the MCP2515 libraries out there and hopefully more user "Arduino" friendly. I was very frustrated with most of the libraries out there as they were made either hardware/shield specific or they mixed in OBD2 protocols to read codes, GPS location, etc... and there was very little documentation/examples.
What I tried to do is put together the best features of most of these libraries and use known functions like read(), send(), begin(). I have also added message structures for CAN (standard, extended), J1939 and CANopen with the correct message format (see the examples).
Its not shield specific so you can use it with Sparkfun, Seedstudio or your own shield. SPI CS is selectable through the sketch and you can control several MCP2515 controllers with one arduino as long as they don't have the same CS (I have done up to 4). The main goal was to have this used in home automation, car/truck/boat applications or simply to send messages between two or more Arduinos.
I have added some examples to the gitHub but I will have more coming, I will also be putting together a document with each function available so there is no need to go back and fort between sketch and header file.
Since I have taken features from so many libraries I can’t tell what came from where by now, so in order not to violate any GPL, LGPL or any other possible license out there I am trying to give credit where credit is due, see the libraries for all the acknowledgments. I am only a contributor to this library so some functions/work there might not be mine. I can only take credit for putting it together and releasing back to the public to make any variation as needed.
If you guys see any features you would like added, removed and modified let me know or send them through gitHub. I will be adding end(), clear(), and available().
I am also working on a CANboard with the Atmega328p, MCP2515 CAN controller and MCP2561/62 transceiver all in one so a CAN shield will not be required and you will have all the Arduino and MCP2515 pins/fucntionality available so you can use any shields you want like wifi, lcd screens, etc (SPI pins will be shared but CS will be selectable between pins 6,7 or 8 ) .
I haven't decided what connector to use yet, the db9 is a little bit of an overkill but it will work with any CAN cable out there (since I will make sure pin 2 is CANL and pin 7 is CAN H not like the odd sparkfun and seedstudio shields...). My prototype currently uses Molex Mini fit Jr 4 pin (CANh, CANl, V and GND) since they are cheap and can make my own cable. If anybody has some input I can look and see what can fit (RJ45 is an option) or just screw in connectors. If there is enough interest I can make a larger batch and make it available to you guys through Tindie.
Let me know what you guys think about the library! https://github.com/DRO/CAN-Library
Thanks!