CAN BUS Shield

Hello to all,
I am a computer engineering student and for my thesis work I am trying to connect the Arduino to my car. I purchased the “Can_Bus_Shield” and I connected to the OBD socket of my car. I received data strange that I can not interpret, I am attaching the code that I used and the results obtained, I need help! has anyone ever tried to do a job like that?
Thank you very much.

[code]

#include <SPI.h>
#include <String.h>
#include “mcp_can.h”
#include <SoftwareSerail.h>

unsigned char Flag_Recv = 0;
unsigned char len = 0;
unsigned char len2 = 0;
unsigned char buf[100];
char str[20];
unsigned char *buff;
String buffer = “”;
#define PID_SUPPORT00 0x00

#define MIL_CODE 0x01

#define FREEZE_DTC 0x02

#define FUEL_STATUS 0x03

#define LOAD_VALUE 0x04

#define COOLANT_TEMP 0x05

#define STFT_BANK1 0x06

#define LTFT_BANK1 0x07

#define STFT_BANK2 0x08

#define LTFT_BANK2 0x09

#define FUEL_PRESSURE 0x0A

#define MAN_PRESSURE 0x0B

#define ENGINE_RPM 0x0C

void setup()
{
Serial.begin(115200);

START_INIT:

if(CAN_OK == CAN.begin(CAN_500KBPS))                   // init can bus : baudrate = 500k
{
    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()
{

unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};

CAN.sendMsgBuf(ENGINE_RPM, 0, 8, stmp);   // send data:  id = 0x00, standrad flame, data len = 8, stmp: data buf
delay(10);                          // when the delay less than 20ms, you shield use receive_interrupt

if(MCP_STAT_RXIF_MASK == CAN.checkReceive())            // check if data coming
{
    //CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf
    CAN.readMsgBuf(&len2, buff);
    for(int i = 0; i<len; i++)    // print the data
    {
        Serial.print(buf[i]);Serial.print("\t");
    }
    Serial.println();
    Serial.println("Buffer ricevuto");
      Serial.println(*buff); 
    
    
}
delay(800);

}[/code]
prova1.png

Some vehicles have a streaming output, this might be what you are receiving.

ok thanks, so how do you advise me to do? I read X bytes and when to stop? Do you know if there is an online guide on the data returned from the ECU of the car?

The streaming output is specific to the make of your vehicle and even then, the streaming data tends to be proprietary in nature. You may get lucky and find someone has done work to decipher the streaming data…

I would suggest you use the mask and filtering feature of the MCP2515 to limit reception to only the OBD II reply for your request.

ok I understand, but the data that I receive no data to answer to my specific request. data that appear in the image arriving at the shield even if I do not attempt to request and therefore would not know what to filter. I also tried to use libraries of other OBD adapters are not good but on the shield CAN_BUS. For if you know any link or person that I could contact for more help? thank you very much for availability

You are missing the CAN ID component of each packet. In essence, you are looking at data packets without taking the identification of each packet into question. You would want to mask and filter the OBD II response ID so that the MCP2515 ignores all other packets. The fact that you are listening to all data on the CAN Bus and are also using delays in your code would result in the MCP2515’s buffers becoming full and pushing out the OBD II response before your code has the chance to read from the MCP2515 and then push it out to the serial port.