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 yokoyoko » Tue 15. Oct 2013, 20:47

This dashboard (nano+tm1638) is really amazing for this price. My disconnect problems with the nano are solved/gone!
I tested the following games: Project Cars, Rfactor1+2, Game stock Car 2012/2013, Iracing. All work as expected and without any noticable lag. Switching between the games is no problem.

At the moment I am using mreiner's code for the nano - thx again for sharing :!: :)

I would like to thank vicpopo for his brilliant work, very well done. Of course thanos and sirnoname thank you too for the support and your (pre and continous) work.

Now I will need to get the big seven segment display running and build a nice case. The parts are here but I don't totally understand the wiring diagram atm :oops:
User avatar
yokoyoko
 
Posts: 392
Images: 28
Joined: Tue 7. Aug 2012, 03:16
Location: Germany / Bad Eilsen
Has thanked: 33 times
Been thanked: 13 times

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

Postby vicpopo » Tue 15. Oct 2013, 21:09

Hi Yokoyoko,

Thanks for compliments ;) and thanks to Thanos and Sirnoname.

what didn't you understand for the wiring diagram ?
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 Tombo » Wed 16. Oct 2013, 18:58

Hi,
for me everything also worked well now. Thanks to everyone who made this happen :D

for wireing diagramm maybe this helps you. I've created a layout. The white lines are bridges on the top side.
Have solderd this to a handmade pcb. With the inverted view its very easy to solder the lines.

You can stick your nano in. The left connectors are for 7 segment, the top one for tm1638. The right one is for pot adjustable shiftligt, you can ignore this.
21982199

Also added some pictures of the finished result. Shiftlight is a red superflux LED from car braking light with a led prisma from ebay. Pot is to adjust at which rpm shiftlight turns on and ofcourse button for max rpm.
Again thanks to everyone who helped me and worked on this project.
220722062208

Ps: here is a link for §dlaserprinting Housing for tm 1638 module. Maybe interesting for someone http://www.thingiverse.com/thing:106804/#comments
Tombo
 
Posts: 97
Images: 36
Joined: Fri 22. Feb 2013, 20:52
Location: Germany
Has thanked: 6 times
Been thanked: 8 times

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

Postby profetadelmus » Thu 13. Feb 2014, 18:27

Hello friends!

I want to share my display. I remove the two 4x7 segments (with a heat gun) and insert at the middle the big 7 segments display. Then, i weld four wires to each 4digits displays and paste again to the plate with glue (heat glue). In the back of the palte i put the arduino and the circuit to drive the big display. For the buttons, i only weld two wires to each button from the back of the TM1638 plate.

At level programming, i change the code and use the invertedTM1638 module (include invertedTM1638.h and define the module as invertedTM1638) to show the digits inverted. All works really good!!!!!!!!!!!

Display
2558

And integrated in the wheel
2559

Thanks to all members!!!
User avatar
profetadelmus
 
Posts: 79
Images: 32
Joined: Sun 22. Dec 2013, 05:14
Location: Vigo - Spain
Has thanked: 10 times
Been thanked: 3 times

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

Postby vicpopo » Thu 13. Feb 2014, 20:02

Hi,

Really good job and good looking.You made your own SLI display and cheaper.

Could you share your code for all other membes ?

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 profetadelmus » Thu 13. Feb 2014, 22:20

My code is basically a mix of various codes published here. The only different part is in the includes and the declaration of the inverted module.
In fact, at this moment, i only use the buttons for changing the rpms. I have study last post to acquire position and other obd2 info

Code: Select all
//  X-Sim Sample code for receiving OBD2 values from the extractor without using the converter
//  OBD2 is industry standard, X-Sim will additionally expand the OBD2 PID with gear and other values
//
//  Usage:
//  Arduino has to be connected to a free USB port on the computer where the extractor is running
//  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 closing the dialog you will see the arduino LED will be enabled which represents receiving data.
//  After closing the extractor application the LED will switch off.
//  Use this code to insert your own display code at the fitting positions
//  Copyright 2013 Martin Wiedenbauer, X-Sim.de
//
//  References:
//  http://en.wikipedia.org/wiki/OBD-II_PIDs
//  http://elmelectronics.com/DSheets/ELM327DS.pdf
//  http://www.x-sim.de



#include <InvertedTM1638.h>
#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
InvertedTM1638 module1(5,4,3);

