I bought a MKR Zero and a MKR CAN Shield and would like to make a stand alone CAN Bus Data Logger. I have a few questions regarding this. First my plan is to power the MKR Zero from the ODB2 Port 12vdc using a 12vdc to 3.3 buck converter fed into the battery connector on the MKR Zero is this doable? Next Ive read the documents for each device (MKR Zero and MKR CAN Shield) and i think i have a good grasp on what I need to do aside from one thing, when I have the MKR CAN Shield collecting the data is there a good article somewhere to set it up to have it put the data out on 1 pin for the MKR Zero to log and save onto the Micro SD Card? Ive used Arduinos in the past but am not an expert but with some assistance i think i can get this to work. Basically i neeed the portion of the sketch that will set the CAN Shield up to output data on say pin A0. Again any recommendation on where to go to further enlighten myself on doing this?
OK Baby Steps is perhaps what I need here. I DO NOT have an article im flying by the seat of my pants with this. What I have so far is this (2 Pictures Imgur: The magic of the InternetImgur: The magic of the Internet ) Is this correct just piggy backing the 2 boards as this is what I thought you did with Arduino "Shields" if not please enlighten me. What my end goal is this: Imgur: The magic of the Internet The link between the MKR Zero and the MKR CAN Shield reflected is meant to represent the piggyback connection like in the pictures. If this isnt correct again please let me know. Thank You
-Brian-
Coming back to the power supply issue, the circuit diagram of the MKR Zero shows the battery feeding into a voltage regulator chip that requires at least 3.3v for operation. So, your 3.3 buck converter arrangement is sitting on the border line between working and not working. Expect it to be unreliable. For a more reliable solution put 5v into Vin.
Can you explain further what you are doing with pin 1, and what you expect to appear on pin A0?
No need to use the A0/1 hardware pins as the Arduino MCP2515 library receives a copy of the data from the CAN shield via the SPI bus. You then use the SD card library to save the data to the SD card.
Well.. Thank You if thats the case my job in doing this project just got a little easier! Now the issue I seem to be having is while Arduino sees the MKR Zero I cannot seem to get the MKR CAN Shield to be recognized not sure what the trick is with that?
I am having issues getting the MKR CAN Shield to be recognized so as I can flash it. I see the MKR Zero when its plugged in via USB shouldnt i be able to also see the MKR CAN Shield?
I have also read that the Silkscreen marking on the CAN Shield are in the wrong order? Mine are as reflected in this picture: Imgur: The magic of the Internet are they correct? This was from another article on this forumn that was closed over a year ago by HansNg its here: ttps://tinyurl.com/hjpmhycv
The seller of the board can best answer that question. If you bought it directly from the Arduino store then contact the company directly.
However, if you are comfortable using a multimeter to trace signals then get a copy of the circuit diagram and follow the Tx or Rx signal from the connector to the transceiver chip.
Heck i didn't even have to break out the multimeter I merely compared the schematics to what my board says and indeed the silscreening is wrong with CANH and CANL being reveresed.. Pics here: Imgur: The magic of the Internet and here Imgur: The magic of the Internet
OK Ive had what I believe is good code passed to me but I am getting 1 error when uploading it to the MKR Zero / MKR Shield. I am seeing the following in the Serial Monitor window:
CAN Receiver
Entering Configuration Mode Successful!
Setting Baudrate Failure...
CAN Init OK
SD card initialized.
Setup complete.
The sket5ch i had apassed to me is as follows:
#include <SPI.h>
#include <SD.h>
#include <mcp_can.h>
// Pin definitions
const int chipSelect = SDCARD_SS_PIN;
const int CAN_CS_PIN = 3; // Adjust this if your CAN shield uses a different CS pin
// Create CAN and SD objects
MCP_CAN CAN(CAN_CS_PIN);
File dataFile;
void setup() {
Serial.begin(115200);
while (!Serial);
// Initialize the CAN bus at 500 kbps
if (CAN.begin(MCP_ANY, 500000, MCP_8MHZ) == CAN_OK) { // adjust to your CAN
Serial.println("CAN Init OK");
} else {
Serial.println("CAN Init Failed");
while (true) yield();
}
// Set CAN mode to normal
CAN.setMode(MCP_NORMAL);
// Initialize SD card
if (!SD.begin(chipSelect)) {
Serial.println("SD card initialization failed!");
while (true) yield();
}
Serial.println("SD card initialized.");
// Create or open a file for writing
dataFile = SD.open("canlog.txt", FILE_WRITE);
if (!dataFile) {
Serial.println("Failed to open file for writing");
while (true) yield();
}
Serial.println("Setup complete.");
}
void loop() {
// Check if data is available from the CAN bus
if (CAN_MSGAVAIL == CAN.checkReceive()) {
// Read the message
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
CAN.readMsgBuf(&rxId, &len, rxBuf);
// Print the received data to the serial monitor
Serial.print("ID: ");
Serial.print(rxId, HEX);
Serial.print(" Data: ");
for (int i = 0; i < len; i++) {
Serial.print(rxBuf[i], HEX);
Serial.print(" ");
}
Serial.println();
// Save the received data to the SD card
if (dataFile) {
dataFile.print("ID: ");
dataFile.print(rxId, HEX);
dataFile.print(" Data: ");
for (int i = 0; i < len; i++) {
dataFile.print(rxBuf[i], HEX);
dataFile.print(" ");
}
dataFile.println();
dataFile.flush(); // Ensure data is written to the file
}
}
}
Because if you look at or read the article this requires 2 each of the MKR Zero and the MKR Can Shield. I own 1 of each and thats all. So doing this tutorial is impossible.
It is apparent you do not completely understand the CAN protocol. CAN uses an IFR (In Frame Response) as part of the protocol. How this works is there is a point in the message being transmitted that has to be acknowledged by another CAN unit on the bus. The transmitter puts our a recessive bit and the responder(s) put out a dominate bit. The can unit monitors its own transmision as part of its protocol and when it puts something on the bus it expects to read that, if not it errors out and tries again for (depending on settings) until its internal counter times out.
You are correct with out an additional CAN module or test device you are as they say dead in the water. Read this for a better understanding: http://esd.cs.ucr.edu/webres/can20.pdf
My INTENTION is to use this device for OBD2 Sniffing not True CAN to CAN communication. I understand the CAN Bus well enough to know that with 1 MKR Zero and 1 MKR CAN Shield I cannot do the tutorial.