The title says it all really as to where I’m at in my project. I’m trying to get access to the stream of data that is running on the CAN-bus in my car, and I can see others on the internet tubes achieving varying levels of success using the same components as I am, but there is somehow a breakdown in communication when I am trying to get help from different parts of the world mostly due to language, so I am going to turn to you guys for some help as I’m at my wits end trying to figure this out. I attribute this wall to my own lack of familiarity with programming the Arduino. While I’ve made huge strides (for me) I think I might just be missing something obvious.
Here’s what I’ve got:
Arduino UNO R3
Seeedstudio CAN-bus Shield v1.0
D9 to OBD-II cable
OBD-II port in VW/Audi vehicle (2014)
I understand how to install libraries and all that… I have the board up and running properly. I can even see the little Rx and Tx lights blinking like crazy (once I removed the R3 resistor - as instructed by the manufacturer), but nothing comes through on the Serial Monitor with the supplied code, or even slightly cleaned up code.
Serial.begin(115200) and the corresponding 115200 is set in the serial monitor.
Audi runs their drivetrain CAN-bus at 500kbps, and the code has the corresponding if(CAN_OK == CAN.begin(CAN_500KBPS))
What I could really use is someone that is familiar with Arduino programming to look at my code and say “here’s where you went wrong” etc. I’ll post an example of the code I am using (in this case I’ve included a send and read related command just trying to unhinge the data from whatever magical place it’s hiding). Anyone that understands Arduino better than I do… please help!
I am more than happy to bring the beer as a huge thank you if anyone wants to sit down and look at this in person.
Ultimately, once I have access to the data, I will be querying the CAN-bus for specific values and using them elsewhere in my project. Gathering this from the CAN-bus would be hugely beneficial and efficient for me so this is a key milestone to get past.
#include <SPI.h>
#include <mcp_can.h>
MCP_CAN CAN(10); // Set CS to pin 10
unsigned char len = 0;
unsigned char buf[8];
unsigned long canId = 0x00;
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
/////////////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(115200);
START_INIT:
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init ok!");
}
else
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
delay(100);
goto START_INIT;
}
}
/////////////////////////////////////////////////////////////////////////////////
void loop()
{
// send data: id = 0x00, standrad flame, data len = 8, stmp: data buf
CAN.sendMsgBuf(0x00, 0, 8, stmp);
delay(100);
//
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
Serial.print("<");Serial.print(canId);Serial.print(",");
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i]);Serial.print("\t");
}
Serial.print(">");
Serial.println();
}
Note that this is mostly copy pasted and then perused by me (a mostly non-programmer) looking for obvious errors… it SHOULD work but for some unknown reason(s) it does not.
I think I may have sent off the vibe that I’m severely Arduino-tarded and nobody wants to touch this lol.
The reality is that this problem is very likely solvable with barely any effort from someone that is quite comfortable within the Arduino IDE environment. The components of the project are pretty compact to so I would be happy to come down the VHS3 at any time or wherever works for anyone that wants to take a peek at this.
ANY help would be supremely appreciated! And anyone that can crack this for me (again, likely the easiest thing you’ve ever done), I would be happy to provide beer/lunch/dinner… name your price!!!
I know a little about CAN-bus … I’ll be at VHS tonight 8pm, we could talk about the difficulties you are encountering and see if we can find a solution together.
I think you should probably start by list what troubleshooting you have already done:
Do you get any of the CAN Shield initiation messages from the setup routine?
Do you get any error messages at all?
Have you peppered debug print messages throughout the code to see if it gets through all the parts or does it hang somewhere?
Have you tried using canned messages to prove your code is good and you are just not getting the CAN data?
Etc…
packetbob… good point! In future I’ll be more descriptive (I thought people would be rolling their eyes if I added too much but in retrospect I see the wisdom in what you advised).
hectorh… I will certainly take you up on your offer!!! I’ll come by at 8 to find you and show you where I’m at. That will only take a few minutes of showing so I’ll skip (for now) the wordsmithing of a deeper explanation here. Thanks very much!
I think it’s a good idea to provide an update at this point, as the project to connect to a cars CAN-bus is hugely awesome (in my mind anyway) and I’m not quite done yet!
Seeing these CAN-bus shields around the internet tubes and seeing the simplicity in which others have connected to the CAN-bus made me originally think this was a simple process. Buy stuff, plug it in, and done. Sadly this isn’t the case, and thanks to both Dan and Hector, the options for connecting to the car the way I thought I could has been properly exhausted to the point where I think I can make a few key observations.
Connecting to the OBD-II diagnostic port on a newer Audi requires some knowledge of how to initialize the connection. Knowledge I do not have.
The people online having fun with the firehose of data coming from the CAN-bus are either confirmed or suspected of connecting to the CAN-bus by splicing into the CAN High and Low wires somewhere else in the car, thus bypassing the Gateway Control Unit (this actually separates the CAN-bus from direct access and allows manufacturer created software/hardware to connect and interface with the car. But this connection relies on the ability to interface/initialize with it properly and even then is only responding to specific requests, not giving you access to the full data stream).
And so it’s become obvious that for this to move forward I need to find a car I am comfortable splicing into the CAN-bus wires elsewhere in the car. My current car is new and is a lease so I don’t think I’ll be doing that to it anytime soon. Once I have done this I’ll report back again.
Sidenote:
The efforts to break into the CAN-bus we employed were awesome (thank you Hector!!) to the point were we turned the CAN-bus shield/Arduino setup into a utility to spy on the communications of an ELM327 which was able to negotiate the OBD-II port/Gateway Control Unit. And while the spying has helped me understand CAN-bus communications in greater detail (thus prepping me for the moment when I get actual access), I still couldn’t figure out the initialization required to spoof it on my own.
I’m really surprised I didn’t see this one before.
For one, please contact me off-list. matthew -at- ottersoft.ca
A long time ago I made a OBD-II scan tool which included CAN and the initialization stuff. Unfortunately I haven’t been able to find my code from that but I do know a thing or two still about how it works.
I know a whole lot more about what goes on ‘under the hood’ though as my job right now is reverse engineering VWs to do interesting little ‘tweaks’ to the vehicle systems (http://www.hpamotorsports.com/product_haldex.html). One of the more interesting details of vehicle busses is that you often don’t need to really splice into them. There’s lots of places the bus goes and connectors all over which you can simply do a pass-through connector with stub to your board. There are two such points on your vehicle near the dash - the steering wheel position sensor (usually an 8-pin 0.1" spaced header with a custom shroud) and the instrument cluster (not sure as it’s probably different between vehicles).
Let me know what kind of data you’re seeking; I also may already have the addresses and scheme to it.
Also, I’m looking for more information on their protection systems so a recording or two from your vehicle would be very helpful.
Hi! I’m trying to connect my Q5 09’ by Arduino. I have CAN shield v1.2 I know some information about connection. maybe together we could do our problem. if you still interesting it you can email me “virtualcity at mail point ru”
Hi! No, I’m from Russia Saint-Petersburg. My name is Michael. Yesturday, I have connected to my car by CAN BUS And I got a flow of data . It has ID and data. it looks like
ID: 6C0 Data: 01 40 04 00 00 0F 03
ID: 585 Data: 00 00 00 00 00 00 00 80
ID: 309 Data: 4A 00 00 40
ID: 104 Data: 90 02 A6 80 00 00 00 B1
ID: 3BF Data: 80 00 00 00 00 00 00 00
ID: 100 Data: 86 ED BF FF 00 00 00 80
I found some ID that read some equipment. But I didn’t test it yet. I hope to do it today. You may write me email I will get it faster then here…
That has a different address encoding that what I’ve reverse-engineered.
So, how I suggest working with this is start by sampling a few known conditions: key on, car idling, car revving twice, etc. Make sure you can record all messages with some form of time info with as high a resolution as possible. Timing, I’ve found, is the easiest way to determine if a single module is generating a set of packets.
Due to how CAN works, lower addresses are higher priority. This means that most modules will transmit multiple addresses.
Once you’ve looked through timing group all of the addresses so you can look for changing fields within them. Most of the time you should be able to see 16/24/32 bit variables by seeing one byte roll over as another byte changes by one.
At this point you should have an idea of which bytes or groups of bytes are changing fields so use a spreadsheet program to graph each one until you find variables that match what your looking for.
Hope this helps.
Have fun eh
Loial
P.S. The most difficult part of this is recording the packets reliably. Anything using the computer needs huge buffers as 500kbaud tiny packets will bog down almost every way of saving them. Postgresql is the best at handling it that I’ve found (tested mysql, sqlite, piping into a file, and a few other methods). Mind you, I was also using python for comms so you might have an easier time of it.