//définition des broches du décodeur 7 segments (vous pouvez changer
//les numéros si bon vous semble)
const int bit_A= 6;
const int bit_B= 7;
const int bit_C= 8;
const int bit_D= 9;
//Definition des Pin pour Affichage Neutral et reverse
const int bit_E= 10;
const int bit_F= 11;
//const int ledPin =  13;   // the number of the LED pin
//byte buttons;
unsigned int rpmmaxi=5000;
//long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
//long interval = 40;           // interval at which to blink (milliseconds)

bool extractordetected=false;   //Will get updated from last positive or negative receive
int receivebuffer[100]={0};      //Receive buffer


void setup()
{
   pinMode(13, OUTPUT); //Arduino UNO LED off
   digitalWrite(13, LOW);
   Serial.begin(9600);
        //Do here stuff to init display and zero to default
//pinMode(ledPin, OUTPUT);
//Les broches sont toutes des sorties
pinMode(bit_A, OUTPUT);
pinMode(bit_B, OUTPUT);
pinMode(bit_C, OUTPUT);
pinMode(bit_D, OUTPUT);
pinMode(bit_E, OUTPUT);
pinMode(bit_F, OUTPUT);

//Les broches sont toutes mises à l'état bas pour le decodeur BCD et haut pour piloter neutral et reverse
digitalWrite(bit_A, LOW);
digitalWrite(bit_B, LOW);
digitalWrite(bit_C, LOW);
digitalWrite(bit_D, LOW);
digitalWrite(bit_E, HIGH);
digitalWrite(bit_F, HIGH);

// initialize the screen:
module1.clearDisplay();              //clears the display from garbage if any
String name = "x-sim";       //sets a custom logo start up banner
delay(5000);
module1.setDisplayToString(name);    //prints the banner
name = "    v2_3"; //sets a custom logo start up banner
module1.setDisplayToString(name);
delay(5000);

module1.setLEDs(0b10000000 | 0b00000001<< 8 );
delay(50);
module1.setLEDs(0b11000000 | 0b00000011<< 8 );
delay(50);
module1.setLEDs(0b11100000 | 0b00000111<< 8 );
delay(50);
module1.setLEDs(0b11110000 | 0b00001111<< 8 );
delay(50);
module1.setLEDs(0b11111000 | 0b00011111<< 8 );
delay(50);
module1.setLEDs(0b11111100 | 0b00111111<< 8 );
delay(50);
module1.setLEDs(0b11111110 | 0b01111111<< 8 );
delay(50);
module1.setLEDs(0b11111111 | 0b11111111<< 8 );
delay(200);
module1.setLEDs(0b00000000 | 0b00000000<< 8 );
delay(50);
module1.setLEDs(0b11111111 | 0b11111111<< 8 );
delay(100);
module1.setLEDs(0b00000000 | 0b00000000<< 8 );
delay(50);
module1.setLEDs(0b11111111 | 0b11111111<< 8 );
delay(100);
module1.setLEDs(0b00000000 | 0b00000000<< 8 );
delay(50);
module1.setLEDs(0b11111111 | 0b11111111<< 8 );
delay(100);
module1.setLEDs(0b00000000 | 0b00000000<< 8 );
delay(3000);                        //small delay 3 sec
module1.clearDisplay();              //clears the 1st display
}
int HexToInt(int c)
{
   if (c >= '0' && c <= '9')
   {
      return c - '0';
   }
   else if (c >= 'a' && c <= 'f')
   {
      return c - 'a' + 10;
   }
   else if (c >= 'A' && c <= 'F')
   {
      return c - 'A' + 10;
   }
   else
   {
      return -1; // getting here is bad: it means the character was invalid
   }
}

int ParseReceiveBuffer(int commandhighbyte, int commandlowbyte, int receivelength)
{
   //First character is removed of the receivebuffer string and must not be verified again
   if( receivebuffer[0]=='1' && receivebuffer[2]==commandhighbyte && receivebuffer[3]==commandlowbyte )
   {
      //Parse 2 byte values on position 5 and 6 in the buffer string
      if(receivelength==7)
      {
         int highresult=HexToInt(receivebuffer[5]);
         int lowresult =HexToInt(receivebuffer[6]);
         if(highresult==-1 || lowresult==-1){return -1;}
         return ((16*highresult) + lowresult);
      }
      //Parse 4 byte values on position 5,6,8 and 9 in the buffer string
      if(receivelength==10)
      {
         int tophighresult=HexToInt(receivebuffer[5]);
         int toplowresult =HexToInt(receivebuffer[6]);
         int highresult=HexToInt(receivebuffer[8]);
         int lowresult =HexToInt(receivebuffer[9]);
         if(tophighresult==-1 || toplowresult==-1 || highresult==-1 || lowresult==-1){return -1;}
         return ((4096*tophighresult) + (256*toplowresult) + (16*highresult) + lowresult);
      }
   }
   return -1; //Something is wrong with the returned OBD2 echo command byte
}

