une 30aine passés sans pb entre les trames

Dependencies:   ADS1015 ARNSRS_SENSORS DmTftLibrary MS5803_14BA SDFileSystem mbed

Fork of ARNSRS_SERVOS_USB_TFT by POTLESS

Committer:
POTLESS_2
Date:
Wed May 03 15:03:20 2017 +0000
Revision:
6:1c2212891714
Parent:
5:e1d0dc7940a6
Child:
7:c5a5d8f678ff
bricoles....

Who changed what in which revision?

UserRevisionLine numberNew contents of line
potless 1:bef7856b5c0a 1 /* procédure lecture capteur COZIR ou MINIR - CO2 seul
potless 1:bef7856b5c0a 2 sur broches F401RE SERIAL PA_11 et PA_12
potless 1:bef7856b5c0a 3 renvoie sur moniteur (IDE arduino par exemple) de la valeur lue
potless 2:4a8bf1d53439 4
potless 2:4a8bf1d53439 5 procédures possibles sont :
potless 2:4a8bf1d53439 6 request (char commande) - renvoie la valeur lue si la commande ne représente qu'un seul caractère (entre '')
potless 2:4a8bf1d53439 7 cozirSend (string commande) - permet d'envoyer des commandes multicaractères (entre "") - exemple A 32 - donne la réponse obtenue
potless 2:4a8bf1d53439 8
potless 2:4a8bf1d53439 9
potless 2:4a8bf1d53439 10 la fonction cozirSend est davantage "sécurisée"
POTLESS_2 4:d84250f67dec 11 */
potless 0:69d4b21d58e0 12
potless 0:69d4b21d58e0 13
potless 1:bef7856b5c0a 14 #include "mbed.h"
POTLESS_2 5:e1d0dc7940a6 15 #include "SDFileSystem.h"
POTLESS_2 5:e1d0dc7940a6 16 #include "ARNSRS_SENSORS.h"
POTLESS_2 5:e1d0dc7940a6 17
POTLESS_2 5:e1d0dc7940a6 18 //Init de la lib ARNSRS;
POTLESS_2 5:e1d0dc7940a6 19 ARNSRS arnsrs;
POTLESS_2 5:e1d0dc7940a6 20
POTLESS_2 5:e1d0dc7940a6 21 //Bouton et led de la carte
POTLESS_2 5:e1d0dc7940a6 22 DigitalIn mybutton(USER_BUTTON);
POTLESS_2 5:e1d0dc7940a6 23 DigitalOut myled(LED1);
POTLESS_2 4:d84250f67dec 24
POTLESS_2 5:e1d0dc7940a6 25 //RTC
POTLESS_2 5:e1d0dc7940a6 26 time_t seconds;
POTLESS_2 5:e1d0dc7940a6 27
POTLESS_2 5:e1d0dc7940a6 28 //Quelque FLAG...
POTLESS_2 5:e1d0dc7940a6 29 bool FLAG_SIMPLE_TIME = false;
potless 1:bef7856b5c0a 30
POTLESS_2 4:d84250f67dec 31 //COM Série
POTLESS_2 6:1c2212891714 32 Serial serialMonit (USBTX,USBRX); //Serial 2
potless 2:4a8bf1d53439 33
POTLESS_2 5:e1d0dc7940a6 34 //Variable des capteurs
POTLESS_2 5:e1d0dc7940a6 35 int co2, ppO2;
POTLESS_2 5:e1d0dc7940a6 36 float pression, Temp1, Temp2, Humi;
POTLESS_2 5:e1d0dc7940a6 37 string DateHeure;
potless 2:4a8bf1d53439 38
POTLESS_2 6:1c2212891714 39 //SD card
POTLESS_2 6:1c2212891714 40 SDFileSystem sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCK, CS
POTLESS_2 6:1c2212891714 41 FILE *fp;
POTLESS_2 4:d84250f67dec 42
potless 2:4a8bf1d53439 43 ///////////////////////////////////
potless 2:4a8bf1d53439 44 // fonction initialisation /////
potless 2:4a8bf1d53439 45 ///////////////////////////////////
POTLESS_2 4:d84250f67dec 46 void setup()
POTLESS_2 4:d84250f67dec 47 {
POTLESS_2 5:e1d0dc7940a6 48 //RTC
POTLESS_2 5:e1d0dc7940a6 49 seconds = time(NULL);
POTLESS_2 5:e1d0dc7940a6 50 DateHeure = ctime(&seconds);
potless 2:4a8bf1d53439 51
POTLESS_2 6:1c2212891714 52 arnsrs.Sensors_INIT(5, SPOOLING, DIGI_FILTER32, CALIB_AIR);
POTLESS_2 4:d84250f67dec 53
potless 0:69d4b21d58e0 54 }
potless 0:69d4b21d58e0 55
potless 1:bef7856b5c0a 56 /////////////////////////////////////
potless 1:bef7856b5c0a 57 /// procédure principale /////////
potless 1:bef7856b5c0a 58 /////////////////////////////////////
potless 0:69d4b21d58e0 59
POTLESS_2 4:d84250f67dec 60 int main()
POTLESS_2 4:d84250f67dec 61 {
POTLESS_2 5:e1d0dc7940a6 62 wait(2);
POTLESS_2 5:e1d0dc7940a6 63
POTLESS_2 5:e1d0dc7940a6 64 serialMonit.printf("Initialisation SD card\r\n");
POTLESS_2 5:e1d0dc7940a6 65 fp = fopen("/sd/Capteurs.txt", "r");
POTLESS_2 5:e1d0dc7940a6 66 if (fp != NULL) {
POTLESS_2 5:e1d0dc7940a6 67 fclose(fp);
POTLESS_2 5:e1d0dc7940a6 68 remove("/sd/Capteurs.txt");
POTLESS_2 5:e1d0dc7940a6 69 serialMonit.printf("Suppression d'un fichier du meme nom\r\n");
POTLESS_2 5:e1d0dc7940a6 70 }
POTLESS_2 5:e1d0dc7940a6 71
POTLESS_2 5:e1d0dc7940a6 72 fp = fopen("/sd/Capteurs.txt", "w");
POTLESS_2 5:e1d0dc7940a6 73 if (fp == NULL) {
POTLESS_2 5:e1d0dc7940a6 74 serialMonit.printf("Impossible d'ouvrir le fichier LOG\r\n");
POTLESS_2 5:e1d0dc7940a6 75 } else {
POTLESS_2 5:e1d0dc7940a6 76 fprintf(fp, "LOG Capteurs ARNSRS");
POTLESS_2 5:e1d0dc7940a6 77 fclose(fp);
POTLESS_2 5:e1d0dc7940a6 78 serialMonit.printf("Header du fichier cree\r\n");
POTLESS_2 5:e1d0dc7940a6 79 }
POTLESS_2 5:e1d0dc7940a6 80
POTLESS_2 5:e1d0dc7940a6 81 setup(); //initialisation
potless 2:4a8bf1d53439 82
POTLESS_2 4:d84250f67dec 83 while (1) {
POTLESS_2 5:e1d0dc7940a6 84
POTLESS_2 6:1c2212891714 85 wait(2);
POTLESS_2 6:1c2212891714 86
POTLESS_2 5:e1d0dc7940a6 87 //RTC
POTLESS_2 5:e1d0dc7940a6 88 seconds = time(NULL);
POTLESS_2 5:e1d0dc7940a6 89
POTLESS_2 5:e1d0dc7940a6 90 if (!FLAG_SIMPLE_TIME){
POTLESS_2 5:e1d0dc7940a6 91 DateHeure = ctime(&seconds);
POTLESS_2 5:e1d0dc7940a6 92 printf(" Date / Heure = %s\r\n", DateHeure);
POTLESS_2 5:e1d0dc7940a6 93 }else{
POTLESS_2 5:e1d0dc7940a6 94 char buffer[32];
POTLESS_2 5:e1d0dc7940a6 95 strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
POTLESS_2 5:e1d0dc7940a6 96 printf(" Heure = %s", buffer);
POTLESS_2 5:e1d0dc7940a6 97 }
POTLESS_2 5:e1d0dc7940a6 98
POTLESS_2 4:d84250f67dec 99 //CO2 / H / T sur Cozir
POTLESS_2 6:1c2212891714 100 co2 = arnsrs.requestCO2();
POTLESS_2 6:1c2212891714 101 Humi = arnsrs.requestHUMI();
POTLESS_2 6:1c2212891714 102 Temp1 = arnsrs.requestTEMP();
POTLESS_2 5:e1d0dc7940a6 103
POTLESS_2 6:1c2212891714 104 //P / T sur MS5803_14BA
POTLESS_2 5:e1d0dc7940a6 105 pression = arnsrs.requestPress();
POTLESS_2 5:e1d0dc7940a6 106 Temp2 = arnsrs.requestTemp();
POTLESS_2 5:e1d0dc7940a6 107
POTLESS_2 5:e1d0dc7940a6 108 //PPO2 sur ADS1015
POTLESS_2 5:e1d0dc7940a6 109 ppO2 = arnsrs.requestPpO2();
POTLESS_2 5:e1d0dc7940a6 110
POTLESS_2 5:e1d0dc7940a6 111 //Affichage sur moniteur série
POTLESS_2 6:1c2212891714 112 serialMonit.printf(" Co2 = %d\r\n" , co2);
POTLESS_2 6:1c2212891714 113 serialMonit.printf(" Humidité = %f\r\n" , Humi);
POTLESS_2 6:1c2212891714 114 serialMonit.printf(" Temperature = %f\r\n" ,Temp1);
POTLESS_2 4:d84250f67dec 115 //P / T sur MS5803
POTLESS_2 6:1c2212891714 116 serialMonit.printf(" Pression = %f\r\n", pression);
POTLESS_2 6:1c2212891714 117 serialMonit.printf(" Temperature = %f\r\n", Temp2);
POTLESS_2 4:d84250f67dec 118 //PPO2 sur ADS1015
POTLESS_2 6:1c2212891714 119 serialMonit.printf(" PPO2 = %d\r\n", ppO2);
POTLESS_2 5:e1d0dc7940a6 120 serialMonit.printf("\r\n", "");
POTLESS_2 5:e1d0dc7940a6 121
POTLESS_2 5:e1d0dc7940a6 122 if (mybutton == 0) { // Button is pressed
POTLESS_2 5:e1d0dc7940a6 123 myled = !myled; // Toggle the LED state
POTLESS_2 5:e1d0dc7940a6 124 FLAG_SIMPLE_TIME = !FLAG_SIMPLE_TIME;
POTLESS_2 5:e1d0dc7940a6 125 wait(0.2); // 200 ms
POTLESS_2 5:e1d0dc7940a6 126 }
POTLESS_2 4:d84250f67dec 127 }
POTLESS_2 4:d84250f67dec 128 }