Bonjour à tous !
Le fais appel à vous pour tenter de résoudre mon problème...
Je possède une Pontiac Firebird de 1994, sur laquelle j'essaye de récupérer, via le port ODB1, la vitesse et le nombre de tours par minutes avec un arduino uno, pour afficher le tout sur un écran LCD.
Je précise de de 1986 à 1995, on pouvait communiquer avec les véhicules via un format développé par General Motors. Pas de chance pour moi, l'ODB2 est arrivée deux ans plus tard....
Grace à l'aide d'un américain, j'ai réussi à récupérer les données avec un programme en Visual basic.
Je souhaite désormais pouvoir reproduire cela sur un arduino.
Après avoir écumé le net, j'ai trouvé et adapté un projet correspondant parfaitement à ce que je veux.
J'ai réalisé une version de test, mais ormis la liaison série qui semble s'établir, je ne parviens pas à communiquer avec l'ECU de ma voiture...
Le projet d'origine est ici : http://www.xm381.com/xm381/aldl.html
J'ai réalisé le câblage suivant : http://www.xm381.com/xm381/aldl_files/ALDL_Communication_1.png
La seule différence est que l'arduino est allimenté via un adaptateur usb branché sur l'allume cigare de la voiture.
La doc technique de l'ALDL est ici : http://www.xm381.com/xm381/aldl_files/ALDL%20DataStreams.zip (Pour mon type de véhicule, c'est la A257)
Je joins une copie de mon code à ce post.
Débutant dans la prog, j'implore votre indulgence sur la qualité de mon code
Un grand merci pour votre aide !
Nitrix
//
// FIREBIRD_9495_ALDL - Version Alpha 2.0
// PARAMETRE DE L'AFFICHEUR LCD
#include <UTFT.h> // Lirairie de gestionLCD
UTFT myGLCD(ITDB18SP,9,10,11,7,8); // Parametrega LCD 128x160px
extern uint8_t SmallFont[]; // Parametrage de la police
//extern uint8_t BigFont[]; // Parametrage de la police
// PARAMETRE DE CONFIGURATION DE LA COMMUNICATION AVEC L'ECU
// MODE 1 (TRANSMIT FIXED DATA STREAM) MESSAGE 0
const byte Mode1Request[] = { 0xE4, 0x57, 0x01, 0x00 }; // Mode 1 Request byte string
const byte Mode1Header[] = { 0xE4, 0x99, 0x01 }; // This is the header returned with the ALDL data
//const byte Mode1DataBytes = 63; // This is the number of data bytes returned (not including the header)
const byte Mode1DataBytes = 67; // This is the number of data bytes returned (not including the header)
// Dans le DATA STREAM A257, le Mode1DataBytes est a 67. On laisse a 63 mais si bug, le passer a 67.
// Parametrage des BYTES
// Dans cette version alpha, on ne prend que la Vitesse en miles (MPH), Les tours par minutes (RPM), Le voltage de la batterie (BAT)
// Status Bytes: ValueName = byte position in ALDLStream
// must offset location in ALDLStreamBuffer, offset = Mode1RequestSize + Mode1HeaderSize
const byte BAT = 4; // (BATTERY VOLTAGE, VOLTS = N/10)
const byte MPH = 11; // (FILTERED MILES PER HOUR)
const byte RPM = 14; // *25 (ENGINE RPM)
// CONFIGURATION DU HARDWARE
// ALDL
#define ALDLSerial Serial // Initialisation de la communication serie
// ***** Variables for ALDL data *****
const byte Mode1RequestSize = sizeof(Mode1Request)/sizeof(Mode1Request[0]); // Calculate how many bytes long is the Mode 1 request string.
const byte Mode1HeaderSize = sizeof(Mode1Header)/sizeof(Mode1Header[0]); // Calculate how many bytes long is the Mode 1 header string.
const byte ALDLStreamSize = (Mode1RequestSize + 1 + Mode1HeaderSize + Mode1DataBytes + 1); // # of Request bytes + checksum byte + header bytes + data bytes + checksum byte
byte offset = Mode1RequestSize + Mode1HeaderSize; //starting location of ALDL in buffer (after request and header data)
byte ALDLStream[ALDLStreamSize]; // Array for verified ALDL data
byte ALDLStreamBuffer[ALDLStreamSize]; // Array to store ALDL for verification
byte checkSum;
byte Mode1RequestcheckSumByte; // Checksum of Mode 1 bytes
byte ALDLValidity;
unsigned long timeout;
// PARAMETRAGE DU PROGRAMME
void setup() {
// initialisation de l'ecran
InitScreen(); // Initialisation de l'ecran LCD
ALDLSerial.begin(8192); // Initialisation de la communication serie
// ***** Mode 1 checksum calculation *****
checkSum = 0;
for (byte Requestbytes=0; Requestbytes < Mode1RequestSize - 1; Requestbytes++) {
checkSum += Mode1Request[Requestbytes];
}
Mode1RequestcheckSumByte = 0 - checkSum;
}
// BOUCLE PRINCIPALE
void loop() {
myGLCD.setFont(SmallFont); // initialisation de la police de caractere
myGLCD.setColor( 255 , 255 , 255 ); // BLANC
// request mode 1
beginMode1();
// get ALDL data
getALDLStream();
// Verify ALDLStream
VerifyALDLStream();
}
void InitScreen() {
//myGLCD.setColor(B,G,R);
myGLCD.InitLCD(); // initialisation de l'ecran LCD
myGLCD.clrScr(); // Effacement de l'ecran LCD
myGLCD.setFont(SmallFont); // initialisation de la police de caractere
}
// ALDL: INITIALISATION DU MODE 1
void beginMode1() {
//myGLCD.print("BeginMode1 :", 1, 0);
while(ALDLSerial.available() != 0){ // empty serial buffer
byte bitbucket = ALDLSerial.read();
}
myGLCD.print("#", 1, 0);
myGLCD.print(" ALDLSerial1:" + String(ALDLSerial.available()), 1, 0);
for(byte bytesRead = 0; bytesRead <= Mode1RequestSize - 1; bytesRead++) { // send request
ALDLSerial.write (Mode1Request[bytesRead]);
myGLCD.print("#", 1, 15);
myGLCD.print(" bytesRead:" + String(bytesRead), 1, 15);
myGLCD.print("#", 1, 30);
myGLCD.print(" ReqSize:" + String(Mode1RequestSize - 1), 1, 30);
}
myGLCD.print("#", 1, 45);
myGLCD.print(" ReqchkSumByte:" + String(Mode1RequestcheckSumByte), 1, 45);
ALDLSerial.write (Mode1RequestcheckSumByte); // send checksum
}
// ALDL: RECUPURATION DU FLUX DE DONNEES
void getALDLStream() {
for (byte Clearbytes=0; Clearbytes < ALDLStreamSize; Clearbytes++) { // empty ALDL Stream array
ALDLStream[Clearbytes] = 0x00;
myGLCD.print("#", 1, 60);
myGLCD.print(" ALDLStream:" + String(ALDLStreamSize), 1, 60);
}
for (byte Clearbytes=0; Clearbytes < ALDLStreamSize; Clearbytes++) { // empty ALDL Stream Buffer array
ALDLStreamBuffer[Clearbytes] = 0x00;
myGLCD.print("#", 1, 75);
myGLCD.print(" ALDLStrBuff:" + String(ALDLStreamBuffer[Clearbytes]), 1, 75);
}
byte bytesRead = 0;
timeout = millis();
while((millis() - timeout) < 100){
if (ALDLSerial.available())
{ // retrieve ALDL response data from ECU in buffer, if any
byte dataByte = ALDLSerial.read();
ALDLStreamBuffer[bytesRead] = dataByte;
// BluetoothSerial.write (dataByte);
bytesRead++;
myGLCD.print("#", 1, 90);
myGLCD.print(" ALDLSerial:Yes " + String(ALDLStreamBuffer[bytesRead]), 1, 90);
}else{
myGLCD.print("#", 1, 90);
myGLCD.print(" ALDLSerial:No ", 1, 90);
}
if(bytesRead >= ALDLStreamSize){
break;
}
}
}
// ALDL: CONTROLE DES DONNEES
// Total Of Mode1Request + checksum + header + ALDL data + checksum byte must be equal to 0
void VerifyALDLStream(){
// check header string in ALDL data stream: does it match Mode1Header string
byte Mode1HeadercheckSum=0;
checkSum=0;
for (byte Requestbytes=0; Requestbytes < Mode1HeaderSize; Requestbytes++) {
Mode1HeadercheckSum += Mode1Header[Requestbytes];
checkSum += ALDLStreamBuffer[Requestbytes + Mode1RequestSize + 1];
myGLCD.print("#", 1, 105);
myGLCD.print(" Check Stream :"+ String(Requestbytes), 1, 105);
// delay(1000);
}
if (Mode1HeadercheckSum != checkSum) {
ALDLValidity = 2;
myGLCD.print("#", 1, 105);
myGLCD.print(" Check Stream : 2", 1, 105);
return;
}
// check ALDL data stream: header + ALDL data + checksum byte should equal 0
checkSum=0;
for (byte Requestbytes=0; Requestbytes < ALDLStreamSize - (Mode1RequestSize + 1); Requestbytes++) {
checkSum += ALDLStreamBuffer[Requestbytes + (Mode1RequestSize + 1)];
}
if (checkSum != 0) {
ALDLValidity = 1;
myGLCD.print("#", 1, 105);
myGLCD.print(" checkSum : 1 ", 1, 105);
return;
}
if (checkSum == 0) {
ALDLValidity = 0;
myGLCD.print("#", 1, 105);
myGLCD.print(" checkSum : 0 ", 1, 105);
for(byte bytesRead = 0; bytesRead < ALDLStreamSize ; bytesRead++){
ALDLStream[bytesRead] = ALDLStreamBuffer[bytesRead]; // transfer good data to ALDLStream
}
}
}
FIREBIRD_9495_ALDL_8192-alpha2.ino (7.06 KB)
A257.txt (62.1 KB)