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 mreiner » Thu 12. Sep 2013, 08:52

Hi together,

Thanks for the great work, this is already working really well for me.
I only was not very satisfied with the solution to adjust the rpmmax for every car with the +/- Buttons, so I changed the code to another solution:
When pressing the rightmost button I switch to "set rpmmax" mode, where I read the current rpm and set the maxrpm accordingly. when pressing the button again, I switch back to normal mode.

So when jumping into a new car, just press button -> kick down throttle -> press button again, and I'm ready to go.


martin
mreiner
 
Posts: 32
Images: 22
Joined: Wed 15. May 2013, 08:53
Location: Lower Austria / Europe
Has thanked: 1 time
Been thanked: 15 times

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

Postby vicpopo » Thu 12. Sep 2013, 10:46

mreiner wrote:Hi together,

Thanks for the great work, this is already working really well for me.
I only was not very satisfied with the solution to adjust the rpmmax for every car with the +/- Buttons, so I changed the code to another solution:
When pressing the rightmost button I switch to "set rpmmax" mode, where I read the current rpm and set the maxrpm accordingly. when pressing the button again, I switch back to normal mode.

So when jumping into a new car, just press button -> kick down throttle -> press button again, and I'm ready to go.


martin


Hi ,

Happy that you improved this , it's the goal of the xsim community , anyone can support and improve what other made.

Could you share the code you made.I can test it and integrate in the ground code .

Thx ;)
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 prodigy » Fri 13. Sep 2013, 12:21

Hey Vic, great job!
User avatar
prodigy
X-Sim Supporter
 
Posts: 274
Images: 42
Joined: Tue 16. Oct 2012, 12:32
Location: Pula, Croatia
Has thanked: 20 times
Been thanked: 22 times

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

Postby vicpopo » Fri 13. Sep 2013, 13:02

prodigy wrote:Hey Vic, great job!

Hi Prodigy ,

Thx !! You can thank Sirnoname too ! ;)
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 mreiner » Fri 13. Sep 2013, 17:16

Hi

I haven't finished integrating the setrpmmax code to the OBD2 verion yet. I'm still unsing it in the converter USO version.

But nevertheless, here is my full code for the USO version.
As I'm pretty busy at the moment, maybe you can implement it on your own.
Code: Select all
// X-sim3dashboard v1  (using TM1638 display and Arduino Nano v3)
// Made by TronicGr (Thanos) 4-26-2012 for X-sim3
// Shared as Public Domain

// Serial parser example: R~a01~~95~S~a02~G~a03~
// Where:
// ~a01~ is 16bit value for rpm
// ~95~ is data value parameter for RPM_MAX divided by 100 to fit into a byte so actual value is 9500
// ~a02~ is 16bit value for speed
// ~a03~ is 8bit value for gear / neutral / reverse

// You can set the USO pause safely to 10ms for nice fast refresh rates!


#include <TM1638.h>          //can be downloaded from http://code.google.com/p/tm1638-library/

// define a module on data pin 5, clock pin 4 and strobe pin 3
TM1638 module( 5, 4, 3 );

int mode = 1;               // Mode what to display:
int maxrpm_changed = 0;
unsigned int    rpmlast;
unsigned int    rpmmax=7000;
byte            setrpm=0;

void setup()
{
   //Create Serial Object
   Serial.begin( 115200 );
   // initialize the screen:
   module.clearDisplay();              //clears the display from garbage if any
   String name = "Welcome";           //sets a custom logo start up banner
   module.setDisplayToString( name );    //prints the banner
   
   module.setLEDs( 0b10000000 | 0b00000001 << 8 );
   delay( 50 );
   module.setLEDs( 0b11000000 | 0b00000011 << 8 );
   delay( 50 );
   module.setLEDs( 0b11100000 | 0b00000111 << 8 );
   delay( 50 );
   module.setLEDs( 0b11110000 | 0b00001111 << 8 );
   delay( 50 );
   module.setLEDs( 0b11111000 | 0b00011111 << 8 );
   delay( 50 );
   module.setLEDs( 0b11111100 | 0b00111111 << 8 );
   delay( 50 );
   module.setLEDs( 0b11111110 | 0b01111111 << 8 );
   delay( 50 );
   module.setLEDs( 0b11111111 | 0b11111111 << 8 );
   delay( 200 );
   module.setLEDs( 0b00000000 | 0b00000000 << 8 );
   delay( 50 );
   module.setLEDs( 0b11111111 | 0b11111111 << 8 );
   delay( 100 );
   module.setLEDs( 0b00000000 | 0b00000000 << 8 );
   delay( 50 );
   module.setLEDs( 0b11111111 | 0b11111111 << 8 );
   delay( 100 );
   module.setLEDs( 0b00000000 | 0b00000000 << 8 );
   delay( 50 );
   module.setLEDs( 0b11111111 | 0b11111111 << 8 );
   delay( 100 );
   module.setLEDs( 0b00000000 | 0b00000000 << 8 );
   
   delay( 1500 );                        //small delay 1.5 sec
   module.clearDisplay();              //clears the display
}

