LFS Dashboard Pt1 October 6, 2010 at 11:19 AM

Well where to start on this one… I suppose my initial inspiration came from this post on HackADay, This lead me to the discovery of Live For Speed and my new gaming addiction! It wasnt long before I had a C# program connecting to the LFS out-gauge API and displaying tachometer info on a small LED display I hacked together on the LPT port… (I will detail this in another post some time 🙂 ) But it wasn’t long before I decided to move onto, ah, bigger ideas 😛

The plan is to have a C# app connecting to LFS and sending data to a PIC micro through a USB-RS232 converter, and then have the PIC control a real instrument cluster! Initially I connected a pic up and wrote a lil C# app to test the theory and mannaged to get the pic to output a variable duty PWM signal dependent on the car’s RPM!! 😀 So onto step 2!

Yesterday I ordered a Logitech G27 to really get some realism going! This should be arriving in a week or two so that’s my time-frame to try get the instrument cluster finished. After ordering the wheel I set off into the depths of the Verulam scrap yards to try find a cheap workable gauge cluster, Initially everywhere was too expensive wanting R500-R700 for the cheapest 2ND HAND!! cluster… But just as I thought all hope was lost I pulled in to a place called “Mandos used spares” where I found this:

BMW Instrument Cluster…

At first they wanted R750 for item, but after some bargaining I managed to get it for R400! Unfortunately I didn’t know if or how easy it would be to use, but I kinda guessed Alex Rosiu was using a similar BMW cluster so how hard could it be!?

Immediately after getting home I located the part number and started a 3 hour long Google quest!:

Part Number: 6932894…

Unfortunately I only found small scattered amounts of info on this cluster, which I now believe to be a cluster off of a 2002 BMW E46. Eventually, after some creative Googling, I tracked down this pin-out which seems to match. However I didn’t see any simple inputs for speed/tachometer etc that I could just stick a PWM signal into and get the needles to move, by the look of things I figured I may have to talk to to the on-board cluster computer somehow and send it the right info serially, something I half expected  I would need to do this being typically BMW… But time to open her up and take a look:

The cluster open revealing lotsa LED’s and even a small LCD!! 😀

Yes I had all ready de-soldered the black connector and hacked in some power and ground pins to test with…

Things were WAY more complicated on the inside than I had originally expected.. I connected it up to 12v from the bench supply and things came to life! but this didn’t help much as I had no way of getting data into it yet… Back to Google and I eventually discovered that MOST of the data was sent to the cluster, not over some simple serial protocol as I had originally hoped but over the vehicles CAN serial interface from the ECU… BIG complications. At this point after a bit of thinking I figured I was stuck with two options:

1) Get my PIC to talk to the cluster over the CAN interface. The problem with this idea is I dont know what ‘Language’ the cluster talks over the CAN interface, AND I dont have any experience making PICs communicate anything other than with the UART over RS232… As far as I can tell, unless I could find a very well documented example of talking to the cluster over the CAN on the net, which doesn’t seem very likely but if you have any ideas PLEASE let me know! my only other option would be to get a Bus Pirate and an E46 BMW and sniff the traffic.. and then inject it into my cluster. All very possible but a huge amount of work and a bit out of my league for the moment and for a relatively simple project… OR

2) Figure out how to control the mechanics that move the needles and implement my own controller from scratch with a PIC. Possibly easier than option 1 although still alot more work than I originally anticipated.. and it would mean basically destroying my R400 cluster!

To make a decision I decided I needed to see what mechanics drove the needles.. I quickly de-soldered one of the ‘Motors’ to have a look hoping it would be similar to an analog Volt or mA meter that could be driven directly from PWM..

No such luck.. Turns out they are miniature Bipolar Stepper motors! It just keeps getting more complicated! Time for some more thinking…

At first I had NO idea how I would drive this thing, I’m sure I could make It move with a PIC but how would I tell what position It was at? Then I realized its a bipolar STEPPER motor, It moves in steps! It has a small tab internally that stops it at a maximum and minimum position and I’d say its range is about 300′. Theoretically I could just set it to the minimum position and move it forward and backwards with the PIC while keeping a counter for how far away it is from the ‘Zero’ position and thus know ‘where’ it is. EXCITING!

Each coil measured 275ohm so at 5v they would pass about 18.5mA of current and according to the data-sheet a PIC 16f88 can sink or source up to 25mA on each I/O pin, so I could drive it directly at-least. After reading up on how to control Bipolar Steppers I connected it to the PIC and through together some rough code.

From the 12 o’clock position going counter-clockwise PIN A,B,C,D

Basically the control scheme for 1 ‘step’ is to connect the pins in the following order AB,CD,BA,DC (where BA is the reverse polarity of AB) some code:

#include <stdio.h>
#include <htc.h>
#include <delay.h>
#include <delay.c>
#include <usart.c>
#include <usart.h>
#include <stdlib.h>

__CONFIG(0x3F30);
__CONFIG(0X3FFC);

//define
#define _XTAL_FREQ=8MHZ
#define A        RA1
#define B        RA0
#define C        RA7
#define D        RA6
#define dly     3
#define TRUE    1
#define FALSE   0

volatile char speed_current, count;
char data_in

void init(void)
{
IRCF2=1; //
IRCF1=1; // These set the internal osc @ 8Mhz. Prob overkill 😀
IRCF0=1; //

TRISA=0b00000000;
TRISB=0b01001111; // make RB6/3/2/1/0 input

GIE=1;
PEIE=1;
init_comms();    // set up the USART – settings defined in usart.h

// Output a message
printf(“\rHello There 🙂 I’m online! :D\n”);

}

void interrupt my_isr(void)
{
if((RCIE)&&(RCIF)) // Data has arrived via usart
{
data_in = getch();
//No clearing RCIF, must clear RCREG
RB4 = !RB4;
RCREG = 0;
}
}

void fwd1stp(void);
void rev1stp(void);
void startup(void);

//main function
//================================================================
void main(void)
{

//device peripheral configuration
init();
startup();
speed_current = 0;
ei();
RCIE = 1;
RB4 = !RB4;

//infinite loop
while(1)
{
if(data_in > speed_current)
{
fwd1stp();
speed_current++;

}

if(data_in < speed_current)
{
rev1stp();
speed_current–;
}

}
}

void fwd1stp(void)
{
D=1;
DelayMs(dly);
D=0;
B=1;
DelayMs(dly);
B=0;
C=1;
DelayMs(dly);
C=0;
A=1;
DelayMs(dly);
A=0;
}

void rev1stp(void)
{
A=1;
DelayMs(dly);
A=0;
C=1;
DelayMs(dly);
C=0;
B=1;
DelayMs(dly);
B=0;
D=1;
DelayMs(dly);
D=0;
}

void startup(void)
{
for(int c =0; c<120; c++)
{
fwd1stp();
}
for(int c =0; c<120; c++)
{
rev1stp();
}

}

I found a delay of about 2ms between coil transitions worked best however I think I didn’t quite get the wiring of the coils right and the stepper code can certainly use some improvement like finer delay sequences and half-stepping to make it A LOT smoother and increase the resolution… I’ll get to this eventually! but for the moment IT WORKS! here is a quick vid I made of the stepper being controlled by LFS: (I apologize for holding the camera the wrong way and the shitty vid xD in my defense it was about 6AM and I hadn’t had my coffee yet! :P)

Well for now thats that! when I get home this evening I’m going to do some more work on this project and see if I can get it all up and running! feel free to comment and keep a look out for part 2!

~Rob.

3 Responses to “LFS Dashboard Pt1”

  1. Hey dude, just throwing it out there – you have far to much free time 😛

  2. This is quite possible! but at-least I’m either spending that time working or learning… 🙂

  3. Thank you for this article. I’d also like to express that it can always be hard when you find yourself in school and simply starting out to create a long credit standing. There are many scholars who are only trying to make it through and have a lengthy or positive credit history can sometimes be a difficult matter to have. Drop by my site whenever you wish. thank you!!!

Leave a Reply