Using Arduino MEGA 2560 with MKR CAN shield

Hello,

I am building some circuit that will adapt some pumps in a car according to the car real-time parameters values. I need to talk to the car through OBDII. I have a MEGA 2560 and OBDII to DB9 cable in addition to a CAN shield (Arduino MKR CAN Shield — Arduino Official Store).

I did not notice that it is supposed to be a shield for an MKR board before buying it, anyways, I tried to look up for the corresponding pins on the MEGA for MOSI, MISO, SCK, etc.

Also, I used these libraries (GitHub - sandeepmistry/arduino-CAN: An Arduino library for sending and receiving data using CAN bus.) & (GitHub - sandeepmistry/arduino-OBD2: An Arduino library for reading OBD-II data from your car over CAN bus)

So, I did the connections, but it does not pull data. I assume there is a problem with the compatibility of the library with the MEGA, so is it a good idea to dig into the library source and tweak some lines to have the MEGA working fine? or it will be very nasty/impossible. If you have any advice for the wise step to take, please let me know.

P.S. I am not very familiar with the differences between MEGA/MKR except the different peripherals availability/distribution.

On the MEGA2560 those signals are on the dual row header - pins 50 to 53.

What connections did you make between the MEGA2560 and the MKR CAN shield?

So yes I have just managed to make them work.

I connected the 5V, VCC, ground on the shield to the 5V, 3.3V, GND pins of the Mega.

MOSI goes to 51, MISO goes to 50, SCK goes to 52.

INT (pin 7 on the shield) goes to 2 on the Arduino (Cause for Mega: 2 is one of the interrupt pins)

CS to pin 10.

I needed to make pinout numbers change in one of the CAN library source files: (MCP2515.h) and traa it's actually working now.

Hi Kareem,

maybe this is not answering your question related to Arduino MKR CAN Shield and Mega 2560.

But I got crazy with a MKR CAN Shield + Arduino MKR Wifi1010 and I manage to SEND OUT can messages FROM MKR CAN Shield running the sandeepmistry library ONLY when I set up the transmission speed to 250 Kbps.

void setup() {
// start the CAN bus at 250kbps which is OK for MKR CAN SHIELD
  if (!CAN.begin(250E3)) {
      Serial.println("Starting CAN failed!");
      while (1);
    }

}

Not sure this will be working in your case as well, but maybe it is worth a try.
Take care,

Andrea

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.