# \[Carloop\] \[OBD2\] Requesting OBD data

**URL:** <https://community.particle.io/t/carloop-obd2-requesting-obd-data/55251>\
**Category:** Firmware\
**Tags:** electron\
**Created:** [March 18, 2020, 9:29pm UTC](https://community.particle.io/t/carloop-obd2-requesting-obd-data/55251 "2020-03-18T21:29:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![spe](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/spe/32/24310_2.png) [@spe](https://community.particle.io/u/spe)\
**Post date:** [March 18, 2020, 9:29pm UTC](https://community.particle.io/t/carloop-obd2-requesting-obd-data/55251/1 "2020-03-18T21:29:52Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/7/b/7b96f98293f6af335030d38370bc92c17e7cfffd.png)

and here’s my Events log:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/2/9/297941fcf4ebf686877a86cadc3cd50326737839.png)

Based on the wikipedia page ([https://en.wikipedia.org/wiki/OBD-II\_PIDs](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](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](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?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [March 18, 2020, 11:38pm UTC](https://community.particle.io/t/carloop-obd2-requesting-obd-data/55251/2 "2020-03-18T23:38:12Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/e/3/e392661663d1c6eec4d67902d56aacb9a165767b.png)  
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.

---

<div class="post-metadata">

**Author:** ![spe](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/spe/32/24310_2.png) [@spe](https://community.particle.io/u/spe)\
**Post date:** [March 18, 2020, 11:56pm UTC](https://community.particle.io/t/carloop-obd2-requesting-obd-data/55251/3 "2020-03-18T23:56:23Z")

</div>

@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](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](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/7/f/7f1a488b7e4c7040a24e8c3f9f401f14b2e1e7ea.png)

---

<div class="post-metadata">

**Author:** ![spe](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/spe/32/24310_2.png) [@spe](https://community.particle.io/u/spe)\
**Post date:** [March 22, 2020, 5:13am UTC](https://community.particle.io/t/carloop-obd2-requesting-obd-data/55251/4 "2020-03-22T05:13:20Z")

</div>

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

> [@ScruffR](#):
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/e/3/e392661663d1c6eec4d67902d56aacb9a165767b.png)
> 
> 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.

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.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/d/6/d672cb05d534eea5cf64f3c377ab9373947fff09.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/f/c/fc34b97227657f54711bd35eb7bcabdacedd478e.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/4/64635adccc35238caa19e9b553ec3e98b163d026.png) [@system](https://community.particle.io/u/system)\
**Post date:** [September 20, 2020, 5:13pm UTC](https://community.particle.io/t/carloop-obd2-requesting-obd-data/55251/5 "2020-09-20T17:13:26Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
