Electronic – arduino – Reading from CAN bus of a Chevrolet Cruze using an Arduino Uno

arduinocanobd

I'm using the Arduino Uno, CAN bus shield, and OBDII to DB9 Cable using their provided libraries. I was only able to initialize it.

Readings:

While connected to the car:

  • CAN-High: 2.7 V – 3.0 V
  • CAN-Low: 2.4 V – 2.7 V

While not connected to the car:

  • CAN-High: ~2.4 V
  • CAN-Low: ~2.5 V

Note: in both cases the Arduino is connected to my PC via USB (for debugging).

Sample code:

#include <SoftwareSerial.h>   //Software serial port
#include <Canbus.h>

#define CBRxD 5  // CAN BUS RX
#define CBTxD 4  // TX

#define DEBUG_ENABLED  1

char buffer[512];  //Data will be temporarily stored to this buffer before being written to the file
char tempbuf[15];
char lat_str[14];
char lon_str[14];

int LED2 = 7;
int LED3 = 8;

boolean scan = true;

SoftwareSerial canbusSerial(CBRxD, CBTxD);

void setup() {
    Serial.begin(9600);
    canbusSerial.begin(4800);
    pinMode(0, INPUT);
    pinMode(BTTxD, OUTPUT);
    pinMode(LED2, OUTPUT);

    pinMode(LED3, OUTPUT);

    digitalWrite(LED2, LOW);
    digitalWrite(LED3, LOW);

    setupCanbus();
}

void loop() {
    char recvChar;
    if (canbusSerial.available()) {  // Check if there's any data sent from the remote CAN bus shield
        recvChar = canbusSerial.read();
        Serial.print("CAN: "+recvChar);
    }

    if (scan) {
        digitalWrite(LED3, HIGH);

        if(Canbus.ecu_req(ENGINE_RPM,buffer) == 1) {       /* Request for engine RPM */
            Serial.println(buffer);                        /* Display data on Serial Monitor */
        }
        Serial.println(buffer);

        if(Canbus.ecu_req(VEHICLE_SPEED,buffer) == 1) {
            Serial.println(buffer);
        }Serial.println(buffer);

        if(Canbus.ecu_req(ENGINE_COOLANT_TEMP,buffer) == 1) {
            Serial.print(buffer);
        }Serial.println(buffer);

        if(Canbus.ecu_req(THROTTLE,buffer) == 1) {
            Serial.println(buffer);
        }
        Serial.println(buffer);
        //  Canbus.ecu_req(O2_VOLTAGE,buffer);

        digitalWrite(LED3, LOW);
        delay(100);
    }
}

void setupCanbus() {
    while (!Canbus.init(CANSPEED_250)) {
        Serial.println("CAN Init");
    }
    Serial.println("CAN Init OK");
    delay(1000);
}

Best Answer

I think your car is similiar to Opel Astra J. It uses GMLAN which is a low- speed CAN bus (33 kbit/s).

I've been able to read and send CAN data with the same hardware.

I had to connect CAN-H and CAN-L respectively to the SW-LS-CAN pin and to ground, according to the second table of page General Motors (GM) OBD II diagnostic interface pinout.

I used the code in https://github.com/Afterglow/arduino-gmlan.

Tell me if this works.