OBD2 vers Arduino uno

Bonjour,
Étant toujours, à la recherche d’expériences a mener je me suis maintenant attelé à l'OBD sur ma titine...
Voici mon projet, un adaptateur OBD/TTL relié à une arduino UNO qui retranscrit (pour l'exemple) le nombre de tr/min sur un moniteur video.

Jusque là, pas de soucis car j'ai trouver une librairie pour l'OBD et une pour la sortie video composite. Seulement, mon envie de vous faire partager mon projet terminée s'est vu coupée net au moment du premier test de mon adaptateur...

Je vous explique mon problème, j'ai acheté un adaptateur OBD/Usb. Je me suis renseigné sur internet et d'après ce que j'ai compris, ce n'est rien de plus qu'un convertisseur de tension avec un ELM327. Du coup (d'après mon raisonnement) vu que les tensions de l'arduino correspondent avec celles de l'usb, ça devait "surement" marché XD
Donc me voici lors du test avec mon pseudo raccord OBD/TTL relié à mon arduino qui envoie les infos par le port série à mon pc mais lorsque je branche le raccord à l'arduino, il m'envoie en permanence et toutes les 3 ou 4sec le message "atz" même s'il n'est pas connecté à la voiture...

De quoi pensez vous que cela puisse venir ?

Sinon pour les interessé voici le code (sans la fonction de sortie video):

#include <OBD.h>

COBD obd;

void setup()
{  
  // start serial communication at the adapter defined baudrate
  Serial.begin(OBD_SERIAL_BAUDRATE); //38 400 Bauds
  // initiate OBD-II connection until success
  while (!obd.Init());  
}

void loop()
{
  int value;
  if (obd.ReadSensor(PID_RPM, value)) {
    Serial.println(value);
  }
}

Voilou,

En espérant pouvoir un jour, vous présenter mon projet terminé et complet :slight_smile:

Bonjour

Un convertisseur ODB/USB ne peut pas être un simple convertisseur de tension.

l'ELM327 est un microcontroleur PIC programmé pour lire différents protocole ODB. Son interface vers l'utilisateur est une liaison série.
L'adaptateur ODB/USB dont tu parles utilise donc un ELM327 + adaptateur USB/série.

Tu ne pourras pas relier à l'Arduino sur la partie USB. Suivant le modèle tu as -ou pas- accès à la partie liaison série.
Dans ce cas, cette liaison série, à niveau TTL, peut être reliée directement à l'Arduino (TX/RX).
Attention, si ce n'est pas de la liaison série TTL mais RS232, les niveaux ne sont pas le mêmes et tu ne peut pas relier à l'Arduino sans un adapteur de tension et de polarité (type MAX232 et famille).

Ah j'savais bien qu'il y avait une arnaque dans cet USB... :~
Plus qu'à ouvrir le boitier et squeezer tout ça.

Je vous tiens aux news :wink:

Merci pour ta reponse

Me revoila avec mon projet :slight_smile:
Cependant j'ai encore un soucis... :~
Je vous explique:

Après avoir démonter mon boitier elm327 pour me brancher avant la partie "USB" je me suis rendu compte que plus rien ne marchait... (ce qui était à prévoir me direz vous)

Qu'à cela ne tienne j'ai du temps à perdre et je me suis donc attelé à fabriquer mon propre montage avec un vrai Elm327 et après avoir corrigé plusieurs erreurs du schéma que j'avais trouvé sur internet mon montage s'est enfin mis à fonctionner !! :smiley:
Du coup je programme mon arduino pour faire afficher les km/h et les tr/min sur un 'tit écran lcd juste pour commencer avec un code que j'ai trouvé sur le site de sparkfun qu'ils utilisent pour leur adaptateur "tout fait" mais le probleme est que ça me disait que je roule à plus de 200km/h à 15000 tr/min sans meme avoir branché la prise obd à ma voiture (et ça fait pareil lorsqu'elle est branchée voiture arrêtée ou en route).
J'ai essayé avec d'autres codes mais ça faisait pareil...

Qu'à cela ne tienne n°2 : J'achète l'adaptateur obd-ii-uart de chez sparfun, après avoir vu plusieurs vidéo de gens qui l'utilisaient et avec seulement 1Rx/Tx je me suis dis que cette foi tout devrait fonctionner parfaitement !

3 semaines plus tard... Je reçois mon petit colis rouge sparkfun 8)

