General

read data from ecu with arduino

userHead Account cancelled 2014-03-11 02:59:55 3696 Views0 Replies
Hello to all,
I'm an Italian student of computer engineering and for my thesis work I am trying to connect the Arduino to the ECU of my car. I bought several online shield including:
http://www.seeedstudio.com/wiki/CAN-BUS_Shield
I wrote this code and once the Arduino connected to the ECU, the serial monitor I got these results which I am attaching:
Code: Select all
#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];
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
        
        for(int i = 0; i<len; i++)    // print the data
        {
            Serial.print(buf[i]);Serial.print("\t");
        }
        Serial.println();
        Serial.println("Buffer ricevuto");
        
        
        
    }
    delay(800);
    
    
}
Someone is able to interpret them? I can not understand what they mean. I need help!
Thank you!