Live For Speed Gear Indicator

Work IN progress...

What is it?

The Racing Simulator "Live For Speed" has the ability to broadcast live simulation data over UDP packets for much of the in-game data so even remote devices can make use of data available. This data is defined as the INSIM PACKET data. Among these is the OUTGAUGE (dashboard) information such as speed, Turbo Boost, RPM, Current Gear, etc.

A while back, a determined hacker named Vladimir Kadlec created a way to display the GEAR INDICATOR data to a seven segment LED attached to the LPT port.

This was all good while we still had LPT ports, but we seem to no longer get LPT ports on our systems. I started a project that would convert the OUTGAUGE UDP - to- LPT project into a OUTGAUGE UDP -to- Serial Port project by removing the LPT code and replacing it with the Serial Port using the Windows API.

Vlad's Project was great. It was written in the very "free" DevC++ Windows C Compiler and all source code was available. Adding the Windows Serial API was pretty straightforward.

So, I coded up a USB-FTDI-Serial port µController.

http://www.pwillard.com/files/gearind.pdf

After looking over some available tutorials... I decided to use them as a launching point for an old project I started that originally used the now obsolete Parallax SX28. I decided to share my progress.

Arduino Code - Complete (below)
INSIM UDP to Serial Relay client - Complete (will be posted on my website)
Enclosure - In Progress

Test Setup:

//----[ OutGaugeBus ]------------------------------------------------------
//  Name    : OGBUS.PDE
//-------------------------------------------------------------------------
//  Purpose : Receive serial commmands from "Live For Speed" INSIM OUTGAUGE
//          : Client and then display real-time dashboard information
//          : on Arduino based output devices, such as LED's.
//          : Live For Speed References:
//          : LFS/DOCS/INSIM.TXT
//          : http://en.lfsmanual.net/wiki/InSim_Tutorials
//          : http://www.brunsware.de/insim/
//          : See Also: http://www.lfs.net/
//-------------------------------------------------------------------------
//  Date    : 25 Oct, 2007 ( Started as a Parallax SX28 project )
//  Version : 2.11
//  Modified: 12/22/2010 11:30:34 AM
//  Author  : Pete Willard
//          :
//Additional:
//  Credits : * Mike McRoberts - Earthshine Design -
//          :     Arduino Starter Kit PDF
//          :
//          : * Hacktronics - http://www.hacktronics.com/Tutorials
//          :
//          : * Arduino ShiftOut tutorial
//          :
//          : To keep code "recognizable", available references were used
//          : and changed very little from reference sources listed above.
//-------------------------------------------------------------------------
//  Notes   : Includes using a 74HC595 Shift Register for the Bar Graph
//          : and discrete 7-segment display for gear indicator
//          :
//          : Commands come from OGBUS.EXE (DevC++ UDP Client) and convert
//          : INSIM OUTGAUGE data into serial packet data for Arduino
//          : INSIM Client Software will send ALL vaalues every update
//          : but can send as little as Clear Command "C0"
//          :
//          : Expansion:
//          : With a little creative wiring, it would be possible to
//          : daisy chain multiple serial Arduino boards or if USB is
//          : used, multiple OGBUS clients can be run at one time
//          :
//          : Command Examples:
//          : (Comma Separated Values) Any Order up to 24 Characters
//          : Format: <command><argument>,<command><argument>...<cr><lf>
//          : C0    = Clear All Outputs
//          : G0-G8 = Gear Indicator
//          : R0-R8 = RPM Bargraph
//          : S0|S1 = Shift Light Pin On|Off (binary)
//          : P0|P1 = Pit Limiter Pin On|Off (binary)
//          :
//-------------------------------------------------------------------------


//----[ Variables ]--------------------------------------------------------
const int buffsize = 25;     // Buffer Size
char buffer[buffsize];      // Incoming Serial Data Buffer
int  debug    = 0;          // Set to NON-ZERO to test with Serial Monitor
int  ledCount = 8;          // The number of LEDs in the Bar Graph LED
//-------------------------------------------------------------------------
// Seven segment LED layout for the Gear Indicator
// Arduino pins must be sequential
int GIstartpin = 2;
//                    Arduino pin: 2,3,4,5,6,7,8
byte seven_seg_digits[9][7] = {  { 0,0,0,0,1,0,1 },  // = R
                                 { 0,0,1,0,1,0,1 },  // = N
                                 { 0,1,1,0,0,0,0 },  // = 1
                                 { 1,1,0,1,1,0,1 },  // = 2
                                 { 1,1,1,1,0,0,1 },  // = 3
                                 { 0,1,1,0,0,1,1 },  // = 4
                                 { 1,0,1,1,0,1,1 },  // = 5
                                 { 1,0,1,1,1,1,1 },  // = 6
                                 { 0,0,0,0,0,0,0 },  // = 7 (blank)
                                                 };
