1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Kilometerzähler programmieren / Programming a Miles counter

Discussion in 'Miscellaneous' started by Moelle200, Jun 8, 2012.

  1. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hallo,
    ich fahre Rennsimulation und letztens beim fahren kam mir die Idee das es interresant währe zu wissen wieviele KM ist schon zurückgelegt habe. Ich habe zuerst an einen Analogen Impulszähler gedacht wie man sie in älteren Armaturenbrettern findet allerdings gabs da wenig auswahl und die ansteurung war mir etwas schleierhaft. Also habe ich nach 7-Segment Displays geschaut und bin darauf gestoßen: http://spiffie.org/kits/usb7/ Das ist genau das was ich gesucht habe eine 6stellige 7-SEgment Display mit USB-Port. Offenbar zeigt dieses Display das an was per ASCII an den Virtuell seriell Port geschickt wird also müsste das doch mit der X-Sim Software kompatibel sein oder??
    Jetzt kommt das schwierige die Ansteuerung. Ich spiele vorallem Race07 manchmal auch LFS und das Display soll unter beiden spielen funktionieren und die Kilometer zusammen zählen.

    Sofern ich das beurteilen kann zeigen beide Spiele nicht an wieviele KM man gefahren ist (oder doch?? das währe :yippiee: ).Deswegen muss man auf eine Rechenoperation zurückgreifen. Ich habe mir vorgestellt das alle 0,1sek (oder 0,5sek) eine abfrage an das spielt kommt wie schnell ich fahre. Daraus resultieren also die Meter/0,1sek(bzw.0,05sek) diese Meter sollen dementsprechen addiert werden und an die 7-Segment anzeige gesendet werden. Eine entsprechende Liste mit den Meter/Zeit habe ich mir schon gemacht von 1-400kmh
    Da die KM anzeige dauerhaft alle KM aufzeichnen soll und für verschiedene Spiele herhalten soll müsste die KM aufzeichnung gespeichert werden. Soweit meine Theoretische überlegung.

    Ich habe mich noch nicht weiter mit der Programmieren und der X-Sim software beschäftigigt des wegen erstmal die Grundfragen ist das was ich vorhabe (kmh abgreifen in externe Dateischreiben und umrechen danach zum Display senden) überhaupt mit der X-Sim software möglich? Oder brauche ich noch externe Schaltungen mit mikrokontrollern die ich selbst bauen und Programmieren muss??
    Ich habe schon gesehen das es ein Math unterpunkt gibt aber dieser ist vermutlich nur dazu da um Kräfte vom Spiel umzurechnen wenn man ein Bewegungsimulator baut oder??

    Ich hoffe ihr könnt meinen Theoretischen überlegungen folgen und mir antworten!

    Besten Dank :)


    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Hi,
    Im driving Racing Simulations and while im Driving im getting an Idea. I want to know how many Kilometers i have driven in my Racing Carrer with diferent Racing Simulator! I found this 7-Segment USB Device http://spiffie.org/kits/usb7/ which should be compatible with the X-Sim software.

    But here is my Problem:
    The Racing Sim didnt count the driven KM so i have to extract the current Speed and and converten then into KM/sec and count them every Second.
    Here is the question ist it doable to extract the KMH in an extra file/programm an do the calculations to count the driven KM? Or is it even possibel to do this progress in the X-Sim Software??

    Hope you could help me Thanks!!
  2. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  3. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    The problem is that you could display your Speed, RPM and/or Gear but to Display the driven Kilometers you have to calculate it out of your current Speed. I have seen that you could create an Statistic Output file this is some kind Im what looking for! But it shows your speed in a chart is an beginning not more :-/
  4. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    So habe jetzt mal ein bisschen rumprobiert. Im SimConverter kann ich ja unter Output ein StaticLog erzeugen wenn ich die abfrage auf 50mili Sekunden senke muss ich den Wert mit 0,00001388888900000 multiplizieren um auf die gewünschten KM/0,05sek zu kommen (sehr kleiner Wert :rofl: ). Wenn er die KM alle unter einer Spaltet zieht kann ich es einfach zusammen rechnen und bin meinem Ziel ein großes stück weiter. Allerdings zeichnet er keine Daten auf. Weder wenn ich auf Start Loggin klicke noch wenn ich mittels Gauge Setup ein Desktop Gauge anzeigen lassen. Ich habe schon die veränderungen in der Registry der Spiele (LFS und Race) wie hier beschrieben http://www.x-simulator.de/wiki/Read_her ... _developer vorgenommen allerdings kommt nix an?? Jemand ne Idee warum nicht??
  5. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Maybe because you are in wrong forum? Did you try at www.x-sim.de forum???
  6. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Thanks for the link to your project above. I have bought the unit with the USO-Interface. At first i wanna try to copy your project - I Like the shift lights! But what i had to do with the code you posted? It´s written in C or?

    In the second vid you connectet 2 units is it connect to 1 USO-Interface or you need them twice?

    Sorry for the question im a real newbie :(
  7. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    The code is for the arduino microcontroller. The second unit shares data lines with the first unit all connected to the same arduino and you need different code for it.
  8. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Ok Thanks. Do i need any aditional software to copy the code to the microcontroller?
  9. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  10. value1

    value1 Nerd SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Jan 9, 2011
    Messages:
    2,184
    Location:
    Zug, Switzerland
    Balance:
    14,751Coins
    Ratings:
    +3,322 / 11 / -1
    My Motion Simulator:
    2DOF, DC motor, JRK, Joyrider
    Have you resolved this in the meantime? You have to start the profiler as well as the logging, see arrows below: Image.png
  11. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    In the meanthime if finde the error. Thanks
  12. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Okay ive reading a bit and now im getting closer to the goal!
    So far i used the Settings which you have posted in the Thread above (which is down at the moment ??). I have cloned the Speed axis in the Math Setup. And use the Copy and combine plugin to add the current value to the last one. In the Output Menu it shows that this is called A4. In the Orange marked filed i could add the value to calculate the kmh into km /second. How often will it recieved new data? Its importend for the calculation!

    Okay the Data (km/s) will be send to the Arduino board as a4. I Know thaht you could save and Read Data to an EEPROM. Could you help me to integrate the Code into your posted Code?

    First step include the EEPROM library into the Code:
    #include <EEPROM.h>

    Next one Read the Data (Driven KM so far) should be empty right now!
    Code:
    Something like:
    
    // start reading from the first byte (address 0) of the EEPROM
    int address = 0;
    byte value;
    
    void setup()
    {
      // initialize serial and wait for port to open:
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for Leonardo only
      }
    }
    
    void loop()
    {
      // read a byte from the current address of the EEPROM
      value = EEPROM.read(address);
      
      Serial.print(address);
      Serial.print(\t);
      Serial.print(value, DEC);
      Serial.println();
      
      // advance to the next address of the EEPROM
      address = address + 1;
      
      // there are only 512 bytes of EEPROM, from 0 to 511, so if we're
      // on address 512, wrap around to address 0
      if (address == 512)
        address = 0;
        
      delay(500);
    }
    Okay now I want to add the data a4 to the loaded EEPROM value. After this Save it to EEPROM and start at the beginning. EEPROM Value should be shown on a second TM1638 like you did in your second Video. Could you please help me??

    Do you have another Link to your shown project? I need the wiring plan that you posted in this. I had saved the TM1638 picture where you marked the Position for VCC; GND and so but i havend the wiring anymore :( I know im bugging and Im so sorry for this :(

    Attached Files:

  13. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    It would make more sense if you add a time function in arduino code and count how many meters you have per second and add the extra meters every second. Then you will have a counter for how many km you traveled in total. I think that this is what you want to do right?
  14. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    There are many roads to rome..
    My Ideas so far: I would use 2 TM1638 Units first one is like your project (gear - Speed - ShiftLight) (need the wiring plan the Project site is down??) the second unit should count the driven KM.
    The X-Sim software sends the speed data every 0,01s right? That means i had to divide the kmh through 360.000:
    eg: I drive 200kmh -> means 3,33333333km/minute (through 60) -> means 0,055555555km/sec (through 60) -> 0,000555555555km/0,01s (through 100).
    In the Math plugin I cloned the Speed Axis and used the Copy and Combine Plugin with the Add the current value option. Now he should add the current speed to last and so on. This value could be used to calculate the KM (like above).

    You could try it this way. GO to the output setup an create an Logfile with the speed every 100ms. Drive some rounds. Now open the Document (OpenOffice excel what so ever) now add all speed together and divide it thorugh 36.000 (100ms not 10ms like above) (=Sum(E2:E(last entry))/36000) now you have the driven KM. It works I tested it :D
    I Havent received the Interface and the Board so far so i coudent test it. :-(



    But the Value is still temporary. When i shut down the computer the Value is empty and he counts new. Thats not soo bad to see how many KM you have driven per Session but not exactly what im looking for. Is it possibel to Save the value into an txt Document?
    Or i will use one of the buttouns to save the data into the EEPROM.
  15. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    The project is always there, but you have to log on x-sim.de to see it. I explain it here: tronic-s-amc-motor-motion-controller-with-pwm-servo-output-t559-1400.html#p39191

    And the schematic is here: http://code.google.com/p/tm1638-library/downloads/list

    If you wish to save the traveled distance you should calculate it inside the arduino code. Let me give you an example:

    1. You calculate the total traveled speed in x-sim, you send that value to be displayed on the TM1638 screen. Ok so far...
    2. You program the arduino to store the value it has so far in the epprom. It is stored. Great!
    3. Now power off everything and on again... what happens?

    What I mean is that even if you store the value in the arduino's epprom you still need to send it back to the x-sim somehow where is the math part for it to know where it stopped counting.

    If you let arduino do the math, you can read the epprom, set the contents of that value as start value and continue counting up.

    And you don't need 0.01s resolution, 1s resolution is enough for a odometer!


     
  16. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Ohh im damm sorry. Sometime I use Windows sometimes Linux and these 2 Forums drive me crazy :( I had just seen the Project does not exist - Sorry!
    I wasent sure how high or deep i had to set the time. I was thinking less time is more precise. Okay i had to figure it out maybe 1 second maybe 0,5second this isnt the tricky part.

    Jeah that are my thoughts too :cheers:. Ok I should store the last value inside the EEPROM (for exemple by pushing a button). And when I start the the programm it Loads the EEPROM Value and counts up. Sounds like an good plan :D. Damm I want to own this platine to start programming but Chinese People had a lot of time.... ;D
  17. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    I know.. I had to wait for a month for the screens to be delivered to me... China post sucks!
  18. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Today I received an email that my order is backordered. Man this sucks.
  19. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    I had tried to start programming. My programm is based on your well written Programm:
    Code:
        #include <TM1638.h> //can be downloaded from http://code.google.com/p/tm1638-library/  
        #include <EEPROM.h>
        
        // define a module on data pin 5, clock pin 4 and strobe pin 3
        TM1638 module1(5, 4, 3);
        // define a second module on data pin 5, clock pin 4 and strobe pin 2
        TM1638 module2(5, 4, 2);
    
        int adress = 0;
        byte value;
        
        void setup() {
          //Create Serial Object
          Serial.begin(115200);
        // initialize the screen:
        module.clearDisplay();              //clears the display from garbage if any
        String name = TronicGr;           //sets a custom logo start up banner
        module.setDisplayToString(name);    //prints the banner
        delay(1500);                        //small delay 1.5 sec
        module.clearDisplay();              //clears the display
        }
        
    
        void loop() {
        int i;
            
        value = EEPROM.read(address);
        adress = adress + 1;
        if (adress == 512)
          adress = 0
          
        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
        unsigned int rpmmax;               //retrieves from x-sim USO this value as parameter divided by 100
        unsigned int carspeed;             //holds the speed data (0-65535 size)
        unsigned int KM;
        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 KM = adress                   // KM-Counter is stored in EEPROM
    So I have a few questions. I want to let Arduino read out the value of the EEPROM and declare this value as Counter so i could use this declaration in the byte KM = part.

    Code:
        value = EEPROM.read(Counter);
        Counter = Counter +1
        if (Counter == 512)
          Counter = 0
    byte KM =  Counter;
    
    Is this right?

    Or something like this

    Code:
        value = EEPROM.read(Counter);
        adress = adress + 1;
        if (adress == 512)
          adress = 0
  20. Moelle200

    Moelle200 New Member

    Joined:
    Dec 16, 2011
    Messages:
    13
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    I had read alot the last days and try to code some programm. Hier is my stat so far:
    Code:
    #include <TM1638.h> //can be downloaded from http://code.google.com/p/tm1638-library/
            #include <EEPROM.h>
          
            // define a module on data pin 5, clock pin 4 and strobe pin 3
            TM1638 module(5, 4, 3);
            // define a second module on data pin 5, clock pin 4 and strobe pin 2
            TM1638 module2(5, 4, 2);
    
            int adress = 0;
            byte value;
          
            void setup() {
              //Create Serial Object
              Serial.begin(115200);
            // initialize the screen:
            module.clearDisplay();              //clears the display from garbage if any
            String name = TronicGr;           //sets a custom logo start up banner
            String Saved = Saved;
            module.setDisplayToString(name);    //prints the banner
            delay(1500);                        //small delay 1.5 sec
            module.clearDisplay();              //clears the display
            KM-Stand = EEPROM.read(address);
            address = adress + 1;
           
            if (adress == 512)
            adress = 0
          
            unsigned long KM-Counter = KM-Stand;           //create KM Counter
     
        }
          
    
            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
            unsigned int rpmmax;               //retrieves from x-sim USO this value as parameter divided by 100
            unsigned int carspeed;             //holds the speed data (0-65535 size)
            unsigned float mpersecond          //creates m/s value
            unsigned float daycounter          //creates the KM-Day Counter
            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+
       
       
       
    if (Serial.available() >= 9)  {    //if 6 bytes available in the Serial buffer...
          for (i=0; i<9; 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)
       rpmmax = bufferArray[3];            // retrieves the maxrpm value
       rpmmax = (rpmmax * 100)+500;        // multiplies the rpm data into thousants
       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!
    }
    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 (rpmdata == 1) {
      
       rpmleds = map(rpm,0,rpmmax,0,9);    // distributes the rpm level to the 8 leds + 1 for shift change
       if (rpmleds==0){
         module.setLEDs(0b00000000 | 0b00000000 << 8);
       }
       if (rpmleds==1){
         module.setLEDs(0b00000000 | 0b00000001<< 8 );
       }
       if (rpmleds==2){
         module.setLEDs(0b00000000 | 0b00000011<< 8 );
       }
       if (rpmleds==3){
         module.setLEDs(0b00000000 | 0b00000111<< 8 );
       }
       if (rpmleds==4){
         module.setLEDs(0b00000000 | 0b00001111<< 8);
       }
       if (rpmleds==5){
         module.setLEDs(0b00000000 | 0b00011111 << 8);
       }
       if (rpmleds==6){
         module.setLEDs(0b00100000 | 0b00011111<< 8 );
       }
       if (rpmleds==7){
         module.setLEDs(0b01100000 | 0b00011111<<8 );
       }
       if (rpmleds==8){
         //module.setLEDs(0b11100000 | 0b000011111<<8 );}
         module.setLEDs(0b11111111 | 0b111111111<<8 );
       }
       rpmdata=0;
    }
    }
    {
    float mpersecond = carspeed / 360000;
    delay (10)
    }
    {
    float daycounter = mpersecond + daycounter;
    delay (10)
    }
    {
    float KM-Counter = mpersecond + KM-Counter
    delay (10)
    }
    
    if module2.getButtons() == 0b00000100 {
      module2.setDisplayToString(Saved);
      EEPROM.write (addr, KM-Counter);
    delay (1000)
      module2.setDisplayToChar(KM-Counter);
    }
    
    
    if module2.getButtons() == 0b00000001 {
      module2.setDisplayToChar(KM-Counter);
    }
    
    if module2.getButtons() == 0b00000010 {
      module2.setDisplayToChar(daycounter);
    }
    
    
    Im still unsure if the:
    KM-Stand = EEPROM.read(address);
    address = adress + 1;

    if (adress == 512)
    adress = 0
    Part gonna work.

    I had add some features: If you push the first button the display will show the Total KM-Counter. If you push the Second it will show the Session-Counter. When pushing the thrid button it will Save the data to the EEPROM.

    Today I caceled the first Dealextreme Order and rebuy it with another ASO-Board because it was out of stock. 3Hours later I received a mail that the new order is shipped. I hope for an fast delivery so i could test it!