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]