Go Down

Topic: Connecting real car cluster with pc games (X-sim)2 (Read 8809 times) previous topic - next topic

herctrap

Sep 09, 2010, 04:27 pm Last Edit: Sep 09, 2010, 04:40 pm by herctrap Reason: 1
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]
http://www.youtube.com/watch?v=QSElXKtEZRM

[size=16]Updating[/size][/u][/b]

herctrap

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);
}


herctrap

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);

}


herctrap


herctrap

#4
Sep 25, 2010, 09:41 am Last Edit: Sep 25, 2010, 09:56 am by herctrap Reason: 1
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










designer2k2

cool project, and didnt know about x-sim, thanks for that too :)
http://www.designer2k2.at

herctrap

#6
Oct 18, 2010, 01:21 am Last Edit: Oct 18, 2010, 01:21 am by herctrap Reason: 1
here is the final

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

pwillard


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy