Pages: [1]   Go Down
Author Topic: Connecting real car cluster with pc games (X-sim)2  (Read 6574 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As a continiue of that http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1280139142

[media]http://www.youtube.com/watch?v=QSElXKtEZRM[/media]


[size=16]Updating[/size][/u][/b]
« Last Edit: September 09, 2010, 09:40:44 am by herctrap » Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
int rpm;
int Speed;
int fuel;
int turbo;
char kind_of_data;


//******************** calibrate neddles here ********************
int fuel_LOW = 110;
int fuel_HIGH = 255;
int speed_LOW = 17;
int speed_HIGH = 165;
int rpm_LOW = 0;
int rpm_HIGH = 230;
int temp_LOW = 30;
int temp_HIGH = 255;
int leds_LOW = 127;
int leds_HIGH = 230;
//******************** calibrate neddles here ********************

void setup(){

  Serial.begin(115200);

  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);

  //calibration();
}

void loop()
{
  //****************************** READ DATA FROM SERIAL ******************************
  while(Serial.available() > 0)
  {

    kind_of_data = Serial.read();
    if (kind_of_data == 'R' ) Read_Rpm();
    if (kind_of_data == 'S' ) Read_Speed();
    if (kind_of_data == 'F' ) Read_Fuel();
    if (kind_of_data == 'T' ) Read_Turbo();

  }
  //****************************** READ DATA FROM SERIAL END ******************************

}

void  Read_Rpm(){

  delay(2);
  int Rpm100 = Serial.read()- '0';
  delay(2);
  int Rpm10 = Serial.read()- '0';
  delay(2);
  int Rpm1 = Serial.read()- '0';

  int rpm = 100*Rpm100 + 10*Rpm10 + Rpm1;

  setAircore(map(rpm,127,255,rpm_LOW,rpm_HIGH));
  Leds(map(rpm,leds_LOW,leds_HIGH,0,9));
}

void Read_Speed(){

  delay(2);
  int Speed100 = Serial.read()- '0';
  delay(2);
  int Speed10 = Serial.read()- '0';
  delay(2);
  int Speed1 = Serial.read()- '0';

  Speed = 100*Speed100 + 10*Speed10 + Speed1;
  analogWrite(9,map(Speed,127,255,speed_LOW,speed_HIGH));
}

void Read_Fuel(){
  delay(2);
  int Fuel100 = Serial.read()- '0';
  delay(2);
  int Fuel10 = Serial.read()- '0';
  delay(2);
  int Fuel1 = Serial.read()- '0';

  fuel = 100*Fuel100 + 10*Fuel10 + Fuel1;
  analogWrite(10,map(fuel,127,255,fuel_LOW,fuel_HIGH));


void Read_Turbo(){
  delay(2);
  int Turbo100 = Serial.read()- '0';
  delay(2);
  int Turbo10 = Serial.read()- '0';
  delay(2);
  int Turbo1 = Serial.read()- '0';

  turbo = 100*Turbo100 + 10*Turbo10 + Turbo1;
  analogWrite(11,map(turbo,0,255,temp_LOW,temp_HIGH));
}

void setAircore(float pos){

  float sinCoilValue = 255*sin(pos/40.58);
  float cosCoilValue = 255*cos(pos/40.58);

  if (sinCoilValue<=0) {
    digitalWrite(14, LOW);
    digitalWrite(15, HIGH);
  } 
  else {
    digitalWrite(14, HIGH);
    digitalWrite(15, LOW);
  }
  if (cosCoilValue<=0) {
    digitalWrite(8, LOW);
    digitalWrite(4, HIGH);
  } 
  else {
    digitalWrite(8, HIGH);
    digitalWrite(4, LOW);
  }

  sinCoilValue = abs(sinCoilValue);
  cosCoilValue = abs(cosCoilValue);

  analogWrite(6, sinCoilValue);
  analogWrite(5, cosCoilValue);
}

void Leds(int leds){

  digitalWrite(12, LOW);
  if ( leds == 0 ) shiftOut(7, 13, MSBFIRST, B00000000);  
  if ( leds == 1 ) shiftOut(7, 13, MSBFIRST, B00000001);  
  if ( leds == 2 ) shiftOut(7, 13, MSBFIRST, B00000011);  
  if ( leds == 3 ) shiftOut(7, 13, MSBFIRST, B00000111);  
  if ( leds == 4 ) shiftOut(7, 13, MSBFIRST, B00001111);  
  if ( leds == 5 ) shiftOut(7, 13, MSBFIRST, B00011111);  
  if ( leds == 6 ) shiftOut(7, 13, MSBFIRST, B00111111);  
  if ( leds == 7 ) shiftOut(7, 13, MSBFIRST, B01111111);  
  if ( leds == 8 ) shiftOut(7, 13, MSBFIRST, B11111111);  
  digitalWrite(12, HIGH);
}

Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and the calibration void:

that moves the neddles from 0 to their max position

Quote
void calibration(){

  int delayTime = 20;

  for( int calib=0; calib<256; calib++ ){
    analogWrite(9,map(calib,0,255,17,165));
    analogWrite(10,map(calib,0,255,110,255));
    analogWrite(11,map(calib,0,255,30,255));
    Leds(map(calib,0,255,0,9));
    setAircore(calib);

    delay(delayTime);
  }
  delay(1000);

  for( int calib=255; calib>=0; calib-- ){
    analogWrite(9,map(calib,0,255,17,165));
    analogWrite(10,map(calib,0,255,110,255));
    analogWrite(11,map(calib,0,255,30,255));
    Leds(map(calib,0,255,0,9));
    setAircore(calib);

    delay(delayTime);
  }
  delay(1000);

  analogWrite(9,0);
  analogWrite(10,0);
  analogWrite(11,0);

}

Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

and i am keeping that for the schematics
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How to drive the aircores with L293D


Now i just thought that you can find wich are the 2 coils by checking the resistanse on the 4 pins

you can use the calibration(); into the void loop() and then trying some combinbations of connecting the cables
how to drive the 12V Lamps if you want


X-Sim settings









« Last Edit: September 25, 2010, 02:56:42 am by herctrap » Logged

Austria
Offline Offline
Sr. Member
****
Karma: 3
Posts: 260
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

cool project, and didnt know about x-sim, thanks for that too smiley
Logged


0
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is the final

[media]http://www.youtube.com/watch?v=y0aSG55CtcI[/media]
« Last Edit: October 17, 2010, 06:21:53 pm by herctrap » Logged

Cumming, GA
Offline Offline
Edison Member
*
Karma: 20
Posts: 1655
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Dang... purdy!!!!
Logged

Pages: [1]   Go Up
Jump to: