Peguei o codigo que foi postado e botei no meu arduino uno com o meu lcd 16x2. Ele le o codigo tudo certinho porem eu não faço a minima ideia de como configurar o X-SIM pra mandar as informações pro arduino.
Extractor -> Settings -> OBD2 -> add your arduino comport, thats all Tell more about the used game, make screenshots of current situation in extractor.
If a answer is correct or did help you for a solution, please use the solve button.
Obrigado Sirnoname, segui oque você falou e deu certo, está tudo funcionando 100%.
Mas eu gostaria de saber como faço para puxar mais informações do jogo para o LCD, olhei alguns Dashboard que a pessoa aperta um botão e mudas as informações no LCD.
Obrigado pela ajuda de vocês. ----------------------------------------------
Google Translate.
Thanks Sirnoname, I followed what you said and it worked, everything is working 100%.
But I would like to know how do I get more information of the game for the LCD, I looked at some Dashboard (the person presses a button and mute the information on the LCD).
Andei postando minhas experiências em outro tópico, mas como ali tá meio "morto" quem sabe aqui o negócio anda para frente. Consegui fazer funcionar no rfactor, rfactor 2, game stock car extreme, formula truck 2013, assetto corsa e euro truck simulator 2.
No assetto corsa e no euro truck só consigo "pegar" rpm, velocidade e marchas (usando OBD II). Nos outros games, além desses itens pego posição, numero da volta, melhor volta. No assetto corsa consigo pegar o tempo total da corrida, mas não a best lap nem o tempo de volta hahahaha. Combustível não consegui fazer funcionar,(ainda). To tentando implementar um código meio "universal" já q esse display 16x2 é bem barato, mais para frente planejo pegar um de oled pq tem o refresh rate maior, ilumina mais e não tem necessidade de backlight.
// X-Sim Sample code for receiving OBD2 values from the extractor without using the converter // OBD2 is industry standard, X-Sim will additionally expand the OBD2 PID with gear and other values // // Usage: // Arduino has to be connected to a free USB port on the computer where the extractor is running // Open the extractor and open the settings menu, there you have to select the OBD2 menu // Add now your arduino comport to the OBD2 list. // After closing the dialog you will see the arduino LED will be enabled which represents receiving data. // After closing the extractor application the LED will switch off. // Use this code to insert your own display code at the fitting positions // Copyright 2013 Martin Wiedenbauer, X-Sim.de // New procedures ideias by bahzitchiu // Share for free // References: // http://en.wikipedia.org/wiki/OBD-II_PIDs // http://elmelectronics.com/DSheets/ELM327DS.pdf // http://www.x-sim.de
int i; char* neutral = "n"; char* reverse = "r"; unsigned int rpmleds; char message[8]; String output; int hours; int mins; int secs; int millisec; long inttime;
gear = GetOBD2GearValue(); c=0; d=0; while (gear >= 0) {
if (extractordetected == false) { SendEchoDisabled(); extractordetected = true; }
// X-Sim Sample code for receiving OBD2 values from the extractor without using the converter // OBD2 is industry standard, X-Sim will additionally expand the OBD2 PID with gear and other values // // Usage: // Arduino has to be connected to a free USB port on the computer where the extractor is running // Open the extractor and open the settings menu, there you have to select the OBD2 menu // Add now your arduino comport to the OBD2 list. // After closing the dialog you will see the arduino LED will be enabled which represents receiving data. // After closing the extractor application the LED will switch off. // Use this code to insert your own display code at the fitting positions // Copyright 2013 Martin Wiedenbauer, X-Sim.de // // References: // http://en.wikipedia.org/wiki/OBD-II_PIDs // http://elmelectronics.com/DSheets/ELM327DS.pdf // http://www.x-sim.de
{ // assignes each segment a write number lcd.createChar(1,bar1); lcd.createChar(2,bar2); lcd.createChar(3,bar3); lcd.createChar(4,bar4); lcd.createChar(5,bar5); lcd.createChar(6,bar6); lcd.createChar(7,bar7); lcd.createChar(8,bar8);
// sets the LCD's rows and colums: lcd.begin(16, 2); pinMode(13, OUTPUT); //Arduino UNO LED off digitalWrite(13, HIGH); Serial.begin(9600);//9600 //Do here stuff to init display and zero to default lcd.begin(16, 2); lcd.print(" X-SIM DASH"); delay(3000); lcd.clear(); }
int HexToInt(int c) { if (c >= '0' && c <= '9') { return c - '0'; } else if (c >= 'a' && c <= 'f') { return c - 'a' + 10; } else if (c >= 'A' && c <= 'F') { return c - 'A' + 10; } else { return -1; // getting here is bad: it means the character was invalid } }
//This function will wait for the first character in receivetrigger and will parse the result int ReceiveValueWithTimeout(int receivetrigger, int commandhighbyte, int commandlowbyte, int receivelength) { int arduinoserialbuffer = 0; int buffercount = -1; for (int z = 0; z < 1500; z++) //500ms timeout should be enough { while (Serial.available()) { if (buffercount == -1) { arduinoserialbuffer = Serial.read(); if (arduinoserialbuffer != receivetrigger) //Wait until the trigger is reached, ignore echo, first character is not in the buffer { buffercount = -1; } else { buffercount = 0; } } else { arduinoserialbuffer = Serial.read(); receivebuffer[buffercount] = arduinoserialbuffer; buffercount++; if (buffercount > receivelength) //buffer has now waitlen character length { return ParseReceiveBufferOffset(commandhighbyte, commandlowbyte, receivelength, 0); buffercount = -1; } } } delay(1); } return -1; }
long ParseReceiveBufferOffset(int commandhighbyte, int commandlowbyte, int receivelength, int offset) { //First character is removed of the receivebuffer string and must not be verified again if (receivebuffer[0] == '1' && receivebuffer[2] == commandhighbyte && receivebuffer[3] == commandlowbyte) { //Parse 2 byte values on position 5 and 6 in the buffer string if (receivelength == 7) { int highresult = HexToInt(receivebuffer[offset + 5]); int lowresult = HexToInt(receivebuffer[offset + 6]); if (highresult == -1 || lowresult == -1){ return -1; } return ((16 * highresult) + lowresult); } //Parse 4 byte values on position 5,6,8 and 9 in the buffer string if (receivelength == 10) { int tophighresult = HexToInt(receivebuffer[offset + 5]); int toplowresult = HexToInt(receivebuffer[offset + 6]); int highresult = HexToInt(receivebuffer[offset + 8]); int lowresult = HexToInt(receivebuffer[offset + 9]); if (tophighresult == -1 || toplowresult == -1 || highresult == -1 || lowresult == -1){ return -1; } return ((4096 * tophighresult) + (256 * toplowresult) + (16 * highresult) + lowresult); }
if (receivelength == 16) { int tophighresult = HexToInt(receivebuffer[offset + 5]); int toplowresult = HexToInt(receivebuffer[offset + 6]); int highresult = HexToInt(receivebuffer[offset + 8]); int lowresult = HexToInt(receivebuffer[offset + 9]); int tophighresult2 = HexToInt(receivebuffer[offset + 11]); int toplowresult2 = HexToInt(receivebuffer[offset + 12]); int highresult2 = HexToInt(receivebuffer[offset + 14]); int lowresult2 = HexToInt(receivebuffer[offset + 15]);
} return -1; //Something is wrong with the returned OBD2 echo command byte }
bool ReceiveAllValuesWithTimeout(int receivetrigger, int commandhighbyte, int commandlowbyte, int receivelength) { int arduinoserialbuffer = 0; int buffercount = -1; for (int z = 0; z < 1500; z++) //500ms timeout should be enough { while (Serial.available()) { if (buffercount == -1) { arduinoserialbuffer = Serial.read(); if (arduinoserialbuffer != receivetrigger) //Wait until the trigger is reached, ignore echo, first character is not in the buffer { buffercount = -1; } else { buffercount = 0; } } else { arduinoserialbuffer = Serial.read(); receivebuffer[buffercount] = arduinoserialbuffer; buffercount++; if (buffercount > receivelength) //buffer has now waitlen character length { return true; buffercount = -1; } } } delay(1); } return false; }
void ClearReceiveBuffer() { while (Serial.available()) { Serial.read(); } }
void SendEchoDisabled() //not used here and a part of the OBD2 ELM327 specifications, as INFO { //ATE0 Echo disabled Serial.write('A'); Serial.write('T'); Serial.write('E'); Serial.write('0'); Serial.write('\r'); }
//01e5 Request current joystick button status 0 to 7 int GetOBD2JoyStatus0to7() { //01e5 ClearReceiveBuffer(); Serial.write('0'); Serial.write('1'); Serial.write('e'); Serial.write('5'); Serial.write('\r'); return ReceiveValueWithTimeout('4', 'E', '5', 7); }
void loop() { //unsigned long currentMillis = millis(); int i; char* neutral = "n"; // sets the character for neutral char* reverse = "r"; // sets the character for reverse unsigned int rpmleds; //holds the 8 leds values char message[8]; // variable to display the message on the display int fuel; int joybutton; byte button; String output; int dots = 40; int hours; int mins; int secs; int millisec; long inttime;
gear = GetOBD2GearValue();
while (gear >= 0) { //unsigned long currentMillis = millis(); if (extractordetected == false) { SendEchoDisabled(); //Will cause a OK\r as answer from the extractor, ignored in this code extractordetected = true; }
if (speed > 0){ c = speed*3.595; sprintf(message,"%3d",c); lcd.setCursor(1,1); lcd.write(message); } delay(1);
rpmlast = rpm;
} extractordetected = false; digitalWrite(13, HIGH); //No connection, turn off the LED lcd.setCursor(0,0); lcd.write("[<-OPEN X-SIM->]"); lcd.setCursor(0,1); lcd.write(" EURO TRUCK 2"); delay(2000); //No serial connection, poll serial port all two seconds + readtimeout until a running extractor is detected lcd.clear(); }
Andei postando minhas experiências em outro tópico, mas como ali tá meio "morto" quem sabe aqui o negócio anda para frente. Consegui fazer funcionar no rfactor, rfactor 2, game stock car extreme, formula truck 2013, assetto corsa e euro truck simulator 2.
No assetto corsa e no euro truck só consigo "pegar" rpm, velocidade e marchas (usando OBD II). Nos outros games, além desses itens pego posição, numero da volta, melhor volta. No assetto corsa consigo pegar o tempo total da corrida, mas não a best lap nem o tempo de volta hahahaha. Combustível não consegui fazer funcionar,(ainda). To tentando implementar um código meio "universal" já q esse display 16x2 é bem barato, mais para frente planejo pegar um de oled pq tem o refresh rate maior, ilumina mais e não tem necessidade de backlight.
// X-Sim Sample code for receiving OBD2 values from the extractor without using the converter // OBD2 is industry standard, X-Sim will additionally expand the OBD2 PID with gear and other values // // Usage: // Arduino has to be connected to a free USB port on the computer where the extractor is running // Open the extractor and open the settings menu, there you have to select the OBD2 menu // Add now your arduino comport to the OBD2 list. // After closing the dialog you will see the arduino LED will be enabled which represents receiving data. // After closing the extractor application the LED will switch off. // Use this code to insert your own display code at the fitting positions // Copyright 2013 Martin Wiedenbauer, X-Sim.de // New procedures ideias by bahzitchiu // Share for free // References: // http://en.wikipedia.org/wiki/OBD-II_PIDs // http://elmelectronics.com/DSheets/ELM327DS.pdf // http://www.x-sim.de
int i; char* neutral = "n"; char* reverse = "r"; unsigned int rpmleds; char message[8]; String output; int hours; int mins; int secs; int millisec; long inttime;
gear = GetOBD2GearValue(); c=0; d=0; while (gear >= 0) {
if (extractordetected == false) { SendEchoDisabled(); extractordetected = true; }
// X-Sim Sample code for receiving OBD2 values from the extractor without using the converter // OBD2 is industry standard, X-Sim will additionally expand the OBD2 PID with gear and other values // // Usage: // Arduino has to be connected to a free USB port on the computer where the extractor is running // Open the extractor and open the settings menu, there you have to select the OBD2 menu // Add now your arduino comport to the OBD2 list. // After closing the dialog you will see the arduino LED will be enabled which represents receiving data. // After closing the extractor application the LED will switch off. // Use this code to insert your own display code at the fitting positions // Copyright 2013 Martin Wiedenbauer, X-Sim.de // // References: // http://en.wikipedia.org/wiki/OBD-II_PIDs // http://elmelectronics.com/DSheets/ELM327DS.pdf // http://www.x-sim.de
{ // assignes each segment a write number lcd.createChar(1,bar1); lcd.createChar(2,bar2); lcd.createChar(3,bar3); lcd.createChar(4,bar4); lcd.createChar(5,bar5); lcd.createChar(6,bar6); lcd.createChar(7,bar7); lcd.createChar(8,bar8);
// sets the LCD's rows and colums: lcd.begin(16, 2); pinMode(13, OUTPUT); //Arduino UNO LED off digitalWrite(13, HIGH); Serial.begin(9600);//9600 //Do here stuff to init display and zero to default lcd.begin(16, 2); lcd.print(" X-SIM DASH"); delay(3000); lcd.clear(); }
int HexToInt(int c) { if (c >= '0' && c <= '9') { return c - '0'; } else if (c >= 'a' && c <= 'f') { return c - 'a' + 10; } else if (c >= 'A' && c <= 'F') { return c - 'A' + 10; } else { return -1; // getting here is bad: it means the character was invalid } }
//This function will wait for the first character in receivetrigger and will parse the result int ReceiveValueWithTimeout(int receivetrigger, int commandhighbyte, int commandlowbyte, int receivelength) { int arduinoserialbuffer = 0; int buffercount = -1; for (int z = 0; z < 1500; z++) //500ms timeout should be enough { while (Serial.available()) { if (buffercount == -1) { arduinoserialbuffer = Serial.read(); if (arduinoserialbuffer != receivetrigger) //Wait until the trigger is reached, ignore echo, first character is not in the buffer { buffercount = -1; } else { buffercount = 0; } } else { arduinoserialbuffer = Serial.read(); receivebuffer[buffercount] = arduinoserialbuffer; buffercount++; if (buffercount > receivelength) //buffer has now waitlen character length { return ParseReceiveBufferOffset(commandhighbyte, commandlowbyte, receivelength, 0); buffercount = -1; } } } delay(1); } return -1; }
long ParseReceiveBufferOffset(int commandhighbyte, int commandlowbyte, int receivelength, int offset) { //First character is removed of the receivebuffer string and must not be verified again if (receivebuffer[0] == '1' && receivebuffer[2] == commandhighbyte && receivebuffer[3] == commandlowbyte) { //Parse 2 byte values on position 5 and 6 in the buffer string if (receivelength == 7) { int highresult = HexToInt(receivebuffer[offset + 5]); int lowresult = HexToInt(receivebuffer[offset + 6]); if (highresult == -1 || lowresult == -1){ return -1; } return ((16 * highresult) + lowresult); } //Parse 4 byte values on position 5,6,8 and 9 in the buffer string if (receivelength == 10) { int tophighresult = HexToInt(receivebuffer[offset + 5]); int toplowresult = HexToInt(receivebuffer[offset + 6]); int highresult = HexToInt(receivebuffer[offset + 8]); int lowresult = HexToInt(receivebuffer[offset + 9]); if (tophighresult == -1 || toplowresult == -1 || highresult == -1 || lowresult == -1){ return -1; } return ((4096 * tophighresult) + (256 * toplowresult) + (16 * highresult) + lowresult); }
if (receivelength == 16) { int tophighresult = HexToInt(receivebuffer[offset + 5]); int toplowresult = HexToInt(receivebuffer[offset + 6]); int highresult = HexToInt(receivebuffer[offset + 8]); int lowresult = HexToInt(receivebuffer[offset + 9]); int tophighresult2 = HexToInt(receivebuffer[offset + 11]); int toplowresult2 = HexToInt(receivebuffer[offset + 12]); int highresult2 = HexToInt(receivebuffer[offset + 14]); int lowresult2 = HexToInt(receivebuffer[offset + 15]);
} return -1; //Something is wrong with the returned OBD2 echo command byte }
bool ReceiveAllValuesWithTimeout(int receivetrigger, int commandhighbyte, int commandlowbyte, int receivelength) { int arduinoserialbuffer = 0; int buffercount = -1; for (int z = 0; z < 1500; z++) //500ms timeout should be enough { while (Serial.available()) { if (buffercount == -1) { arduinoserialbuffer = Serial.read(); if (arduinoserialbuffer != receivetrigger) //Wait until the trigger is reached, ignore echo, first character is not in the buffer { buffercount = -1; } else { buffercount = 0; } } else { arduinoserialbuffer = Serial.read(); receivebuffer[buffercount] = arduinoserialbuffer; buffercount++; if (buffercount > receivelength) //buffer has now waitlen character length { return true; buffercount = -1; } } } delay(1); } return false; }
void ClearReceiveBuffer() { while (Serial.available()) { Serial.read(); } }
void SendEchoDisabled() //not used here and a part of the OBD2 ELM327 specifications, as INFO { //ATE0 Echo disabled Serial.write('A'); Serial.write('T'); Serial.write('E'); Serial.write('0'); Serial.write('\r'); }
//01e5 Request current joystick button status 0 to 7 int GetOBD2JoyStatus0to7() { //01e5 ClearReceiveBuffer(); Serial.write('0'); Serial.write('1'); Serial.write('e'); Serial.write('5'); Serial.write('\r'); return ReceiveValueWithTimeout('4', 'E', '5', 7); }
void loop() { //unsigned long currentMillis = millis(); int i; char* neutral = "n"; // sets the character for neutral char* reverse = "r"; // sets the character for reverse unsigned int rpmleds; //holds the 8 leds values char message[8]; // variable to display the message on the display int fuel; int joybutton; byte button; String output; int dots = 40; int hours; int mins; int secs; int millisec; long inttime;
gear = GetOBD2GearValue();
while (gear >= 0) { //unsigned long currentMillis = millis(); if (extractordetected == false) { SendEchoDisabled(); //Will cause a OK\r as answer from the extractor, ignored in this code extractordetected = true; }
if (speed > 0){ c = speed*3.595; sprintf(message,"%3d",c); lcd.setCursor(1,1); lcd.write(message); } delay(1);
rpmlast = rpm;
} extractordetected = false; digitalWrite(13, HIGH); //No connection, turn off the LED lcd.setCursor(0,0); lcd.write("[<-OPEN X-SIM->]"); lcd.setCursor(0,1); lcd.write(" EURO TRUCK 2"); delay(2000); //No serial connection, poll serial port all two seconds + readtimeout until a running extractor is detected lcd.clear(); }
exatamente o que eu queria, mais como fazer a ligação no arduino?