void loop() {
   int          i;
   char          bufferArray[20];                 // holds all serial data into a array
   unsigned int    rpm;                     // holds the rpm data (0-65535 size)
   unsigned int    rpmleds;                 // holds the 8 leds values
                     // retrieves from x-sim USO this value as parameter divided by 100
   unsigned int    carspeed;                // holds the speed data (0-65535 size)
   byte          gear;                            // holds gear value data
   byte          d1;                              // high byte temp variable
   byte          d2;                              // low byte temp variable
   byte          rpmdata = 0;                     // marker that new data are available
   byte          speeddata = 0;                   // marker that new data are available
   byte          geardata = 0;                    // marker that new data are available
   byte         button;
   String          output;
   
// read Data input
   
   if ( Serial.available() >= 11 ) {               //if 6 bytes available in the Serial buffer...
      for ( i=0; i<11; i++ ) {                   // for each byte
         bufferArray[i] = Serial.read();              // put into array
      }
   }
 
   if ( bufferArray[0] == 'R' )   {               // if new bytes have been recieved
      d1 = bufferArray[1];                        // store high byte of rpm
      d2 = bufferArray[2];                           // store low byte of rpm
      rpm = ( ( d1 << 8 ) + d2 );                     // concatonate bytes (shift 8 bits)
      rpmdata=1;                                   // we got new data!
   }
   
   if ( bufferArray[4] == 'S' ) {
      d1 = bufferArray[5];                  // store high byte of speed
      d2 = bufferArray[6];                  // store low byte of speed
      carspeed = ( ( d1 << 8 ) + d2 );             // concatonate bytes (shift 8 bits)
      speeddata=1;                           // we got new data!
   }
   
   if ( bufferArray[7] == 'G' ) {
      gear = bufferArray[8];         // retrieves the single byte of gear (0-255 value)
      geardata=1;                    // we got new data!
   }
   
// read the buttons
   button = module.getButtons();

   if ( button == 0b00000001 ) {      // Button 1 - Set Mode to 1
      mode = 1;
      module.clearDisplay();
      output = "Gear Spd";
      module.setDisplayToString( output );
                delay ( 500 );
      module.clearDisplay();              //clears the display
   }

   
   if ( button == 0b10000000 )      // decrease the rpmmaxi with 200rpm pitch
   {
      module.clearDisplay();
                switch ( setrpm )
                {
                  case 0:
                    setrpm = 1;
                    output = "Set RPM";
                    rpmmax = 100;
                    module.setDisplayToString( output);
                    mode = 8;
                    delay (500);
                    break;
                   
                  case 1:
                    setrpm = 0;
                    module.clearDisplay();
                    mode = 1;
                    delay (500);
                    break;
                }
          }
   
// Print output for different modes
   
   if ( mode == 1 ) {               // Display Gear and Speed
      if ( speeddata == 1 ) {
         module.setDisplayToDecNumber( carspeed, 0, false );  //displays numerical the speed
         speeddata=0;                     
      }   
   
      if ( geardata == 1 ) {
         char* neutral = "n";                // sets the character for neutral
         char* reverse = "r";                // sets the character for reverse
         gear = gear - 127;                  // offset the 0 value in 8-bit
         if ( gear >= 1 and gear <10 ) {
            module.setDisplayDigit( gear, 0, false );   // displays numerical value of the current gear
         }
         if ( gear == 0 ) {
            module.setDisplayToString( neutral, 0, 0 );  // displays the character for neutral
         }
            if ( gear == 255 ) {                        // -1 that reprecents reverse rollover to 255 so...
            module.setDisplayToString( reverse, 0, 0 );  // displays the character for reverse
         }
         geardata=0;
      }
   }

        if ( mode == 8 ) {
                module.setDisplayToDecNumber( rpmmax, 0, false );
                if ( rpmlast > (rpmmax+200) ) {
                  rpmmax = rpmlast;
                }
   }

// color the LEDs
   
   if ( rpmdata == 1 ) {
      rpmleds = map( rpm,0,rpmmax,0,15 );    // distributes the rpm level to the 8 leds + 1 for shift change
      if ( rpmleds==1 ) {
         module.setLEDs( 0b00000000 | 0b00000000 << 8);
      }
      if ( rpmleds==7 ) {
         module.setLEDs( 0b00000001 | 0b00000000 << 8 );
      }
      if ( rpmleds==8 ) {
         module.setLEDs( 0b00000011 | 0b00000000 << 8 );
      }
      if ( rpmleds==9 ) {
         module.setLEDs( 0b00000111 | 0b00000000 << 8 );
      }
      if ( rpmleds==10 ) {
         module.setLEDs( 0b00001111 | 0b00000000 << 8 );
      }
                if ( rpmleds==11 ) {
         module.setLEDs( 0b00011111 | 0b00000000 << 8 );
      }
                if ( rpmleds==12 ) {
         module.setLEDs( 0b00111111 | 0b00000000 << 8 );
      }
                if ( rpmleds==13 ) {
         module.setLEDs( 0b01111111 | 0b00000000 << 8 );
      }
      if ( rpmleds==14 ) {
         module.setLEDs( 0b00000000 | 0b11111111 << 8 );
      }
      if ( rpmleds==15 ) {
         module.setLEDs( 0b00000000 | 0b11111111 << 8 );
         delay ( 20 );
         module.setLEDs( 0b00000000 | 0b00000000 << 8 );
         delay ( 20 );
      }
      rpmdata=0;
   }
   rpmlast = rpm;
}
mreiner
 
