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

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.

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
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);
}

• What output do you get on the serial terminal? – AmazingHorse Jan 1 '14 at 3:05
• Also, if you have a multimeter, switch it to ohms and measure the resistance across the CANH and CANL pins. Check out your pinout here. Should be pins 6 and 14. You may need to terminate the connection with a 120ohm resistor if it's not already terminated. – AmazingHorse Jan 1 '14 at 3:08
• first thing>> "CAN INIT OK". Then empty lines (printing empty buffer array) – mabdrabo Jan 1 '14 at 8:31
• The resistance measured across CANH and CANL is 38.4 Kohm, and across CANL and CANH is 79.8 Kohm. (not sure if that's possible) – mabdrabo Jan 1 '14 at 8:36
• yes, it checked it before it is 6 and 14, but how do i know it's terminated, if not how do i terminate it? – mabdrabo Jan 1 '14 at 8:37

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.

Their example code has

SoftwareSerial mySerial = SoftwareSerial(4, 5);


You have

SoftwareSerial canbusSerial(CBRxD, CBTxD);


Which translates to the opposite pin order

SoftwareSerial canbusSerial(5, 4);


Perhaps switching CBRxD and CBTxD would work.

• i hope it works, i'll try as soon as i have access to the car. Should i be getting any different response on the serial monitor although not connected to the car? – mabdrabo Jan 1 '14 at 8:40
• Unfortunately, it didn't fix it. – mabdrabo Jan 2 '14 at 9:45
• Did the example code with the shield work? – geometrikal Jan 2 '14 at 12:44
• nothing has changed, i get CAN Init OK, and then all empty lines (empty buffer) – mabdrabo Jan 2 '14 at 17:42
• Is the speed correct? In their code they init with CANSPEED_500 – geometrikal Jan 2 '14 at 22:24