//This function will wait for the first character in receivetrigger and will parse the result
int ReceiveValueWithTimeout(int receivetrigger, int commandhighbyte, int commandlowbyte, int receivelength)
{
   int arduinoserialbuffer=0;
   int buffercount=-1;
   for(int z=0; z < 1500; z++) //500ms timeout should be enough
   {
      while(Serial.available())
      {
         if(buffercount==-1)
         {
            arduinoserialbuffer = Serial.read();
            if(arduinoserialbuffer != receivetrigger) //Wait until the trigger is reached, ignore echo, first character is not in the buffer
            {
               buffercount=-1;
            }
            else
            {
               buffercount=0;
            }
         }
         else
         {
            arduinoserialbuffer = Serial.read();
            receivebuffer[buffercount]=arduinoserialbuffer;
            buffercount++;
            if(buffercount > receivelength) //buffer has now waitlen character length
            {
               return ParseReceiveBuffer(commandhighbyte, commandlowbyte, receivelength);
               buffercount=-1;
            }
         }
      }
      delay(1);
   }
   return -1;
}

void SendEchoDisabled() //not used here and a part of the OBD2 ELM327 specifications, as INFO
{
   //ATE0 Echo disabled
   Serial.write('A');
   Serial.write('T');
   Serial.write('E');
   Serial.write('0');
   Serial.write('\r');
}

//010c Request RPM, remember:  OBD2 RPM is ((A*256)+B)/4
int GetOBD2RpmValue()
{
   //010c
   Serial.write('0');
   Serial.write('1');
   Serial.write('0');
   Serial.write('c');
   Serial.write('\r');
   return ReceiveValueWithTimeout('4','0','C',10);
}

//010d Request speed in kmh
int GetOBD2SpeedValue()
{
   //010d
   Serial.write('0');
   Serial.write('1');
   Serial.write('0');
   Serial.write('d');
   Serial.write('\r');
   return ReceiveValueWithTimeout('4','0','D',7);
}

//01e0 Request gear number
int GetOBD2GearValue()
{
   //01e0
   Serial.write('0');
   Serial.write('1');
   Serial.write('e');
   Serial.write('0');
   Serial.write('\r');
   return ReceiveValueWithTimeout('4','E','0',7);
}
//01e1 Request position number
int GetOBD2PosValue()
{
   //01e1
   Serial.write('0');
   Serial.write('1');
   Serial.write('e');
   Serial.write('1');
   Serial.write('\r');
   return ReceiveValueWithTimeout('4','E','1',7);
}



