[Carloop] [OBD2] Requesting OBD data

I’m using the Electron and the Carloop transceiver attachment to try to send an OBD request to my car and publish the response, but it’s not doing what I’d like. Here’s my code:

and here’s my Events log:

Based on the wikipedia page (https://en.wikipedia.org/wiki/OBD-II_PIDs) I would expect my Events log to populate with events where the Name is somewhere between 7E8 and 7EF (see https://en.wikipedia.org/wiki/OBD-II_PIDs#Response), and the Data says the same thing every time (see https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_01_PID_00).

To make sure my Electron only receives OBD replies, and not just any raw CAN data, I’ve added line 7 in my code.

My thoughts are that either:

  1. My car’s CANbus doesn’t recognize the request the Electron is sending
  2. can.transmit(message) is not doing what I think it’s doing
  3. can.receive(message) is not working because message already has data in it

Any thoughts?


When a “command” only requires 3 bytes why would you opt for sending 5 extra/dummy bytes across the bus?
Short/important messages can be delivered faster when not sending useless data along with it.

@ScruffR I’m not totally sure what message.len is, since according to a youtube video I found (https://www.youtube.com/watch?v=OhShoU_E-0g&t=486s at 6:53) the first byte (message.data[0]) is the length of the message.

I set it to 8 because an example Carloop program I found has it set to 8.

image

Following up for curious readers: I’m actually receiving OBD data from my car’s CANbus now. I changed a few things and one of them did the trick:

  1. Include the “carloop” library
  2. add #include <carloop.h> to the top of the program
  3. add Carloop<CarloopRevision2> carloop; to the top of the program. (example Carloop programs I found on the Carloop website say that this lets the microcontroller know which revision of Carloop it’s connected to.)
  4. replace can.begin(500000); with carloop.begin();.(example Carloop programs I found on the Carloop website say carloop.begin() defaults to a speed of 500000 bits/sec.)
  5. replace all occurrences of can.receive(message) with carloop.can().receive(message)
  6. replace all occurrences of can.transmit(message) with carloop.can().transmit(message)
  7. added lines: message.data[3] = 0x55; message.data[4] = 0x55; message.data[5] = 0x55; message.data[6] = 0x55; message.data[7] = 0x55;

I haven’t done rigorous testing to see exactly why I wasn’t getting a response previously, but I’m guessing it might have to do with can.transmit(). Maybe how it functions with Carloop.

Also @ScruffR following up with your post

I did some testing and found that I would send messages where message.len=3; and wouldn’t get any response from the CANbus, but then I would change the line to be message.len=8; and I’d get a response. Not sure why.

Below was what my program looked like when I started to get OBD responses from my car. On line 29 I compare messages with len=3 to messages with len=8. The messages where len=3 didn’t get a response, but the messages with len=8 did.


1 Like