Arduino LCD Display

Topics and questions about dashboards, gauges etc.

Arduino LCD Display

Postby tomasi » Fri 19. Jul 2013, 00:03

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.

heres the code:
Code: Select all
#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 ("test");
//  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:
Image

Image

Image
Image
Last edited by tomasi on Tue 23. Jul 2013, 19:28, edited 1 time in total.
tomasi
 
Posts: 10
Joined: Sat 26. Jan 2013, 05:30
Has thanked: 0 time
Been thanked: 0 time

Re: Arduino LCD Display

Postby sirnoname » Fri 19. Jul 2013, 01:10

It is highly recommended to use the OBD2 arduino sourcecode!

You are using a big overhead by using the converter.
Your fail is not to use the 1:1 pass through. Your values get scaled up to 2³² and then down to 16 bit. You can also insert as scaling the maximum 2147483647.
However this is the wrong way, look at vicpopos sample (mainpage).
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1700
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 117 times

Re: Arduino LCD Display

Postby tomasi » Fri 19. Jul 2013, 18:14

Hi sirnoname ,

Im afraid OBD2 cant register lap times , tire wear and grid position. Ill take a look although.
When i select 1:1 pass through I get no data. Really dunno why.
tomasi
 
Posts: 10
Joined: Sat 26. Jan 2013, 05:30
Has thanked: 0 time
Been thanked: 0 time

Re: Arduino LCD Display

Postby sirnoname » Fri 19. Jul 2013, 18:19

1:1 ->If you output 32 bit - yes. If you shrink 32 bit to 8 bit in USO you will not see anything.
Why our OBD2 do not have lap time and position?
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1700
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 117 times

Re: Arduino LCD Display

Postby tomasi » Fri 19. Jul 2013, 18:50

Selected 32bit output and RPM now is stuck @128 and speed is 21439.

Im sorry about dumb questions. I thought OBD2 is only engine data (like real vehicles).I just installed XSIM this week and restart studying Arduino & C++ since april. Messing with it in my spare time.
I read the OBD2 Arduino sourcecode. Very well explained, although i couldnt understand the ReceiveValueWithTimeout function. Real noob here.

Im still trying hard.

Cheers from Brazil
tomasi
 
Posts: 10
Joined: Sat 26. Jan 2013, 05:30
Has thanked: 0 time
Been thanked: 0 time

Re: Arduino LCD Display

Postby tomasi » Sat 20. Jul 2013, 17:16

Any1?
Ok, got the revs working.

the math setup is value * 100000 / 160134 and maximum value set to 104856.
Although its not working with speed values. Dunno why.
tomasi
 
Posts: 10
Joined: Sat 26. Jan 2013, 05:30
Has thanked: 0 time
Been thanked: 0 time

Re: Arduino LCD Display

Postby tomasi » Fri 26. Jul 2013, 19:50

No progress so far. I´d appreciate if any1 could help. Im really lost here. Tried everything without any success...
tomasi
 
Posts: 10
Joined: Sat 26. Jan 2013, 05:30
Has thanked: 0 time
Been thanked: 0 time

Re: Arduino LCD Display

Postby vicpopo » Fri 26. Jul 2013, 20:05

Hi tomasi,

You should use as Sirnoname proposed the obd2 xsim feature.

Sorry but I can't help you with with uso parser ,I'm a noob with this feature.I always copied the code whithout to understand really it.
User avatar
vicpopo
 
Posts: 643
Joined: Fri 20. Apr 2012, 18:04
Location: Strasbourg France
Has thanked: 37 times
Been thanked: 79 times

Re: Arduino LCD Display

Postby tomasi » Fri 26. Jul 2013, 20:56

Hi vicpopo,

I tried the OBD interface and everything run pretty fine, although i thought it was very slow. Is there a way to tweak it?
tomasi
 
Posts: 10
Joined: Sat 26. Jan 2013, 05:30
Has thanked: 0 time
Been thanked: 0 time

Re: Arduino LCD Display

Postby vicpopo » Fri 26. Jul 2013, 21:16

If you red the complete topic and the replies from Sirnoname , he said that is not possible to tweak it.
I'm not qualified to discuss from,this point , I just forward what Sir explained .
If he goes here he will one more time confirm this point .
User avatar
vicpopo
 
Posts: 643
Joined: Fri 20. Apr 2012, 18:04
Location: Strasbourg France
Has thanked: 37 times
Been thanked: 79 times

Next

Return to Peripherals

Who is online

Users browsing this forum: No registered users and 1 guest

cron