//function to display the gear on the big 7 segmemts display
void afficher(char chiffre)
{
  // pin are all set to lower levelet high level for neutral reverse
  digitalWrite(bit_A, LOW);
  digitalWrite(bit_B, LOW);
  digitalWrite(bit_C, LOW);
  digitalWrite(bit_D, LOW);
  digitalWrite(bit_E, HIGH);
  digitalWrite(bit_F, HIGH);
  //display the numerical needed
  if(chiffre >= 8)
  {
    digitalWrite(bit_D, HIGH);
    chiffre= chiffre - 8;
    }
  if(chiffre>= 4)
  {
    digitalWrite(bit_C, HIGH);
  chiffre= chiffre - 4;
  }
  if(chiffre >= 2)
  {
    digitalWrite(bit_B, HIGH);
    chiffre= chiffre - 2;
  }
  if(chiffre >= 1)
  {
    digitalWrite(bit_A, HIGH);
    chiffre= chiffre - 1;
  }
}
void loop()
{
        //unsigned long currentMillis = millis();
        int i ;
        unsigned int rpmleds; //holds the 8 leds values
        char message [8];     // variable to display the message on the display
   int vitesse=0;
   unsigned int rpm;
        unsigned int   pos;
   int gear=GetOBD2GearValue();
        pos=GetOBD2PosValue();
        while(gear >= 0)
   {
   //unsigned long currentMillis = millis();   
            if(extractordetected==false)
      {
         SendEchoDisabled();   //Will cause a OK\r as answer from the extractor, ignored in this code
         extractordetected=true;
      }
      //Read all values
      gear = GetOBD2GearValue(); //Notice: offset +1 because of reverse gear
      vitesse = GetOBD2SpeedValue();
      pos = GetOBD2PosValue();
                rpm  = GetOBD2RpmValue();
                rpm = rpm/4;
                //unsigned long currentMillis = millis();
                sprintf(message,"%3d%5d",vitesse,rpm);//display the message first 3 digits speed last 5 digits rpm
               
      if(gear!=-1 && vitesse!=-1 && rpm!=-1)
      {
         digitalWrite(13, HIGH); //We have connection and all values are ok, turn on the LED
         //Do here your LCD or display stuff
                     //rpm = constrain (rpm , 0, rpmmaxi);// limit rpm to rpmmaxi
                     
                                     
                                     
                            rpmleds = map( rpm,0,rpmmaxi,0,16 );    // distributes the rpm level to the 8 leds + 1 for shift change
                         if ( rpmleds==1 ) {
                            module1.setLEDs( 0b00000000 | 0b00000000 << 8);
                         }
                         if ( rpmleds==7 ) {
                            module1.setLEDs( 0b00000001 | 0b00000000 << 8 );
                         }
                         if ( rpmleds==8 ) {
                            module1.setLEDs( 0b00000011 | 0b00000000 << 8 );
                         }
                         if ( rpmleds==9 ) {
                            module1.setLEDs( 0b00000111 | 0b00000000 << 8 );
                         }
                         if ( rpmleds==10 ) {
                            module1.setLEDs( 0b00001111 | 0b00000000 << 8 );
                         }
                         if ( rpmleds==11 ) {
                            module1.setLEDs( 0b00011111 | 0b00000000 << 8 );
                         }
                            if ( rpmleds==12 ) {
                            module1.setLEDs( 0b00111111 | 0b00000000 << 8 );
                         }
                            if ( rpmleds==13 ) {
                            module1.setLEDs( 0b01111111 | 0b00000000 << 8 );
                         }
                         if ( rpmleds==14 ) {
                            module1.setLEDs( 0b00000000 | 0b11111111 << 8 );
                         }
                         if ( rpmleds>=15 ) {
                            module1.setLEDs( 0b00000000 | 0b11111111 << 8 );
                            delay ( 20 );
                            module1.setLEDs( 0b00000000 | 0b00000000 << 8 );
                            delay ( 20 );
                         }
                     
                         
                        if (gear==0){
                        // displays the character for reverse
                   digitalWrite(bit_A, HIGH);
                   digitalWrite(bit_B, HIGH);
                   digitalWrite(bit_C, HIGH);
                   digitalWrite(bit_D, HIGH);
                   digitalWrite(bit_E, LOW);
                   digitalWrite(bit_F, LOW);
                        //display speed
                        module1.clearDisplay();
                        module1.setDisplayToString(message , 0,0);
                        //display rpm and blinked led
                        //displays numerical the speed
                        }
                        if (gear==1){//displays the caracter for neutral
                        digitalWrite(bit_A, HIGH);
                   digitalWrite(bit_B, HIGH);
                     digitalWrite(bit_C, HIGH);
                     digitalWrite(bit_D, HIGH);
                     digitalWrite(bit_E, LOW);
                     digitalWrite(bit_F, HIGH);
                        //display speed
                        module1.clearDisplay();
                        module1.setDisplayToString(message , 0,0);
                       

                        //display rpm and blinked led
                        //displays numerical the speed
                       
                        }
                        if (gear >= 2 and gear <10 ){
                        gear=gear-1;
                        afficher(gear);//call function to display gear
                        module1.clearDisplay();
                        module1.setDisplayToString(message , 0,0);//displays numerical the speed and rpm
                        }   
                       
                       
                        //BOTONES PERSONALIZADOS
                        if (module1.getButtons() == 0b00000001){ // Posicion
                          module1.clearDisplay();
                          String name="Posicion";
                          module1.setDisplayToString(name);
                          delay (100);
                          module1.setDisplayToDecNumber(pos, 0, false);//display the pos value registered
                          delay (500);
                          }
                        if (module1.getButtons() == 0b10000000){ //store the rpmmaxi with pushing the most right button
                          rpmmaxi=rpm;
                          module1.setDisplayToDecNumber(rpmmaxi, 0, false);//display the rpmmaxi value registered
                          delay (500);
                          }
                        if (module1.getButtons() == 0b01000000){// decrease the rpmmaxi with 200rpm pitch
                          rpmmaxi=rpmmaxi-200;
                           module1.setDisplayToDecNumber(rpmmaxi, 0, false);//display the rpmmaxi value registered
                          delay (500);
                          }
                         
                        if (module1.getButtons() == 0b00100000){// decrease the rpmmaxi with 200rpm pitch
                          rpmmaxi=rpmmaxi+200;
                           module1.setDisplayToDecNumber(rpmmaxi, 0, false);//display the rpmmaxi value registered
                          delay (500);
                          }
      }

   }

   extractordetected=false;
   digitalWrite(13, LOW); //No connection, turn off the LED

   //Do here stuff to set display to zero or default
        module1.clearDisplay();              //clears the display from garbage if any
        String name = "x-sim";           //sets a custom logo start up banner
        module1.setDisplayToString(name);    //prints the banner
                              //sets a custom logo start up banner
        delay (500);
      name = "   v2_3";    //sets a custom logo start up banner
        module1.setDisplayToString(name);    //prints the banner                      //sets a custom logo start up banner
        delay (500);
       
        module1.clearDisplay();
        module1.setDisplayToDecNumber(rpmmaxi, 0, false);//display the rpmmaxi value registered
        delay (500);
        /*if (module1.getButtons() == 0b10000000){ //increase the rpmmaxi with 200rpm pitch
          rpmmaxi=rpmmaxi + 200;
        }
        if (module1.getButtons() == 0b01000000){// decrease the rpmmaxi with 200rpm pitch
          rpmmaxi=rpmmaxi-200;
        }*/
        module1.setLEDs(0b10000000 | 0b00000001<< 8 );
        delay(50);
        module1.setLEDs(0b11000000 | 0b00000011<< 8 );
        delay(50);
        module1.setLEDs(0b11100000 | 0b00000111<< 8 );
        delay(50);
        module1.setLEDs(0b11110000 | 0b00001111<< 8 );
        delay(50);
        module1.setLEDs(0b11111000 | 0b00011111<< 8 );
        delay(50);
        module1.setLEDs(0b11111100 | 0b00111111<< 8 );
        delay(50);
        module1.setLEDs(0b11111110 | 0b01111111<< 8 );
        delay(50);
        module1.setLEDs(0b11111111 | 0b11111111<< 8 );
        delay(200);
        module1.setLEDs(0b00000000 | 0b00000000<< 8 );
        delay(50);
        module1.setLEDs(0b11111111 | 0b11111111<< 8 );
        delay(100);
        module1.setLEDs(0b00000000 | 0b00000000<< 8 );
        delay(50);
        module1.setLEDs(0b11111111 | 0b11111111<< 8 );
        delay(100);
        module1.setLEDs(0b00000000 | 0b00000000<< 8 );
        delay(50);
        module1.setLEDs(0b11111111 | 0b11111111<< 8 );
        delay(100);
        module1.setLEDs(0b00000000 | 0b00000000<< 8 );
        delay(1000);                        //small delay 1 sec
        module1.clearDisplay();              //clears the 1st display
}

