Pub

dimanche 14 février 2021

Mise à jour du programme BARO1-3 - new release for the simple but smart barometer

  Une nouvelle release - Valentine's Version  :-) - avec un  affichage par couleurs dont chacune représente cette fois une plage spécifique de valeurs de pression. Et toujours des clignotements verts ou bleus si la pression monte ou diminue, et un affichage en rouge et clignotements rouges en cas de chute rapide de la pression. Cette fois-ci, les clignotements sont des signaux morse visuels, U pour Up, D pour Down, W pour Warning.

A priori, ça devrait être l'avant-dernière pour ce projet, il reste encore un détail à régler pour éviter par moments des séries trop fréquentes Up et Down, vraisemblablement lorsque la valeur de la pression barométrique oscille légèrement autour d'une valeur entière et que la troncature de sa valeur la fait passer à + ou - 1 hPa. Il faudra donc mesurer la pression en dixième d'hecto-pascal et non plus seulement en valeur entière d'hecto-pascal. Mais là, tout-de-suite, je n'ai pas le temps...

Voici le code de la Valentine's Version :

/* Program name: BARO1-3-guyvano.ino
   Author: Guy Vanoverbeke @GuyVano
   Program last update (dd/mm/yyyy) : 14/02/2021 Valentine's Version (v.1 r.3 c.0)
   Arduino IDE V1.8.13
   Board: Arduino UNO R3
   Function: Using a BME280 sensor, display the range of barometric pressure and trend on a single RGB LED.
     Fixed purple: Barometric pressure(QNH) is lower or equal (<=) to 1000 hPa (hollow depression)
     Fixed indigo: 1001 <= QNH <= 1005 hPa 
     Fixed blue:   1006 <= QNH <= 1010 hPa 
     Fixed yellow: 1011 <= QNH <= 1015 hPa 
     Fixed green:  1016 <= QNH <= 1020 hPa 
     Fixed ice white: 1021 <= QNH
     Fixed Red + flashing Red each 30 seconds : barometric pressure fast falling warning (-3 hPa or more in the last 15 mn).
     Short green flashes each 30 seconds: barometric pressure has increased recently (in the last 15 minutes).
     Short blue flashes each 30 seconds: barometric pressure has decreased recently (in the last 15 minutes).
     If there is no variation for 15 minutes, the change and alert indicators are reset.
   Disclaimer:
   This program (in other words: this code, this software or this application) is a personal creation made as part of a hobby
   and it is given without guarantee of any kind and no support is provided. It is free of rights
   and can be reused freely as you wish.
*/

#include <Wire.h>
//
// I2C Temperature, humidity and barometric pressure sensor
//
#include <Adafruit_BME280.h>
Adafruit_BME280 bme;

//
//  Define the 3 pins of the RGB LED
//
const byte pblueled = 9;
const byte pgreenled = 10;
const byte predled = 11;
//
const int anticyc = 1013;  // define the Anticyclonic value
//
const int myaltitude = 186;  // altitude above sea level en meter
//
const boolean acnt = false; // true for serial monitor/debug
//
// variables
//

int qfe = 0; // Local barometric pressure
int dqfe = 0; // Local barometric pressure difference between 2 sensor reads cycle
int pqfe = 0; // Local barometric pressure of the previous read cycle
int qfesf = 0; // Local barometric pressure stored at the begining of the falling period
int qnh = 0;  // Barometric pressure calculated at sea level
int i = 0; // Loop control
boolean fqfeup = false; // flag mem qnh up
boolean fqfedown = false; // flag mem qnh down
boolean fqfewarn = false; // flag mem qnh fast down
byte blqfe = 0 ; // number of cycles before clearing flags mem qfe up or down
//

