Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.65 KB | None | 0 0
  1. #include
  2. #include
  3. #include
  4. #include
  5. //#include
  6. #define SDA_PIN 8
  7. #define SCL_PIN 9
  8. //Adafruit_ssd1306syp display(SDA_PIN,SCL_PIN);
  9. #define U8glib display(SDA_PIN,SCL_PIN);
  10. #define DS18B20 0x28
  11.  
  12. OneWire ds(10);
  13.  
  14. // Création du gps via la librairie TinyGPSPlus
  15. TinyGPS gps;
  16.  
  17. // Connexion série pour le GPS
  18. SoftwareSerial gps_serial(6, 0); // Port choisi sur Arduino UNO, le TX ne nous interesse pas
  19.  
  20. int maxspeed=0;
  21. int verif=0;
  22. double heureDepart=0.0;
  23. double coordDepartLat=0.0;
  24. double coordDepartLng=0.0;
  25. char avg_final[20];
  26.  
  27. /************************ CAPTEUR TEMPERATURE *************************/
  28. boolean getTemperature(int *temp){
  29. byte data[9], addr[8]; // data : Données lues depuis le scratchpad || addr : adresse du module 1-Wire détecté
  30.  
  31. if (!ds.search(addr)) { // Recherche un module 1-Wire
  32. ds.reset_search(); // Réinitialise la recherche de module
  33. return false; // Retourne une erreur
  34. }
  35.  
  36. if (OneWire::crc8(addr, 7) != addr[7]) // Vérifie que l’adresse a été correctement reçue
  37. return false; // Si le message est corrompu on retourne une erreur
  38.  
  39. if (addr[0] != DS18B20) // Vérifie qu’il s’agit bien d’un DS18B20
  40. return false; // Si ce n’est pas le cas on retourne une erreur
  41.  
  42. ds.reset(); // On reset le bus 1-Wire
  43. ds.select(addr); // On sélectionne le DS18B20
  44.  
  45. ds.write(0x44, 1); // On lance une prise de mesure de température
  46.  
  47. ds.reset(); // On reset le bus 1-Wire
  48. ds.select(addr); // On sélectionne le DS18B20
  49. ds.write(0xBE); // On envoie une demande de lecture du scratchpad
  50.  
  51. for (byte i = 0; i < 9; i++) // On lit le scratchpad
  52. data[i] = ds.read(); // Et on stock les octets reçus
  53.  
  54. // Calcul de la température en degré Celsius
  55. *temp = ((data[1] < 0){
  56. /************************ INITIALISATION DES VARIABLES POUR LA MOYENNE (coordoonnées et heure du départ) *************************/
  57. if(verif==0){
  58. heureDepart=(gps.time.hour()+1)+(gps.time.minute()/60.0);
  59. coordDepartLat=gps.location.lat();
  60. coordDepartLng=gps.location.lng();
  61. if(gps.location.isValid()){ // Permet d’incrémenter la variable verif afin de faire la boucle précedente une seule fois
  62. verif++;
  63. }
  64. }
  65. /************************ FIN INITIALISATION DES VARIABLES POUR LA MOYENNE (coordoonnées et heure du départ) *************************/
  66. if (gps.encode(gps_serial.read())) displayInfo(&maxspeed);
  67. }
  68.  
  69. if (millis() > 5000 && gps.charsProcessed() < 10)
  70. {
  71. Serial.println(F("No GPS detected: check wiring."));
  72. while(true);
  73. }
  74. }
  75.  
  76. void displayInfo(int *maxspeed)
  77. {
  78. int temp;
  79. int vitesse=gps.speed.kmph();
  80. Serial.print(F("Localisation: "));
  81. if (gps.location.isValid())
  82. {
  83. if(getTemperature(&temp)){ // Si le capteur de température est bien connecté (permet l'affichage de toutes les infos sur l'écran sans clignotements)
  84. Serial.print(gps.location.lat(), 6);
  85. Serial.print(F(","));
  86. Serial.print(gps.location.lng(), 6);
  87. Serial.print(F(","));
  88. Serial.println(gps.speed.kmph(), 6);
  89. Serial.print(F("Vitesse: "));
  90. Serial.print(gps.speed.kmph());
  91.  
  92. display.update();
  93. display.clear();
  94. display.setTextSize(2);
  95. display.setTextColor(WHITE);
  96. display.setCursor(30,25);
  97.  
  98. /********* AFFICHAGE VITESSE *********/
  99. display.print(vitesse);
  100. display.print("km/h");
  101. /********* FIN AFFICHAGE VITESSE *********/
  102.  
  103. /********* AFFICHAGE TEMP *********/
  104. display.setTextSize(1);
  105. display.setCursor(108,0);
  106. display.print(temp);
  107. display.print('C');
  108. /********* FIN AFFICHAGE TEMP *********/
  109.  
  110. /********* AFFICHAGE MAX *********/
  111. if(*maxspeed<gps.speed.kmph())*maxspeed=gps.speed.kmph();
  112. display.setCursor(0,55);
  113. display.print(*maxspeed);
  114. display.print("km/h");
  115. /********* FIN AFFICHAGE MAX *********/
  116.  
  117. /********* AFFICHAGE SAT *********/
  118. display.setCursor(60,55);
  119. display.print(gps.satellites.value());
  120. /********* FIN AFFICHAGE SAT *********/
  121.  
  122. const double ceri_LAT = 43.909712;
  123. const double ceri_LONG = 4.889542;
  124. double distanceKm = TinyGPSPlus::distanceBetween(gps.location.lat(),gps.location.lng(),ceri_LAT,ceri_LONG) / 1000.0;
  125. double courseTo = TinyGPSPlus::courseTo(gps.location.lat(),gps.location.lng(),ceri_LAT,ceri_LONG);
  126.  
  127. /********* AFFICHAGE DISTANCE *********/
  128. display.setCursor(80,57);
  129. display.print(distanceKm);
  130. display.print("km");
  131. /********* FIN AFFICHAGE DISTANCE *********/
  132.  
  133. /********* AFFICHAGE AVG *********/
  134. double heure=(gps.time.hour()+1)+(gps.time.minute()/60.0);
  135. double coordLat=gps.location.lat();
  136. double coordLng=gps.location.lng();
  137. double temps=heure-heureDepart;
  138. double distance=TinyGPSPlus::distanceBetween(coordDepartLat,coordDepartLng,coordLat,coordLng) / 1000.0;
  139. double avg=distance/temps;
  140.  
  141. avg=floor(avg*10)/10; //Permet d'arrondir a 0.0
  142. dtostrf(avg, 5, 1, avg_final); // au lieu de 0.00
  143.  
  144. display.setTextSize(1);
  145. display.setTextColor(WHITE);
  146. display.setCursor(-10,45);z
  147. display.print(avg_final);
  148. display.print("km/h");
  149. /********* FIN AFFICHAGE AVG *********/
  150. }
  151. }
  152. else
  153. {
  154. Serial.print(F("INVALID"));
  155. display.update();
  156. display.clear();
  157. display.setTextSize(2);
  158. display.setTextColor(WHITE);
  159. display.setCursor(0,25);
  160. display.print("GPS en cours de fix…");
  161. }
  162.  
  163. Serial.print(F(" "));
  164. if (gps.time.isValid())
  165. {
  166. /********* AFFICHAGE HEURE *********/
  167. display.setTextSize(1);
  168. display.setTextColor(WHITE);
  169. display.setCursor(0,0);
  170. if (gps.time.hour() < 9) display.print("0");
  171. display.print(gps.time.hour()+1);
  172. display.print(":");
  173. if (gps.time.minute() < 9) display.print("0");
  174. display.print(gps.time.minute());
  175. /********* FIN AFFICHAGE HEURE *********/
  176.  
  177. }
  178. else
  179. {
  180. Serial.print(F("INVALID"));
  181. display.update(); // " la ligne qui me pose problème pour le moment"
  182. display.clear();
  183. display.setTextSize(2);
  184. display.setTextColor(WHITE);
  185. display.setCursor(0,25);
  186. display.print("GPS en cours de fix…");
  187. }
  188. Serial.println();
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement