1

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);
}
Peter Mortensen
  • 1,676
  • 3
  • 17
  • 23
mabdrabo
  • 185
  • 3
  • 9
  • What output do you get on the serial terminal? – AmazingHorse Jan 01 '14 at 03: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](http://pinoutsguide.com/CarElectronics/gm_car_obd_ii_pinout.shtml). 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 01 '14 at 03:08
  • first thing>> "CAN INIT OK". Then empty lines (printing empty buffer array) – mabdrabo Jan 01 '14 at 08: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 01 '14 at 08: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 01 '14 at 08:37

2 Answers2

2

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.

Peter Mortensen
  • 1,676
  • 3
  • 17
  • 23
acca
  • 21
  • 2
0

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.

geometrikal
  • 4,921
  • 2
  • 23
  • 41