New!!OBD2 Com with Xsim3 and Arduino-New!!

Dashboard, gauge projects etc.
Please use the image gallery for your pictures, a short tutorial can be found here.
The first image in the first post will be shown in the project gallery.

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby sliversgyj » Sun 29. Sep 2013, 16:06

vicpopo wrote:Hi ,

First you remember this post :http://www.x-sim.de/forum/viewtopic.php?f=40&t=1083&start=30#p9937

That means for me that the pid for current lap is given by obd2 protocol that Sirnoname programed.

I didn't yet tested but below my proposition to proceed :

1- As I wrote in a previous post you have tu drive one complete lap before showing current lap time counted .The first thing is to check in input menu that the current lap time will change form -1000 to numerical value . I didn't remember which data format but in thousands (32 547?) .Write both values the one in input value and the one in game display .After you can calculate the data format.
Sirnoname wrote that the 2 word 4* ** 00 00 the last two words represents ms .The thing I not checked is if this value is the difference or the total current time lap.

Exemple : you finished a lap and your time is 1min 42 s 23 43 ,
that means that the value in ms is 102 234 ms or 01 8F 5A in Hex .There are 3 words not 2 as the pid give.

That the point I 'm with ths current time lap.

For PositionValue is more simple than laptime,I had tried to debug the ReceiveValueWithTimeout function with it first.
and found the problem is "if(arduinoserialbuffer != receivetrigger)" never be reached.
I'm not sure why "4"(ascii 52) is the trigger? and why I can't recevice such trigger for Postionvalue command.
The data I received is 62,78,79,32,68,65,84,65,13,62(I translater to ascii char is "NO DATA <enter>") is that mean the version of X-sim is use not supported such command?
sliversgyj
X-Sim Supporter
 
Posts: 37
Images: 34
Joined: Sun 3. Mar 2013, 13:00
Has thanked: 2 times
Been thanked: 2 times

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby sirnoname » Sun 29. Sep 2013, 16:45

NO DATA say you did not send a valid request. Since you did not answer the used X-Sim package version number it seems you use an old version.
"4" is the first character in the response. Since NoData has no 4 you get a timeout of 1500ms because of your error.
Code: Select all
//E1 Position (not elm327 complaint)
char returnbuffer[]="41 E1 00 ";

To the part of your slow resonse of 200ms you must tell more about how you did verify this? Exact 200ms seems not to be a oscilloscope value.
Here I need per request about 15ms. 4 requests = 60-100ms. The request management is i.e. for position 1:10, which means speed is requested all the time, the ingame position all 10 times of speed. Windows has a 10ms realtime insurance. So single request get in problems. We can add a OBD2 command like 01EF which output all values in a big stream. This can then be faster. However you must program yourself the arduino.

@vicpopo: this is true, -1000 might be a problem. I have changed this now to not send negative values and too high values. This is more save for laptime.

A tip: There are RX and TX LEDs on your board. They must be continous light without big breaks. If you have breaks your code is broken.
While a game starts and stops the arduino might disconnect and reconnect (LEDon output 13 indicator).
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby sliversgyj » Sun 29. Sep 2013, 16:57

sirnoname wrote:NO DATA say you did not send a valid request. Since you did not answer the used X-Sim package version number it seems you use an old version.
"4" is the first character in the response. Since NoData has no 4 you get a timeout of 1500ms because of your error.
Code: Select all
//E1 Position (not elm327 complaint)
char returnbuffer[]="41 E1 00 ";

To the part of your slow resonse of 200ms you must tell more about how you did verify this? Exact 200ms seems not to be a oscilloscope value.
Here I need per request about 15ms. 4 requests = 60-100ms.

Thank you sirnoname,you are right,it was because my version is too old.I use the lastest version.now I can get the position value.But laptime still not ok,I will check it tomorrow.
For the reponse time check,I add a print of the z value before return ParseReceiveBuffer,and found each loop will cost about 50 ~80(ms).

for(int z=0; z < 1500; z++) //1500ms timeout should be enough
...
if(buffercount > receivelength) //buffer has now waitlen character length
{
lcd.setCursor(7, 0) ;
lcd.print("t=");
lcd.print(z);
delay(2000);
return ParseReceiveBuffer(commandhighbyte, commandlowbyte, receivelength);
buffercount=-1;
}
sliversgyj
X-Sim Supporter
 
Posts: 37
Images: 34
Joined: Sun 3. Mar 2013, 13:00
Has thanked: 2 times
Been thanked: 2 times

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby sliversgyj » Mon 30. Sep 2013, 10:35

I test the Lap time with "ReceiveValueWithTimeout('4','E','3',10);"
but only get four bytes data return.
Just like vicpopo.It looks missing 1byte.I try to change increate the receivelength to 11, but I still can only receive 10 from x-sim.
example:
I run a lap: 1:24:101 = 86101ms = 15055(HEX)
the receivedbuffer:
receivebuffer[5] = 49 = 1(ASCII)
receivebuffer[6] = 53 = 5(ASCII)
receivebuffer[8] = 48 = 0(ASCII)
receivebuffer[9] = 53 = 5(ASCII)
So looks missing the last digit "5".

