Pages: [1]   Go Down
Author Topic: XSIM Rfactor and Arduino  (Read 545 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 70
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
Im trying to parse data  like RPM and speed from XSIM to a 16x2 lcd driven by Arduino.
Everything is ok except for misreadings. RPM on idle is 1232 and LCD displays 3338.
Speed is 0 and LCD displays 127.
Im really lost here.
 Anyone familiar with XSIM??
 heres the code:
Code:
#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int rpm;
int i;
int leds;
int Speed;
int fuel;
int ebrake;
int brake;
int fuelled;
int Turbo;
int gear;
int previous_potion = 0;
int rotate;

char kind_of_data;


void setup(){
  lcd.begin(16,2);
  Serial.begin(115200);
//  lcd.print ("BoxRaceBrazil");
//  delay(2000);
//  lcd.clear();
//  lcd.setCursor(0,1);
//  lcd.print ("inicializando...");
//  delay (5000);

lcd.clear();

}



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 == 'E' ) Read_EBrake();
//    if (kind_of_data == 'B' ) Read_Brake();

  }


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

void  Read_Rpm(){

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

  int rpm = 1000*Rpm1000+100*Rpm100 + 10*Rpm10 + Rpm1;
  rpm = map(rpm,0,255,0,255);
 
  lcd.setCursor(0,0);
  lcd.print("RPM:");
  lcd.print(rpm);
//  if (rpm<135) digitalWrite(13,HIGH);
//  if (rpm>135) digitalWrite(13,LOW);
//  if (rpm>245) digitalWrite(8,HIGH);
//  if (rpm<245) digitalWrite(8,LOW);


}

void Read_Speed(){

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

  Speed = 100*Speed100 + 10*Speed10 + Speed1;
 
lcd.setCursor(0,1);
lcd.print("VEL:");
 lcd.print(Speed);

}

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

  fuel = 100*Fuel100 + 10*Fuel10 + Fuel1;

  lcd.print(fuel);
  //if (fuel<135) digitalWrite(10,HIGH);
  //if (fuel>135) digitalWrite(10,LOW);

}


//void Read_EBrake(){
//  delay(1);
//  int EBrake100 = Serial.read()- '0';
//  delay(1);
//  int EBrake10 = Serial.read()- '0';
//  delay(1);
//  int EBrake1 = Serial.read()- '0';
//
//  ebrake = 100*EBrake100 + 10*EBrake10 + EBrake1;
//
//  if (ebrake>200) digitalWrite(3,HIGH);
//  if (ebrake<200) digitalWrite(3,LOW);
//
//}
//void Read_Brake(){
//  delay(1);
//  int Brake100 = Serial.read()- '0';
//  delay(1);
//  int Brake10 = Serial.read()- '0';
//  delay(1);
//  int Brake1 = Serial.read()- '0';
//
//  brake = 100*Brake100 + 10*Brake10 + Brake1;
//
//  if (brake>200) digitalWrite(5,HIGH);
//  if (brake<200) digitalWrite(5,LOW);
//
//}

And XSIM pages:





Logged

Pages: [1]   Go Up
Jump to: