Building a low cost OBD2 ECU Simulator

Re: Building a low cost OBD2 ECU Simulator

Postby mmessuri » Fri Jul 10, 2015 4:26 pm

litello wrote:
mmessuri wrote:

Hi, I am also a newbie, and sorry for my english :) I have exactly the same problem than him. Could you please tell us what's wrong with the code?


You need to change the CS pin number to 9.

Code: Select all
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN); 
mmessuri
 
Posts: 3
Joined: Wed Jun 03, 2015 4:45 pm

Re: Building a low cost OBD2 ECU Simulator

Postby anubislg » Sat Jul 11, 2015 12:13 am

Hi all,

I had to register in order to post and share this, buuuutt it's worth it.

For everyone that's having difficulties getting any readings despite their shield being initialized okay, I believe I figured out what's going on.

It all boils down to how OBD2 works, and the protocols that it expects. When first connecting to an ECU an OBD2 reader will make a query on which PID's are available to it. If it can't successfully make this query, then it might fail (or...it might not).

By changing the following code:
unsigned char SupportedPID[8] = {1,2,3,4,5,6,7,8};

To:
unsigned char SupportedPID[4] = {4,65,0,5};

I now have my OBD2 reader working flawlessly! I'm using Torque (cell app) to read it, and transmitting via a Bluetooth dongle.

So what's going on here? Well...it's important to first know how OBD2 sends signals. Things become more difficult when you factor in that we're looking at DEC numbers, not HEX which is what CAN natively talks in. The best that I can guess, is that not all OBD2 readers care about PID lists, and simply poll for any data they can get. Those that DO care though, are getting hung up when they receive invalid data on which PID's are available.

So...let me try and break down what the data-strings also mean:
Using the following byte-string as an example... {4, 65, 0, 5}
Byte 1, 4 - Unknown. This appears to signal that it's something that is sending?

Byte 2, 65 - In HEX this translates to 41. It's a response! CAN is broken into several "modes", Mode 1 is what we're working with. Oddly enough when we're responding back, we add 40. Why 40? Who knows. If we were working in Mode 2, it would be 42. Mode 3, 43. And so on.

Byte 3, 0 - In HEX this translates to 00. This is simply telling the CAN BUS that we're responding back to that PID. What's PID 00? According to Wikipedia it's a PID that gives a response back as to what PID's are available!

Byte 4, 5 - In HEX this translates to....05. Big surprise? This is us simply telling the OBD2 adapter that PID 05....Engine Coolant Temperature...is available to read!

There's more to it, as you might guess, but this is a good primer on what's going on.
You can also see this behavior in the messages we receive using the code.
{2,1,5,0,0,0,0,0} simply means "Hello (2), I'm using Mode 1 (1), and looking for information on PID 05 (5)". The other zero's are just garbage data that we could actually ignore.

I got all this information from the following source:
https://cdn.sparkfun.com/assets/learn_t ... M327DS.pdf

Page 30 is where you'll find the topic on "Talking to the vehicle".

Good luck out there everyone!
anubislg
 
Posts: 1
Joined: Fri Jul 10, 2015 11:55 pm

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Sun Jul 12, 2015 11:03 pm

anubislg wrote:Hi all,

I had to register in order to post and share this, buuuutt it's worth it.

For everyone that's having difficulties getting any readings despite their shield being initialized okay, I believe I figured out what's going on.

It all boils down to how OBD2 works, and the protocols that it expects. When first connecting to an ECU an OBD2 reader will make a query on which PID's are available to it. If it can't successfully make this query, then it might fail (or...it might not).

By changing the following code:
unsigned char SupportedPID[8] = {1,2,3,4,5,6,7,8};

To:
unsigned char SupportedPID[4] = {4,65,0,5};

I now have my OBD2 reader working flawlessly! I'm using Torque (cell app) to read it, and transmitting via a Bluetooth dongle.

So what's going on here? Well...it's important to first know how OBD2 sends signals. Things become more difficult when you factor in that we're looking at DEC numbers, not HEX which is what CAN natively talks in. The best that I can guess, is that not all OBD2 readers care about PID lists, and simply poll for any data they can get. Those that DO care though, are getting hung up when they receive invalid data on which PID's are available.

So...let me try and break down what the data-strings also mean:
Using the following byte-string as an example... {4, 65, 0, 5}
Byte 1, 4 - Unknown. This appears to signal that it's something that is sending?

Byte 2, 65 - In HEX this translates to 41. It's a response! CAN is broken into several "modes", Mode 1 is what we're working with. Oddly enough when we're responding back, we add 40. Why 40? Who knows. If we were working in Mode 2, it would be 42. Mode 3, 43. And so on.

Byte 3, 0 - In HEX this translates to 00. This is simply telling the CAN BUS that we're responding back to that PID. What's PID 00? According to Wikipedia it's a PID that gives a response back as to what PID's are available!

Byte 4, 5 - In HEX this translates to....05. Big surprise? This is us simply telling the OBD2 adapter that PID 05....Engine Coolant Temperature...is available to read!

There's more to it, as you might guess, but this is a good primer on what's going on.
You can also see this behavior in the messages we receive using the code.
{2,1,5,0,0,0,0,0} simply means "Hello (2), I'm using Mode 1 (1), and looking for information on PID 05 (5)". The other zero's are just garbage data that we could actually ignore.

I got all this information from the following source:
https://cdn.sparkfun.com/assets/learn_t ... M327DS.pdf

Page 30 is where you'll find the topic on "Talking to the vehicle".

Good luck out there everyone!


Hi thanks for taking time to register and share your findings , good contribution. I'm sure it's going to help someone in the future.

cheers Martin
Image
User avatar
MartinViljoen
 