Posts: 32
Images: 22
Joined: Wed 15. May 2013, 08:53
Location: Lower Austria / Europe
Has thanked: 1 time
Been thanked: 15 times

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

Postby vicpopo » Fri 13. Sep 2013, 17:54

Hi ,

Many thanks.I will have a look at your code and test the '' set rpmmax feature '' :D
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 vicpopo » Mon 16. Sep 2013, 18:27

Hi Prodigy ,

Here is the answer for the request about the obd2 pid available on xsim .

OBD2 does only output:

//05 coolant temperature
//0C RPM *4
//0D Speed in kmh
//E0 GEAR with 1 as offset (not elm327 complaint)
//E1 Position (not elm327 complaint)
//E2 Current Lap (not elm327 complaint)
//E3 Best laptime (not elm327 complaint)

Regards
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 17. Sep 2013, 07:50

vicpopo wrote:Hi Prodigy ,

Here is the answer for the request about the obd2 pid available on xsim .

OBD2 does only output:

//05 coolant temperature
//0C RPM *4
//0D Speed in kmh
//E0 GEAR with 1 as offset (not elm327 complaint)
//E1 Position (not elm327 complaint)
//E2 Current Lap (not elm327 complaint)
//E3 Best laptime (not elm327 complaint)

Regards

Hi,
What's the data format of "Best laptime",and which value to be set for receivelength of following function?
ReceiveValueWithTimeout(int receivetrigger, int commandhighbyte, int commandlowbyte, int receivelength)
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 » Tue 17. Sep 2013, 20:26

char returnbuffer[]="41 E3 00 00 ";

00 00 represents the word (two bytes) in ms.
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 prodigy » Tue 17. Sep 2013, 23:33

I want to try OBD2 Com with my Arduino Nano V3 + TM1638 Display and I need some help.
I've uploaded Vicpopo's latest Arudino code (from 16.07.) to my Nano, it has restarted after upload and on my display there is a message "sim off, 10000" and leds are blinking. This message is repeating all the time.

Then I did this:

// Open the extractor and open the settings menu, there you have to select the OBD2 menu
// Add now your arduino comport to the OBD2 list.

After that on my display I got message "obd2 com" and then two "0", with last two buttons I can change RPM.
When I start a game, I'm receiving "Sim Off" message again.

What do I need to setup in Converter?
User avatar
prodigy
X-Sim Supporter
 
Posts: 274
Images: 42
Joined: Tue 16. Oct 2012, 12:32
Location: Pula, Croatia
Has thanked: 20 times
Been thanked: 22 times

PreviousNext

Return to Peripheral Projects

Who is online

Users browsing this forum: No registered users and 2 guests

cron