How to write CAN message to serial monitor?

Hello,

I am working with the following code below.

#include <SPI.h>          //SPI is used to talk to the CAN Controller
#include <mcp_can.h>

MCP_CAN CAN(9);          //set SPI Chip Select to pin 9

void setup()
{
  Serial.begin(115200);   //to communicate with Serial monitor

  //tries to initialize, if failed --> it will loop here for ever
START_INIT:

  if (CAN_OK == CAN.begin(CAN_500KBPS))     //setting CAN baud rate to 500Kbps
  {
    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;
  }
}

//loading the data bytes of the message. Up to 8 bytes
unsigned char stmp[8] = {0xC0, 0x29, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00};
//{192 mph, 10542 RPM, check ON, oil ON, 5 unused}

void loop()
{
  //CAN.sendMsgBuf(msg ID, extended?, #of data bytes, data array);
  CAN.sendMsgBuf(0xF1, 0, 8, stmp);
  delay(3000);
}

For helping my own understanding, I want to see the output of CAN.sendMsgBuf in the serial monitor. I’ve tried doing so with Serial.print(CAN.sendMsgBuf(0xF1, 0, 8, stmp)), but it results with a single number and that is not what I expect it to be. Is this what it is supposed to be or is there a different way to see the correct output?

Karma for posting the first post with a code-section.

take a look inside the files mcp_can.h and mcp_can.cpp to see what functions are available

What is the exact type of the chip your can-controller is using?
Where did you download/install the mcp_can-library?

If somebody should help you we need this information

EDIT: You really need to say where you got the mcp_can-library from.
I uses the search-function of the arduino-IDE and with keyword mcp_can

it comes up with 7 liraries none of them is named "mcp_can"

best regards Stefan

Hi Stefan,

I'm currently trying to understand the mcp_can.h and mcp_can.cpp files. I got the library from this link
I am using the MCP2515 CAN Bus controller

Thank you

the link to the CAN-Bus-shield offers a manual how to install the can-bus.shield-library.

ANd after installing it you have new examples in the Arduino-IDE

file - examples - can-Bus-shield-master

So did you start with these examples? and do they work?

best regards Stefan

Hi Stefan,

I figured out my issues! I did not want to leave you hanging. I actually had some hardware issues I needed to fix and that allowed me to finish my project. Thanks!

Regards,
Noah