void setup()
{
  if (acnt) {
    Serial.begin(9600);
    Serial.println(" ");
    Serial.println("*******************************************************");
    Serial.println(" ");
    Serial.println("BARO1-3-guyvano restarted! Valentine's Version (v.1 r.3 c.0)");
  } else {};
  //
  //   Define pins modes
  //

  pinMode(predled, OUTPUT);
  pinMode(pgreenled, OUTPUT);
  pinMode(pblueled, OUTPUT);
  //
  // Sensor
  //

  bme.begin(0x76);    // address of the BME280 I2C sensor
  //
  // LED check
  //
  // Purple

  digitalWrite(predled, HIGH);
  digitalWrite(pgreenled, LOW);
  digitalWrite(pblueled, HIGH);
  delay(1000);
  // Indigo
  digitalWrite(predled, LOW);
  delay(1000);
  // Blue
  digitalWrite(pgreenled, HIGH);
  delay(1000);
  // Yellow
  digitalWrite(pblueled, LOW);
  digitalWrite(predled, HIGH);
  delay(1000);
  // Green
  digitalWrite(predled, LOW);
  delay(1000);
  // Ice white
  digitalWrite(predled, HIGH);
  digitalWrite(pblueled, HIGH); 
  delay(1000);
  digitalWrite(pblueled, LOW);
  digitalWrite(predled, LOW);
  digitalWrite(pgreenled, LOW);
  delay(1000);
  // R in morse (Ready!) ._.
  digitalWrite(pgreenled, HIGH);
  delay(150);
  digitalWrite(pgreenled, LOW);
  delay(200);
  digitalWrite(pgreenled, HIGH);
  delay(450);
  digitalWrite(pgreenled, LOW);
  delay(200);
  digitalWrite(pgreenled, HIGH);
  delay(150);
  digitalWrite(pgreenled, LOW);
  delay(1000);
  //
  qfe = bme.readPressure() / 100.0F;
  qnh = qfe + (myaltitude * 0.1205);
  pqfe = qfe;
}
void loop()
{
  qfe = bme.readPressure() / 100.0F;
  qnh = qfe + (myaltitude * 0.1205);
  dqfe = qfe - pqfe;
  //
  if ((dqfe > 0) & ~(fqfeup)) {
    blqfe = 30; // 30 corresponds to about 15 minutes for the short flashes periods, if delay at the end of loop is 30 seconds.
    fqfeup = true;
    fqfedown = false;
    fqfewarn = false;
  } else {};
  //
  if ((dqfe < 0) & ~(fqfedown)) {
    blqfe = 30; // 30 corresponds to about 15 minutes for the short flashes periods, if delay at the end of loop is 30 seconds.
    qfesf = qfe;
    fqfeup = false;
    fqfedown = true;
  } else {};
  //
  if ((qfesf - qfe) > 2 & (fqfedown)) {
    fqfewarn = true;
  }
  else {};
  //
  // QFE +/- flashing conditions
  //
  // UP (green flashing)
  //

  if ((fqfeup) & ~(fqfewarn)) {
    digitalWrite(pblueled, LOW);
    digitalWrite(predled, LOW);
    digitalWrite(pgreenled, LOW);
    delay(1000);
    for (i = 0; i < 5; i++ ) {
      // flash U in morse code ..-
      digitalWrite(pgreenled, HIGH);
      delay(150);
      digitalWrite(pgreenled, LOW);
      delay(200);
      digitalWrite(pgreenled, HIGH);
      delay(150);
      digitalWrite(pgreenled, LOW);
      delay(200);
      digitalWrite(pgreenled, HIGH);
      delay(450);
      digitalWrite(pgreenled, LOW);
      delay(1000);
    };
    blqfe = blqfe - 1;
  }
  else {};
  //
  // DOWN : Blue flashing
  //

  if ((fqfedown) & ~(fqfewarn)) {
    digitalWrite(pblueled, LOW);
    digitalWrite(pgreenled, LOW);
    digitalWrite(predled, LOW);
    delay(1000);
    for (i = 0; i < 5; i++ ) {
      // flash D in morse code -..
      digitalWrite(pblueled, HIGH);
      delay(450);
      digitalWrite(pblueled, LOW);
      delay(200);
      digitalWrite(pblueled, HIGH);
      delay(150);
      digitalWrite(pblueled, LOW);
      delay(200);
      digitalWrite(pblueled, HIGH);
      delay(150);
      digitalWrite(pblueled, LOW);
      delay(1000);
    };
    blqfe = blqfe - 1;
  }
  else {};
  //
  // FAST FALLING WARNING
  //

  if (fqfewarn) {
    digitalWrite(pblueled, LOW);
    digitalWrite(pgreenled, LOW);
    digitalWrite(predled, LOW);
    delay(1000);
    for (i = 0; i < 5; i++ ) {
      // flash W in morse code .--
      digitalWrite(predled, HIGH);
      delay(150);
      digitalWrite(predled, LOW);
      delay(200);
      digitalWrite(predled, HIGH);
      delay(450);
      digitalWrite(predled, LOW);
      delay(200);
      digitalWrite(predled, HIGH);
      delay(450);
      digitalWrite(predled, LOW);
      delay(1000);
    };
    blqfe = blqfe - 1;
  }
  else {};
  if (blqfe < 1) {
    fqfeup = false;
    fqfedown = false;
    fqfewarn = false;
  }
  else {};
  //
  //   Long light on conditions
  //
  // QNH <= 1000 : Purple
  //

  if (qnh <= 1000) {
    digitalWrite(predled, HIGH);
    digitalWrite(pblueled, HIGH);
    digitalWrite(pgreenled, LOW);
  }
  else {};
  //
  //  1001 <= QNH <= 1005 : Indigo
  //

  if ((1001 <= qnh) & (qnh <= 1005)) {
    digitalWrite(pblueled, HIGH);
    digitalWrite(predled, LOW);
    digitalWrite(pgreenled, LOW);
  } else {};
  //
  // 1006 <= QNH <= 1010 : Light Blue
  //

  if ((1006 <= qnh) & (qnh <= 1010)) {
    digitalWrite(pblueled, HIGH);
    digitalWrite(pgreenled, LOW);
    digitalWrite(predled, HIGH);
  } else {};
  //
  // 1011 <= QNH <= 1015 : Yellow
  //

  if ((1011 <= qnh) & (qnh <= 1015)) {
    digitalWrite(pblueled, LOW);
    digitalWrite(pgreenled, HIGH);
    digitalWrite(predled, HIGH);
  } else {};
  //
  // 1016 <= QNH <= 1020 : Green
  //

  if ((1016 <= qnh) & (qnh <= 1020)) {
    digitalWrite(pblueled, LOW);
    digitalWrite(pgreenled, HIGH);
    digitalWrite(predled, HIGH);
  } else {};
  //
  // 1021 <= QNH : Ice White
  //

  if (1021 <= qnh) {
    digitalWrite(pblueled, HIGH);
    digitalWrite(pgreenled, HIGH);
    digitalWrite(predled, HIGH);
  } else {};
  //
  // Warning : red (R)
  //

  if (fqfewarn) {
    digitalWrite(pblueled, LOW);
    digitalWrite(pgreenled, LOW);
    digitalWrite(predled, HIGH);
  } else {};
  //
  // serial control values
  //

  if (acnt) {
    Serial.println(" ");
    Serial.print("qnh:");
    Serial.print(qnh);
    Serial.print(", qfe:");
    Serial.print(qfe);
    Serial.print(", pqfe:");
    Serial.print(pqfe);
    Serial.print(", dqfe:");
    Serial.print(dqfe);
    Serial.print(", blqfe:");
    Serial.print(blqfe);
    Serial.print(", fqfeup:");
    Serial.print(fqfeup);
    Serial.print(", fqfedown:");
    Serial.print(fqfedown);
    Serial.print(", fqfewarn:");
    Serial.print(fqfewarn);
  } else {};
  //
  pqfe = qfe;
  //
  delay(30000);  // 30000 means 30 seconds to wait before a new cycle
}
// End of the program - Thanks for watching ! --...  ...--




*** Guy F8ABX - 14-15/02/2021 ***

Aucun commentaire:

Enregistrer un commentaire