Sirnoname would you please help to confirm,if I'm wrong?
Thanks!
sliversgyj
X-Sim Supporter
 
Posts: 37
Images: 34
Joined: Sun 3. Mar 2013, 13:00
Has thanked: 2 times
Been thanked: 2 times

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby sirnoname » Mon 30. Sep 2013, 14:52

Right, only 4 digits are supported, the first ones are used.

ms seems to be a problem with 65535. I increase to 8 digits = 4 bytes with next version.
I have finished the stream data with all values in one big output to reduce the polling delay and encrease the update rate.
The stream will have a order of all values but can be expanded in the future, so you have to trigger for the return and read the values with offset.
I will not write code for this, so everyone who likes to offer a example is welcomed.
I think I release this changes this evening, so you can work with this new commands.
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby sliversgyj » Mon 30. Sep 2013, 18:51

sirnoname wrote:Right, only 4 digits are supported, the first ones are used.

ms seems to be a problem with 65535. I increase to 8 digits = 4 bytes with next version.
I have finished the stream data with all values in one big output to reduce the polling delay and encrease the update rate.
The stream will have a order of all values but can be expanded in the future, so you have to trigger for the return and read the values with offset.
I will not write code for this, so everyone who likes to offer a example is welcomed.
I think I release this changes this evening, so you can work with this new commands.

Thanks a lot for your work!I will wait for your new commands.
sliversgyj
X-Sim Supporter
 
Posts: 37
Images: 34
Joined: Sun 3. Mar 2013, 13:00
Has thanked: 2 times
Been thanked: 2 times

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby sirnoname » Mon 30. Sep 2013, 19:52

This are the news for 3.0.2.7

Code: Select all
//EF stream output rpm (2 bytes), speed (2 bytes), coolant (1 byte), gear (1 byte), position (1 byte), currentlap (1 byte), bestlaptime (4 byte), fuel (1 byte)  (not elm327 complaint)
char returnbuffer[]="41 EF 00 00 00 00 00 00 00 00 00 00 00 00 00 ";
char returnbuffer[]="41 EF RR RR SS SS CC GG PP LL BB BB BB BB FF ";// First character of value representing byte after 41EF


Do not forget to increase the receive buffer to the new length that are used (Arduino INO file):
Code: Select all
int receivebuffer[100]={0};      //Receive buffer


The timeout function (INO file) is receive len -1 (First scouting character '4' not counted):
Code: Select all
return ReceiveValueWithTimeout('4','E','F',42);

Remember there are spaces between the hex numbers because OBD2 want it.

This is the new laptime response:
Code: Select all
//E3 Best laptime (not elm327 complaint, now 4 bytes)
char returnbuffer[]="41 E3 00 00 00 00 ";
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby vicpopo » Mon 30. Sep 2013, 20:10

Hi Sir,

Thanks for this new release , now we have a little bit work for testing all OBD2 stuff !! ;)
User avatar
vicpopo
 
Posts: 645
Joined: Fri 20. Apr 2012, 18:04
Location: Strasbourg France
Has thanked: 39 times
Been thanked: 80 times

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby sliversgyj » Tue 1. Oct 2013, 11:22

Hi Sirnoname,
Thank for your new release.I have a simple test on it.
with the new command "EF",the realtime issue not existed anymore.The time cost I count for this command is about 60ms.For this command will get all the data I need,so I think it's good enough,now :lol:
And I also tested the parameter in this command.All the parameter are ok,excpect RPM and bestlaptime.
1)For RPM,I found the data is only exist in the seceond byte.For example:when the rpm = 1236,
I get :
receivebuffer[5] = 48 =0
receivebuffer[6] = 48 =0
receivebuffer[8] = 55 = 7
receivebuffer[9] = 66 = B
that's only 7B(hex) = 123 looks missing the 6.
BTW,I also not sure what's the mean of the comments "//remember OBD2 RPM is ((A*256)+B)/4"
what is A and B?
2) For bestlaptime I get bytes from receivebuffer[29],30,32,33,35,36,38,39
but always get receivebuffer[29]~33 are 48(=0), and receivebuffer[35]~39 are 70(=F).that's mean the data I get is "00,00,FF,FF"
For I also test the "current lap" and "current fuel" they are all ok.So I think it is not an offset issue.

Please help to have a look.Thanks again!
sliversgyj
X-Sim Supporter
 
Posts: 37
Images: 34
Joined: Sun 3. Mar 2013, 13:00
Has thanked: 2 times
Been thanked: 2 times

Re: New!!OBD2 Com with Xsim3 and Arduino-New!!

Postby sirnoname » Tue 1. Oct 2013, 19:20

RPM is /4. The formula is OBD2 standard.
The extended RPM with EA or EF is RPM/10 to reach 655350 RPM, you told something about above 100000 which is above 65535.

With laptime you are right, it is cutted to 65535 (FF FF) because I forgot to change it up. It must count up to this value then stay FF FF.
Did fix this for the future.
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

PreviousNext

Return to Peripheral Projects

Who is online

Users browsing this forum: No registered users and 2 guests