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:
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.
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:
Include the "carloop" library
add #include <carloop.h> to the top of the program
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.)
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.)
replace all occurrences of can.receive(message) with carloop.can().receive(message)
replace all occurrences of can.transmit(message) with carloop.can().transmit(message)
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.
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.