Posts: 109
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby litello » Wed Jul 15, 2015 9:09 am

mmessuri wrote:
litello wrote:
mmessuri wrote:

Hi, I am also a newbie, and sorry for my english :) I have exactly the same problem than him. Could you please tell us what's wrong with the code?


You need to change the CS pin number to 9.

Code: Select all
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN); 


Thank you for the answer ! But unfortunately, it doesn't work for me :( (and I tried it with pins 2,3... until 13 ). The problem is that my CAN-shield is a chinese copy, and a bit different from sparkfun/seeduino shields ....
Here it is : http://www.alibaba.com/product-detail/CAN-BUS-Shield-Compatible-Arduino_60105873670.html , I could study the data sheet, but no data sheet proper to this shield exists!!!

I'm going to try to enable the debug mode in the CAN library that I m using to investigate on that issue :(

EDIT : I studied the library carefully, but is it possible that the library is wrong ? (the same as you) In the "mcp_can.cpp" file, I didn't understand (in the "init mcp 2515" function) that line "res = mcp2515_setCANCTRL_Mode(MODE_CONFIG); " was not "res = mcp2515_setCANCTRL_Mode(MODE_NORMAL);"

I changed it, but it seems so me that 's wierd to find an error in a library written by an expert whil I'm a newbie x) Maybe it's not the right way ?

EDIT2 : thanks to my cousin ( engineer in electronics ), I found that the mcp_2515 was just broken . I sent a data through SPI connection, the data is well sent but it s impossible to read it afterwards, the MISO doesn't see anything. I just have to buy a new one ;).
litello
 
Posts: 2
Joined: Wed Jul 08, 2015 3:25 pm

Re: Building a low cost OBD2 ECU Simulator

Postby josebelzam » Sat Jul 18, 2015 5:58 pm

Hi,
Can someone explain to me the meaning of each number on the OBD-II messages??
For example: 4, 65, 12, rndRPM, 224, 185, 147
4: ??
65: (41 Hex) answer a request in mode 1
12: PID RPM
rndRPM: rpm value
224,185,147: ??? why no 0,0,0??

thank you so much!!
josebelzam
 
Posts: 2
Joined: Mon May 25, 2015 4:54 pm

Re: Building a low cost OBD2 ECU Simulator

Postby jiphre26 » Wed Jul 22, 2015 2:49 pm

Hey I am trying to recreate this project. Am I correct that the connections going into the ObD2 adapter are:
-CAN H
-CAN L (both from CAN Bus shield)
-Battery voltage (12V bench supply?)

And the signal and chassis ground pins both connected to ground.

Please help. I dont want to blow up any of my electronics lol
jiphre26
 
Posts: 1
Joined: Wed Jul 22, 2015 10:52 am

Re: Building a low cost OBD2 ECU Simulator

Postby daniel30 » Thu Sep 03, 2015 2:42 am

I am working in a thesis project and I am using the seeed CAN bus shield.
Someone can tell me what about the INT LED. What does mean. I searched infromacion
about it but I have not found
daniel30
 
Posts: 2
Joined: Sat Aug 29, 2015 3:43 am

Re: Building a low cost OBD2 ECU Simulator

Postby josebelzam » Fri Sep 04, 2015 10:51 pm

daniel30 wrote:I am working in a thesis project and I am using the seeed CAN bus shield.
Someone can tell me what about the INT LED. What does mean. I searched infromacion
about it but I have not found


you can found all about CAN bus Shield here: http://www.seeedstudio.com/wiki/CAN-BUS_Shield

I was working whit it during 6 months, so if u need some help write me and i will try to help you. 8-)
josebelzam
 
Posts: 2
Joined: Mon May 25, 2015 4:54 pm

Re: Building a low cost OBD2 ECU Simulator

Postby daniel30 » Tue Sep 08, 2015 1:37 am

josebelzam wrote:
daniel30 wrote:I am working in a thesis project and I am using the seeed CAN bus shield.
Someone can tell me what about the INT LED. What does mean. I searched infromacion
about it but I have not found


you can found all about CAN bus Shield here: http://www.seeedstudio.com/wiki/CAN-BUS_Shield

I was working whit it during 6 months, so if u need some help write me and i will try to help you. 8-)



Thank you :P

My project consists of building a platform for studying a system EPS (electric power steering) of a Pontiac G5, basically I need that the system work outside the car. Therefore I need emulate the strength of tires and ignition voltage, this last I have it but the system needs two basic values of the car: the vehicle speed and engine rpm. These values are sent via CAN by the BCM (body control module) to the EPS ECU. I use the seedstudio shield to emulate the BCM. My problem is that the EPS module continues to send this message: 64,0,0,16 and don´t answer my messages. I tried to change the ID CAN shield seeedstudio but doesn´t work. Actually I don´t know how GM encodes data (the communication using by Pontiac is GMLAN and is based on CAN) obviously I searched information but I have not found.

PD. I don´t have the car
daniel30
 
Posts: 2
Joined: Sat Aug 29, 2015 3:43 am

Re: Building a low cost OBD2 ECU Simulator

Postby mttweeks » Thu Sep 10, 2015 6:37 pm

Im very new to this system. I might be having trouble with the library but i keep getting the error when compling the code: "CAN" was not declared in this scope. The error starts with this line: if(CAN_OK == CAN.begin(CAN_500KBPS)) and pretty much every line that includes "CAN."
A push in the right direction would be appreciated.

*I solved my problem by switching to a Windows 7 computer and starting over. Not sure if I didn't call or install the library correctly or Windows 10 isn't supported yet.
mttweeks
 
Posts: 1
Joined: Mon Aug 31, 2015 3:20 pm

PreviousNext

Return to OBD2 & CAN-BUS Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron