First of all you need the Seeed CAN-BUS Shield’s Library downloadable at GIT-HUB



After downloading the CAN-BUS Library you need to import it into your Arduino Libraries folder.

In the Arduino Editor Select Sketch --> Import Library --> Add Library and then point it to the Zip file you downloaded, (No need to unzip the contents it can be imported as is.



Tip: You might have to rename the zip as the Arduino IDE does not like unusual characters , so maybe try canbus.zip instead of can-bus.zip

Something important to note:

The CAN-BUS Shield library comes with a working example, it does not include getting the CAN-ID which is quite important to know when analysing the data, So i modified it slightly to include the ID also to seperate all values with a comma so that you can use it as a csv file.

Copy and paste the below code into your Arduino Sketch Editor.

#include "mcp_can.h"<br> INT32U canId = 0x000;

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

void setup() { Serial.negin(115200); 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()<br>{ if(CAN_MSGAVAIL == CAN.checkReceive()) { CAN.readMsgBuf(&len, buf); canId = CAN.getCanId(); Serial.print(canId);Serial.print(","); for(int i = 0; i<len; i++) { Serial.print(buff[i]);Serial.print(","); } Serial.println(); } }

Hit the upload button to upload the sketch.