Une nouvelle mise à jour avec une bonne amélioration pour déterminer la tendance.
Je pense que là, le p'tit baro est un petit moins bête. Reste à lui apprendre à faire des prévisions, peut-être dans une prochaine version.
Voici le code :
/* Program name: BARO1-4-guyvano.ino
Author: Guy Vanoverbeke @GuyVano
Program last update (dd/mm/yyyy) : 15/02/2021 - V.1 R.4 C.0 "Desired Daisy"
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 (at least -0.5 hPa in the last 15 mn).
Short green flashes each 30 seconds: barometric pressure has increased recently (at least +0.2 hPa in the last 15 minutes).
Short blue flashes each 30 seconds: barometric pressure has decreased recently (at least -0.2 in the last 15 minutes).
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 myaltitude = 186; // altitude above sea level in meter
const boolean acnt = false; // true for serial monitor/debug
//
// variables
//
int qfe = 0; // locale barometric pressure qfe in daPa (decaPascal)
int dqfe = 0; // Local barometric pressure difference between 2 sensor reads cycle (in daPa)
int pqfe = 0; // Local barometric pressure of the previous read cycle (in daPa)
int qnh = 0; // Barometric pressure calculated at sea level (in hPa)
int sdqfe = 0; // sum dqfe
int i = 0; // Loop control
boolean fqfeup = false; // flag qnh up
boolean fqfedown = false; // flag qnh down
boolean fqfewarn = false; // flag qnh fast down
byte cpt = 0; // cycle counter
int tdqfe[30] = {}; // history table of dqfe
//
void setup()
{
if (acnt) {
Serial.begin(9600);
Serial.println(" ");
Serial.println("*******************************************************");
Serial.println(" ");
Serial.println("BARO1-4-guyvano restarted! V.1 R.4 C.0 'Desired Daisy'");
}
//
// Define pins modes
//
pinMode(predled, OUTPUT);
pinMode(pgreenled, OUTPUT);
pinMode(pblueled, OUTPUT);
//
// Sensor
//
bme.begin(0x76); // address of the BME280 I2C sensor
//
// the colors used from the lower to higher pressures
//
// 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);
//
// Let's go! letter 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() + 5.0F) / 10.0F; // locale pressure qfe in daPa rounded
pqfe = qfe;
// initialize history table of the 30 dqfe values with 0
for (i = 0; i < 30; i++ ) {
tdqfe[i] = 0;
}
cpt = 0;
}
void loop()
{
qfe = (bme.readPressure() + 5.0F) / 10.0F;
qnh = (qfe / 10.0F) + (myaltitude * 0.1205F);
dqfe = qfe - pqfe;
tdqfe[cpt] = dqfe;
//
sdqfe = 0;
for (i = 0; i < 30; i++ ) {
sdqfe = sdqfe + tdqfe[i];
}
//
fqfeup = false;
fqfedown = false;
fqfewarn = false;
//
if ( 1 < sdqfe) {
fqfeup = true;
}
//
if (sdqfe < -1) {
fqfedown = true;
}
//
if (sdqfe < -4) {
fqfewarn = true;
fqfedown = false;
}
//
// UP : Green flashing
//
if (fqfeup) {
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);
}
}
//
// DOWN : Blue flashing
//
if (fqfedown) {
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);
}
}
//
// FAST FALLING WARNING : Red flashing
//
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);
}
}
//
// Long light on, depending of the qnh range
//
// QNH <= 1000 : Purple
//
if (qnh <= 1000) {
digitalWrite(predled, HIGH);
digitalWrite(pblueled, HIGH);
digitalWrite(pgreenled, LOW);
}
//
// 1001 <= QNH <= 1005 : Indigo
//
if ((1001 <= qnh) & (qnh <= 1005)) {
digitalWrite(pblueled, HIGH);
digitalWrite(predled, LOW);
digitalWrite(pgreenled, LOW);
}
//
// 1006 <= QNH <= 1010 : Light Blue
//
if ((1006 <= qnh) & (qnh <= 1010)) {
digitalWrite(pblueled, HIGH);
digitalWrite(pgreenled, LOW);
digitalWrite(predled, HIGH);
}
//
// 1011 <= QNH <= 1015 : Yellow
//
if ((1011 <= qnh) & (qnh <= 1015)) {
digitalWrite(pblueled, LOW);
digitalWrite(pgreenled, HIGH);
digitalWrite(predled, HIGH);
}
//
// 1016 <= QNH <= 1020 : Green
//
if ((1016 <= qnh) & (qnh <= 1020)) {
digitalWrite(pblueled, LOW);
digitalWrite(pgreenled, HIGH);
digitalWrite(predled, HIGH);
}
//
// 1021 <= QNH : Ice White
//
if (1021 <= qnh) {
digitalWrite(pblueled, HIGH);
digitalWrite(pgreenled, HIGH);
digitalWrite(predled, HIGH);
}
//
// Warning : red (R)
//
if (fqfewarn) {
digitalWrite(pblueled, LOW);
digitalWrite(pgreenled, LOW);
digitalWrite(predled, HIGH);
}
//
// serial control values if acnt set to true
//
if (acnt) {
Serial.println(" ");
Serial.print("cpt:");
Serial.print(cpt);
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(", sdqfe:");
Serial.print(sdqfe);
Serial.print(", fqfeup:");
Serial.print(fqfeup);
Serial.print(", fqfedown:");
Serial.print(fqfedown);
Serial.print(", fqfewarn:");
Serial.print(fqfewarn);
for (i = 0; i < 30; i++ ) {
Serial.print(", tdqfe[");
Serial.print(i);
Serial.print("]:");
Serial.print(tdqfe[i]);
}
}
//
pqfe = qfe;
cpt = (cpt + 1) % 30; // cpt+1 modulo 30, cpt return to 0 after 29.
//
delay(30000); // 30000 means 30 seconds to wait before a new cycle
}
// End of the program - Thanks for watching !
Author: Guy Vanoverbeke @GuyVano
Program last update (dd/mm/yyyy) : 15/02/2021 - V.1 R.4 C.0 "Desired Daisy"
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 (at least -0.5 hPa in the last 15 mn).
Short green flashes each 30 seconds: barometric pressure has increased recently (at least +0.2 hPa in the last 15 minutes).
Short blue flashes each 30 seconds: barometric pressure has decreased recently (at least -0.2 in the last 15 minutes).
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 myaltitude = 186; // altitude above sea level in meter
const boolean acnt = false; // true for serial monitor/debug
//
// variables
//
int qfe = 0; // locale barometric pressure qfe in daPa (decaPascal)
int dqfe = 0; // Local barometric pressure difference between 2 sensor reads cycle (in daPa)
int pqfe = 0; // Local barometric pressure of the previous read cycle (in daPa)
int qnh = 0; // Barometric pressure calculated at sea level (in hPa)
int sdqfe = 0; // sum dqfe
int i = 0; // Loop control
boolean fqfeup = false; // flag qnh up
boolean fqfedown = false; // flag qnh down
boolean fqfewarn = false; // flag qnh fast down
byte cpt = 0; // cycle counter
int tdqfe[30] = {}; // history table of dqfe
//
void setup()
{
if (acnt) {
Serial.begin(9600);
Serial.println(" ");
Serial.println("*******************************************************");
Serial.println(" ");
Serial.println("BARO1-4-guyvano restarted! V.1 R.4 C.0 'Desired Daisy'");
}
//
// Define pins modes
//
pinMode(predled, OUTPUT);
pinMode(pgreenled, OUTPUT);
pinMode(pblueled, OUTPUT);
//
// Sensor
//
bme.begin(0x76); // address of the BME280 I2C sensor
//
// the colors used from the lower to higher pressures
//
// 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);
//
// Let's go! letter 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() + 5.0F) / 10.0F; // locale pressure qfe in daPa rounded
pqfe = qfe;
// initialize history table of the 30 dqfe values with 0
for (i = 0; i < 30; i++ ) {
tdqfe[i] = 0;
}
cpt = 0;
}
void loop()
{
qfe = (bme.readPressure() + 5.0F) / 10.0F;
qnh = (qfe / 10.0F) + (myaltitude * 0.1205F);
dqfe = qfe - pqfe;
tdqfe[cpt] = dqfe;
//
sdqfe = 0;
for (i = 0; i < 30; i++ ) {
sdqfe = sdqfe + tdqfe[i];
}
//
fqfeup = false;
fqfedown = false;
fqfewarn = false;
//
if ( 1 < sdqfe) {
fqfeup = true;
}
//
if (sdqfe < -1) {
fqfedown = true;
}
//
if (sdqfe < -4) {
fqfewarn = true;
fqfedown = false;
}
//
// UP : Green flashing
//
if (fqfeup) {
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);
}
}
//
// DOWN : Blue flashing
//
if (fqfedown) {
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);
}
}
//
// FAST FALLING WARNING : Red flashing
//
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);
}
}
//
// Long light on, depending of the qnh range
//
// QNH <= 1000 : Purple
//
if (qnh <= 1000) {
digitalWrite(predled, HIGH);
digitalWrite(pblueled, HIGH);
digitalWrite(pgreenled, LOW);
}
//
// 1001 <= QNH <= 1005 : Indigo
//
if ((1001 <= qnh) & (qnh <= 1005)) {
digitalWrite(pblueled, HIGH);
digitalWrite(predled, LOW);
digitalWrite(pgreenled, LOW);
}
//
// 1006 <= QNH <= 1010 : Light Blue
//
if ((1006 <= qnh) & (qnh <= 1010)) {
digitalWrite(pblueled, HIGH);
digitalWrite(pgreenled, LOW);
digitalWrite(predled, HIGH);
}
//
// 1011 <= QNH <= 1015 : Yellow
//
if ((1011 <= qnh) & (qnh <= 1015)) {
digitalWrite(pblueled, LOW);
digitalWrite(pgreenled, HIGH);
digitalWrite(predled, HIGH);
}
//
// 1016 <= QNH <= 1020 : Green
//
if ((1016 <= qnh) & (qnh <= 1020)) {
digitalWrite(pblueled, LOW);
digitalWrite(pgreenled, HIGH);
digitalWrite(predled, HIGH);
}
//
// 1021 <= QNH : Ice White
//
if (1021 <= qnh) {
digitalWrite(pblueled, HIGH);
digitalWrite(pgreenled, HIGH);
digitalWrite(predled, HIGH);
}
//
// Warning : red (R)
//
if (fqfewarn) {
digitalWrite(pblueled, LOW);
digitalWrite(pgreenled, LOW);
digitalWrite(predled, HIGH);
}
//
// serial control values if acnt set to true
//
if (acnt) {
Serial.println(" ");
Serial.print("cpt:");
Serial.print(cpt);
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(", sdqfe:");
Serial.print(sdqfe);
Serial.print(", fqfeup:");
Serial.print(fqfeup);
Serial.print(", fqfedown:");
Serial.print(fqfedown);
Serial.print(", fqfewarn:");
Serial.print(fqfewarn);
for (i = 0; i < 30; i++ ) {
Serial.print(", tdqfe[");
Serial.print(i);
Serial.print("]:");
Serial.print(tdqfe[i]);
}
}
//
pqfe = qfe;
cpt = (cpt + 1) % 30; // cpt+1 modulo 30, cpt return to 0 after 29.
//
delay(30000); // 30000 means 30 seconds to wait before a new cycle
}
// End of the program - Thanks for watching !
edit 16/02/2021 : New release available here!
*** Guy F8ABX - 15-16/02/2021 ***
Aucun commentaire:
Enregistrer un commentaire