Je le branche, reprends mon code sur le site sparkfun, et... toujours pareil... je reçois des valeurs toutes bêtes...
je ne sais plus quoi faire, si quelqu'un à une idée d'où viendrait le problème je suis preneur :wink:

Pour info j'ai tout vérifier: mon câble, les codes arduino, mon arduino elle même et mon écran lcd mais tout est impeccable...

Voici le code pour ceux que ça intéresse :

#include <NewSoftSerial.h>

//Create an instance of the new soft serial library to control the serial LCD
//Note, digital pin 3 of the Arduino should be connected to Rx of the serial LCD.
NewSoftSerial lcd(2,3);

//This is a character buffer that will store the data from the serial port
char rxData[20];
char rxIndex=0;

//Variables to hold the speed and RPM data.
int vehicleSpeed=0;
int vehicleRPM=0;

void setup(){
  //Both the Serial LCD and the OBD-II-UART use 9600 bps.
  lcd.begin(9600);
  Serial.begin(9600);
  
  //Clear the old data from the LCD.
  lcd.print(254, BYTE);
  lcd.print(1, BYTE);  
  
  //Put the speed header on the first row.
  lcd.print("Speed: ");
  lcd.print(254, BYTE);
  //Put the RPM header on the second row.
  lcd.print(128+64, BYTE);
  lcd.print("RPM: ");
  
  //Wait for a little while before sending the reset command to the OBD-II-UART
  delay(1500);
  //Reset the OBD-II-UART
  Serial.println("ATZ");
  //Wait for a bit before starting to send commands after the reset.
  delay(2000);
  
  //Delete any data that may be in the serial port before we begin.
  Serial.flush();
}

void loop(){
  //Delete any data that may be in the serial port before we begin.  
  Serial.flush();
  //Set the cursor in the position where we want the speed data.
  lcd.print(254, BYTE);
  lcd.print(128+8, BYTE);
  //Clear out the old speed data, and reset the cursor position.
  lcd.print("        ");
  lcd.print(254, BYTE);
  lcd.print(128+8, BYTE);
  //Query the OBD-II-UART for the Vehicle Speed
  Serial.println("010D");
  //Get the response from the OBD-II-UART board. We get two responses
  //because the OBD-II-UART echoes the command that is sent.
  //We want the data in the second response.
  getResponse();
  getResponse();
  //Convert the string data to an integer
  vehicleSpeed = strtol(&rxData[6],0,16);
  //Print the speed data to the lcd
  lcd.print(vehicleSpeed);
  lcd.print(" km/h");
  delay(100);
  
  //Delete any data that may be left over in the serial port.
  Serial.flush();
  //Move the serial cursor to the position where we want the RPM data.
  lcd.print(254, BYTE);
  lcd.print(128 + 69, BYTE);
  //Clear the old RPM data, and then move the cursor position back.
  lcd.print("          ");
  lcd.print(254, BYTE);
  lcd.print(128+69, BYTE);

  //Query the OBD-II-UART for the Vehicle rpm
  Serial.println("010C");
  //Get the response from the OBD-II-UART board
  getResponse();
  getResponse();
  //Convert the string data to an integer
  //NOTE: RPM data is two bytes long, and delivered in 1/4 RPM from the OBD-II-UART
  vehicleRPM = ((strtol(&rxData[6],0,16)*256)+strtol(&rxData[9],0,16))/4;
  //Print the rpm data to the lcd
  lcd.print(vehicleRPM); 
  
  //Give the OBD bus a rest
  delay(100);
  
}

void getResponse(void){
  char inChar=0;
  //Keep reading characters until we get a carriage return
  while(inChar != '\r'){
    //If a character comes in on the serial port, we need to act on it.
    if(Serial.available() > 0){
      //Start by checking if we've received the end of message character ('\r').
      if(Serial.peek() == '\r'){
        //Clear the Serial buffer
        inChar=Serial.read();
        //Put the end of string character on our data string
        rxData[rxIndex]='\0';
        //Reset the buffer index so that the next character goes back at the beginning of the string.
        rxIndex=0;
      }
      //If we didn't get the end of message character, just add the new character to the string.
      else{
        //Get the new character from the Serial port.
        inChar = Serial.read();
        //Add the new character to the string, and increment the index variable.
        rxData[rxIndex++]=inChar;
      }
    }
  }
}