//                                 a b c d e f g ------>  LED segment
//-------------------------------------------------------------------------
// Bargraph Values for 8 LED Bargraph
// Only 8 values of BYTE are needed to light the 8 bargraph LED's
// sequentially
// NOTE: Most Bargraph LED's are "10 unit" so I have bottom 2 and top 2
// LED's tied together.
// Part Number used:   AVAGO "HDSP-4832"  3-Green 4-Yellow 3-Red
// Mouser Part Number: 630-HDSP-4832
// The Shift Register lowest outputs start with Green Anodes of the
// Bargraph.
//
byte bargraph[9] = {0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};
//-------------------------------------------------------------------------
// LED PINS - optional since we are low on pins
int shiftlight = 12;
//int pitlimit   = 13;     // Pick one
//int lowfuel    = 13;
//-------------------------------------------------------------------------
// 74HC595 Pin Setup
int latchPin = 9;   // Pin connected to ST_CP (12) of 74HC595
int clockPin = 10;  // Pin connected to SH_CP (11) of 74HC595
int dataPin  = 11;  // Pin connected to DS    (14) of 74HC595

//----[ SETUP ]-----------------------------------------------------------
void setup() {
  // Speed needs to match INSIM - Outgauge Client Configuration setting
  Serial.begin(19200);
  Serial.flush();

  // Set all pins to Outut Mode
  int a;
  for(a=0;a < 13;a++){
      pinMode(a, OUTPUT);
   }
}

//----[ MAIN LOOP ]------------------------------------------------------
void loop() {

// Mike McRoberts serial input command routines
// from the "Serial Controlled Mood Lamp" example
// in Arduino Starter Kit Manual from Earthshine Design

if (Serial.available() > 0) {
int index=0;
  delay(10); // let the buffer fill up
  int numChar = Serial.available();
   if (numChar>buffsize) {
       numChar=buffsize;
      }
   while (numChar--) {
          buffer[index++] = Serial.read();
         }
 splitString(buffer); // Process Serial Packet
 }
}

//----[ SubRoutines ]----------------------------------------------------

void splitString(char* data) {
// also from "Serial Controlled Mood Lamp" example

if (debug) {
 Serial.print("Data entered: ");
 Serial.println(data);
}

// Sequentially De-Tokenize the Serial Commands received
 char* parameter;
       parameter = strtok (data, " ,");
   while (parameter != NULL) {
          // Pass result to parseCMD for each Command received
          parseCMD(parameter);
          // remove processed commands from the list
          parameter = strtok (NULL, " ,");
   }

   // Clear the text and serial buffers
   for (int x=0; x<buffsize; x++) {
        buffer[x]='\0';
   }
  Serial.flush();
}

//=======================================================================
void parseCMD(char* data) {
// Flexible, easily expanded Command Parser
// based on "Serial Controlled Mood Lamp" example
// *** Marvelous coding by Mike MCRoberts

//--[gear]---------------------------------------
if ((data[0] == 'G') || (data[0] == 'g')) {
 // Have command, now get Argument "value" while removing whitespace
 int ArgVal = strtol(data+1, NULL, 10);
 // then limit the results to what we expect for this command
     ArgVal = constrain(ArgVal,0,8);
     sevenSegWrite(ArgVal);

     if (debug) {
         Serial.print("Gear is set to: ");
         Serial.println(ArgVal);
     }
}

//--[shift light]--------------------------------
if ((data[0] == 'S') || (data[0] == 's')) {
 int ArgVal = strtol(data+1, NULL, 10);
     ArgVal = constrain(ArgVal,0,1);
     digitalWrite(shiftlight,ArgVal);

     if (debug) {
         Serial.print("SHIFT is set to: ");
         Serial.println(ArgVal);
     }
}

//--[reset]--------------------------------------
 if ((data[0] == 'C') || (data[0] == 'c')) {
   int ArgVal = strtol(data+1, NULL, 10);
       ArgVal = constrain(ArgVal,0,1);

       sevenSegWrite(8);
       shiftWrite(0x00);

     if (debug) {
         Serial.print("Clear Outputs");
     }
 }

 //--[rpm bar graph]-----------------------------
 if ((data[0] == 'R') || (data[0] == 'r')) {
   int ArgVal = strtol(data+1, NULL, 10);
       ArgVal = constrain(ArgVal,0,8);

       shiftWrite(bargraph[ArgVal]);

       if (debug) {
           Serial.print("RPM is set to: ");
           Serial.println(ArgVal);
       }
 }

} // End parseCMD Loop


//=======================================================================
void sevenSegWrite(byte digit) {
  byte pin = GIstartpin;
  for (byte segCount = 0; segCount < 7; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
 }
//=======================================================================
void shiftWrite(byte Rdata){
    // prepare the register for data
    digitalWrite(latchPin, LOW);
    // shift out the bits:
    shiftOut(dataPin, clockPin, MSBFIRST, Rdata);
    //Set the latch pin high to enable the outputs
    digitalWrite(latchPin, HIGH);
}

Cool, nice work, please post a picture of you driving setup when your done.

as a LFS player, this is PERFECT :sunglasses: keep it up, will build a copy here!

you might find somethinkmore from my post

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284042428/0#4

A lot of the real work was done in the UDP-INSIM-PACKET application on the PC. It listens to the OUTGAUGE values from the network and creates the serial commands that are sent to the arduino.

While this was an attempt to recreate the Gear Indicator project, it could certainly be expanded to control other things... like a real world Speedo and real gauges. Having all the source code makes it just a simple matter of coding.

Not having to use overly complicated C# or JAVA means I can code something up even if I'm short on time.

While I am certainly still tweaking the UDP-Serial application, I have made it available in its current state on my website.

http://www.pwillard.com/files/OGBFINAL.zip