/* Programme simple pour tester le capteur de CO2 SenseAirS8 et afficher les données sur un M5StickC ou M5M5StickCPlus. Des adpatations seront à faire pour la visualisation des textes affichés à chaque ligne comprenant M5.Lcd.setCursor....... */ /************************* Import bibliothèque *************************************************/ #include //#include //Bibliotheque M5SticC Plus #include // import de la bibliothèque Air Gradient /****************************** Configuration du capteur Sensair-S8 *******************************************/ AirGradient ag = AirGradient(); // Création de l'objet ag String co2_val; /****************************** SETUP *******************************************/ void setup() { Serial.begin(9600); //Démarrage de la liaison série M5.begin(); // Démarrage du M5Stick M5.Lcd.setRotation (1); ag.CO2_Init(36, 26, 9600); // démarrage et initialisation de l'objet } /****************************** LOOP *******************************************/ void loop() { int CO2 = ag.getCO2_Raw(); // mesure brute du CO2 Serial.print("C02: "); co2_val = ag.getCO2(); Serial.println(co2_val); // Affichage du CO2 en ppm dans la console affiche_CO2(co2_val); // Fonction affichage de la valeur mesurée et modifications des paramètres écran calibration(); // Fonction calibrage delay(5000); // attente de 5 secondes (temps de mesure du capteur 2s) } /******* Modification message + couleur écran M5Stick-C en fonction de la valeur CO2 ***********/ void affiche_CO2(String val) { if (val.toInt() < 800) { M5.Lcd.fillScreen(GREEN); M5.Lcd.setTextColor(BLACK); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(40, 10); M5.Lcd.print("Excellent"); M5.Lcd.setCursor(20, 40); M5.Lcd.print(val + " ppm"); } if (val.toInt() >= 800 && val.toInt() < 1000) { M5.Lcd.fillScreen(0xFFE0); // jaune M5.Lcd.setTextColor(BLACK); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(40, 10); M5.Lcd.print("Moyen" ); M5.Lcd.setCursor(20, 40); M5.Lcd.print(val + " ppm"); } if (val.toInt() >= 1000 && val.toInt() < 1500) { M5.Lcd.fillScreen(0xFDA0); // orange M5.Lcd.setTextColor(BLACK); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(40, 10); M5.Lcd.print("Mediocre "); M5.Lcd.setCursor(20, 40); M5.Lcd.print(val + " ppm"); } if (val.toInt() >= 1500) { M5.Lcd.fillScreen(RED); M5.Lcd.setTextColor(BLACK); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(2, 10); M5.Lcd.print("Vicie "); M5.Lcd.setCursor(20, 40); M5.Lcd.print(val + " ppm"); } } /******* Calibration Capteur CO2 ***********/ void calibration() { pinMode(37, INPUT); pinMode(0, OUTPUT); digitalWrite(0, HIGH); boolean cur_value = digitalRead(37); while (!cur_value) { cur_value = digitalRead(37); M5.Lcd.fillScreen(BLACK); M5.Lcd.setTextColor(WHITE); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(2, 10); M5.Lcd.print("Calibration"); digitalWrite(0, LOW); } }