User avatar
profetadelmus
 
Posts: 79
Images: 32
Joined: Sun 22. Dec 2013, 05:14
Location: Vigo - Spain
Has thanked: 10 times
Been thanked: 3 times

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

Postby vicpopo » Thu 13. Feb 2014, 22:58

Thx for sharing ;)
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 » Tue 29. Apr 2014, 19:21

Hi all,

I updated the code to display the speed up to 255 km/h . The pid not elm complient is E9.The code updated is on the first topic page

Enjoy ;)
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 kbssa » Tue 13. May 2014, 05:36

Hi all,

I came to show you the dashboard that I am developing.

2845
2846
2847

This dashboard fits like a glove on the G27 and I will use double-sided tape to stick on the wheel. (more pics in few days)

For testing I am using vicpopo's code, but I will make my own and add all functions that the obd2 can provide.

To be easier to change functions,joystick buttons will be used.

When I get it working I come back to show you the results and post the code !!

Thank you to Vicopoco and Sirnoname that pointed me to right direction !

Sorry for my bad english.

Bruno
kbssa
 
Posts: 120
Images: 16
Joined: Thu 19. Apr 2012, 21:03
Has thanked: 5 times
Been thanked: 3 times

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

Postby vicpopo » Tue 13. May 2014, 06:48

Thanks kbssa,

Very intersting project and I will follow your progress.Thank you for sharing your further job.
You can also thank all poster from this thread because they all contribute to improve the code and the functionalities of the dashboard. ;)

Forgotten to ask something :

Very nice housing for the dashboard .Did you ude a printer 3D to build it?
User avatar
vicpopo
 
Posts: 645
Joined: Fri 20. Apr 2012, 18:04
Location: Strasbourg France
Has thanked: 39 times
Been thanked: 80 times

PreviousNext

Return to Peripheral Projects

Who is online

Users browsing this forum: No registered users and 2 guests