Lecture d'une trame avec ARDUINO

Bonjour,

Je possède un PARTISOL que j'ai relié en RS232 -> TTL vers une ARDUINO MEGA2560.

La machine m'envoie une trame de 8 bits toutes les trois secondes sur le terminal de mon ARDUINO, cette trame est la suivante :

23/12/2015,08:57:06,3,0,4,0,5,0

Lorsque la machine rencontre un problème sa trame change :

23/12/2015,08:57:06,3,0,4,0,5,1012

C'est donc le dernier paramètre qui est modifié, j'ai donc plusieurs questions :

  1. Lorsque je reçois une trame de 8bits de mon partisol, j'ai un bit de départ, un bit de parité et un bit de stop et le reste en donnée ?

  2. Comment récupérer cette dernière valeur pour la comparer à 0 ? Car lorsque je veux utiliser un tableau, le tableau au lieu de prendre paramètre par paramètre me prend toute la trame à chaque incrémentation.

Merci pour votre futur aide.

Bonjour,

Si ça peux te donner une piste, je récupéré des trame de sonde de temperature avec ce code :

// Funksensor TFA, 433 MHz Temperatur-Außensender TFA 30.3120.90  not compatible with receiver 30.3034.01 
// read and decode temperature.  44 bits alltogather  
// 12 bits device type 111101011111 
// 7 bits device ID changes every time batteries inserted
// 1 bit  checksum is one if bit sum in first 3 digits is even
// 4 bits inverted tens. Subtract 5 to get degrees. 4 bits inverted ones. 4 bits inverted decimal parts
// 4 bits invertedtens again. 4 bits invertedones again. 4 bits inverted tens. We don’t use this.  
byte pin = 13; // from receiver. Between receiver and Arduino is 2 transistor 3V to TTL voltage converter 
byte ar[116], pos=0; unsigned long dur; //array, position in array, pulse duration
int b, d, t;         
void setup() { pinMode(pin, INPUT);  Serial.begin(9600); Serial.flush(); }  
void loop() { b: pos=0; 
// 1111 01 011111 device type other temp sensor TFA 30.3120.90 
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++;
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++;
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++;
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++;
dur = pulseIn(pin, HIGH); if ((dur>400)&&(dur<700)) {ar[pos] = 0; pos++; 
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++;
dur = pulseIn(pin, HIGH); if ((dur>400)&&(dur<700)) {ar[pos] = 0; pos++; 
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++; 
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++; 
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++; 
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++; 
dur = pulseIn(pin, HIGH); if ((dur>1100)&&(dur<1500)) {ar[pos] = 1; pos++; 
}else goto b;
}else goto b; 
}else goto b; 
}else goto b; 
}else goto b; 
}else goto b; 
}else goto b; 
}else goto b; 
}else goto b; 
}else goto b; 
}else goto b; 
}else goto b; 
//  Serial.print("data "); // if one gets to this point then message is most probably correct  
 for (int i=1; i <= 32; i++){ 
   dur = pulseIn(pin, HIGH);   
 if ((dur>400)&&(dur<700)){ar[pos] = 0; pos++; /* Serial.print("0"); */ } 
 if ((dur>1100)&&(dur<1500)){ar[pos] = 1; pos++;/*  Serial.print("1"); */}
 /* if (i==7) { Serial.print(" "); }  
 if (i==8) { Serial.print(" "); }  
 if (i==12) { Serial.print(" "); } 
 if (i==16) { Serial.print(" "); } 
 if (i==20) { Serial.print(" "); } 
 if (i==24) { Serial.print(" "); } 
 if (i==28) { Serial.print(" "); } 
 if (i==32) { Serial.print(" "); } */
 }  

// Serial.print("databegin TFA2 ");  
 d=0; for (int i=0; i <= 6; i++) {/*if (ar[12+i]==1) Serial.print("1"); if (ar[11+i]==0) Serial.print("0");*/
 d=d << 1; d=d+ar[12+i]; } // Serial.print(d); Serial.print(" "); // Device ID  

  d=0; for (int i=0; i <= 3; i++) {d=d << 1; if (ar[20+i]==1) b=0; else b=1; d=d+b;} d=d-5; t=d*100; // tens of degrees  
  d=0; for (int i=0; i <= 3; i++) {d=d << 1; if (ar[24+i]==1) b=0; else b=1; d=d+b;} t=t+10*d; // ones of degrees 
  d=0; for (int i=0; i <= 3; i++) {d=d << 1; if (ar[28+i]==1) b=0; else b=1; d=d+b;} t=t+d;  // decimal parts of degrees
  t=t/10;
  Serial.print(t);  
  Serial.print(".");
  Serial.println(d);
  d=ar[19]; for (int i=0; i <= 11; i++) {if (ar[20+i]==1) d=d+1;} 
  // Serial.println(d);  
 // if ( (d % 2) == 0) Serial.println(" CRCerror"); else Serial.println(" CRCok"); 
  }