Skocz do zawartości

Pomiar ciśnienia z BMP280 w lokalnej lokalizacji


solyaris

Pomocna odpowiedź

Jestem nowy na forum i witam wszystkich użytkowników. Jestem już emerytem i może to nie jest miejsce dla mnie ale spróbuję bo mam problem i proszę o pomoc.

Zbudowałem i zaprogramowałem gotowy program pogodynkę, wszystko działa prawidłowo tylko w oryginalnym programie nie ma możliwości odczytać właściwego ciśnienia w danej lokalizacji czyli zależnego od wysokości nad poziomem morza. Pracowałem jako elektronik ale z programowaniem nie miałem nic wspólnego. Ten gotowy program uprościłem bo wilgotność mnie nie interesuje tylko temperatura i ciśnienie. Próbowałem skopiować z innych szkiców ale nie mogę sobie poradzić. Po prostu nie wiem gdzie i co powinienem wkleić do mojego. Załączam szkic w którym dodałem nr. 9, 10 #define ........ ale brak zadziałania, dodaję cały szkic i proszę o pomoc.

Pozdrawiam Jan

1#include <SPI.h>               //include Seria
2#include <Adafruit_GFX.h>      // include Adafruit graphics library
3#include <Adafruit_ST7735.h>   // include Adafruit ST7735 TFT library
4#include <Adafruit_BMP280.h>   // include Adafruit BMP280 sensor library
5#include <Adafruit_Sensor.h>
6#define TFT_RST   8            // TFT RST pin is connected to arduino pin D8
7#define TFT_CS    10           // TFT CS  pin is connected to arduino pin D9
8#define TFT_DC    9            // TFT DC  pin is connected to arduino pin D10
9#define SEALEVELPRESSURE_HPA (1013.25) //cisnienie na poziomie morza
10#define ALTITUDE 100.0 // wysokosc wzgledna w metrach dla miejsca pomiaru – u mnie 160 m npm

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);      // initialize ST7735 SERIES TFT library
 
// define device I2C address: 0x76 or 0x77 (0x77 is the library default address)
#define BMP280_I2C_ADDRESS  0x76
 
Adafruit_BMP280  bmp280;                               // initialize Adafruit BMP280 library

 
void setup(void)
{
  tft.initR(INITR_144GREENTAB);                        // initialize a ST7735S chip, black tab
  tft.fillScreen(ST77XX_BLACK);                        // setting black background 
  tft.setTextColor(ST77XX_CYAN );                      // set text color to white and black background
  tft.setTextSize(1);                                  // setting text size to 1
  //tft.setCursor(4, 0);                               // move cursor to position (4, 0) pixel
  //tft.print("ARDUINO + ST7735 TFT");
  tft.setCursor(25, 5);                                // move cursor to position (25, 5) pixel 
 
  if( bmp280.begin(BMP280_I2C_ADDRESS) == 0 )           // connection error or device address wrong!
  {  
   
  }
 
  tft.drawFastHLine(0, 64,  tft.width(), ST77XX_CYAN);  // draw horizontal seperation line at position (0, 55)pixel
  tft.setTextColor(ST77XX_RED, ST77XX_BLACK);           // set text color to red and black background
  tft.setCursor(30, 6);                                 // move cursor to position (30, 20) pixel
  tft.print("TEMPERATURA ");                            // setting heading for first section
  tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);          // set text color to cyan and black background
  tft.setTextColor(ST77XX_RED, ST7735_BLACK);           // set text color to green and black background
  tft.setCursor(40, 70);                                // move cursor to position (40, 100) pixel
  tft.print("CISNIENIE ");                              // setting heading for third section 
  tft.setTextSize(2);                                   // setting text size to 2 
}
 
void loop()
  {
   
  char _buffer[8];                                       // read temperature, humidity and pressure from the BMP280 sensor
  
  float temp = bmp280.readTemperature();                 // get temperature in °C
  float pres = bmp280.readPressure();                    // get pressure in hPa
  delay(2000);
  if(temp < 0)                                           // if temperature < 0
    sprintf( _buffer, "-%02u.%02u", (int)abs(temp), (int)(abs(temp) * 100) % 100 );
  else                                      // if temperature >= 0
    sprintf( _buffer, " %02u.%02u", (int)temp, (int)(temp * 100) % 100 );// setting the value approximation 
  tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);  // set text color to yellow and black background
  tft.setCursor(11, 34);                          // move cursor to position (11,34) pixel 
  tft.print(_buffer);                             // print temperature from BMP-280 sensor
  tft.drawCircle(89, 34, 2, ST77XX_YELLOW);       // print the degree symbol ( ° )(can be omitted if * is used instead)
  tft.setCursor(95, 34);                          // move cursor to position (95,34) pixel 
  tft.print("C");                                 // print the Celcius symbol   
   delay(2000);
  // 2: print pressure (in hPa)
  sprintf( _buffer, "%04u.%02u", 
  (int)(pres/100), 
  (int)((uint32_t)pres % 100) ); // setting the value approximation 
  tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);  // set text color to orange and black background
  tft.setCursor(2, 100);                          // move cursor to position (3,112)pixel      
  tft.print(_buffer);                             // print atmospheric pressure from BMP-280
  tft.setCursor(80, 100);                         // move cursor to position (91,112)pixel
  tft.print(" hPa");                               // print unit of atmospheric pressure as hecto pascal
  delay(1000);                                    // wait 1 second before taking next sensor reading
  
 
}

 

  • Lubię! 1
Link do komentarza
Share on other sites

Czekaj, co chcesz osiągnąć? Bo ten czujnik to prosty barometr, mierzy nacisk na barierę między zamknietą komorą a światem zewnętrznym i na tej podstawie oblicza absolutną wartość ciśnienia po drugiej stronie tej bariery. Co więcej chcesz uzyskać?

Link do komentarza
Share on other sites

 
#include <SPI.h>               //include Seria
#include <Adafruit_GFX.h>      // include Adafruit graphics library
#include <Adafruit_ST7735.h>   // include Adafruit ST7735 TFT library
#include <Adafruit_BMP280.h>   // include Adafruit BMP280 sensor library
#include <Adafruit_Sensor.h>
#include <EnvironmentCalculations.h>
#define TFT_RST   8            // TFT RST pin is connected to arduino pin D8
#define TFT_CS    10           // TFT CS  pin is connected to arduino pin D9
#define TFT_DC    9            // TFT DC  pin is connected to arduino pin D10

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);      // initialize ST7735 SERIES TFT library
 
// define device I2C address: 0x76 or 0x77 (0x77 is the library default address)
#define BMP280_I2C_ADDRESS  0x76

float referencePressure = 1013.6;  // hPa local QFF (official meteor-station reading)
float outdoorTemp = 0.0;           // °C  measured local outdoor temp.
float barometerAltitude = 100.3;  // meters ... map readings + barometer position

Adafruit_BMP280  bmp280;                               // initialize Adafruit BMP280 library
 
void setup(void)
{

  Wire.begin();

  tft.initR(INITR_144GREENTAB);                        // initialize a ST7735S chip, black tab
  tft.fillScreen(ST77XX_BLACK);                        // setting black background 
  tft.setTextColor(ST77XX_CYAN );                      // set text color to white and black background
  tft.setTextSize(1);                                  // setting text size to 1
  //tft.setCursor(4, 0);                               // move cursor to position (4, 0) pixel
  //tft.print("ARDUINO + ST7735 TFT");
  tft.setCursor(25, 5);                                // move cursor to position (25, 5) pixel 
 
  if( bmp280.begin(BMP280_I2C_ADDRESS) == 0 )           // connection error or device address wrong!
   Serial.print("Assumed outdoor temperature: "); Serial.print(outdoorTemp);
  Serial.print("°C\nAssumed reduced sea level Pressure: "); Serial.print(referencePressure);
  Serial.print("hPa\nAssumed barometer altitude: "); Serial.print(barometerAltitude);
  Serial.println("m\n");
  {  
   
  }
 
  tft.drawFastHLine(0, 64,  tft.width(), ST77XX_CYAN);  // draw horizontal seperation line at position (0, 55)pixel
  tft.setTextColor(ST77XX_RED, ST77XX_BLACK);           // set text color to red and black background
  tft.setCursor(30, 6);                                 // move cursor to position (30, 20) pixel
  tft.print("TEMPERATURA ");                            // setting heading for first section
  tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);          // set text color to cyan and black background
  tft.setTextColor(ST77XX_RED, ST7735_BLACK);           // set text color to green and black background
  tft.setCursor(40, 70);                                // move cursor to position (40, 100) pixel
  tft.print("CISNIENIE ");                              // setting heading for third section 
  tft.setTextSize(2);                                   // setting text size to 2
  Serial.print("Assumed outdoor temperature: "); Serial.print(outdoorTemp);
  Serial.print("°C\nAssumed reduced sea level Pressure: "); Serial.print(referencePressure);
  Serial.print("hPa\nAssumed barometer altitude: "); Serial.print(barometerAltitude);
  Serial.println("m\n***************************************"); 
}
 
void loop()

  {
  char _buffer[8];                                       // read temperature, humidity and pressure from the BMP280 sensor
  
  float temp = bmp280.readTemperature();                 // get temperature in °C
  float pres = bmp280.readPressure();                    // get pressure in hPa
 
  delay(2000);
  if(temp < 0)                                           // if temperature < 0
    sprintf( _buffer, "-%02u.%02u", (int)abs(temp), (int)(abs(temp) * 100) % 100 );
  else                                      // if temperature >= 0
    sprintf( _buffer, " %02u.%02u", (int)temp, (int)(temp * 100) % 100 );// setting the value approximation 
  tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);  // set text color to yellow and black background
  tft.setCursor(11, 34);                          // move cursor to position (11,34) pixel 
  tft.print(_buffer);                             // print temperature from BMP-280 sensor
  tft.drawCircle(89, 34, 2, ST77XX_YELLOW);       // print the degree symbol ( ° )(can be omitted if * is used instead)
  tft.setCursor(95, 34);                          // move cursor to position (95,34) pixel 
  tft.print("C");                                 // print the Celcius symbol   
   delay(2000);
  // 2: print pressure (in hPa)
  sprintf( _buffer, "%04u.%02u", 
  (int)(pres/100), 
  (int)((uint32_t)pres % 100) );                   // setting the value approximation 
  tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);  // set text color to orange and black background
  tft.setCursor(2, 100);                          // move cursor to position (3,112)pixel      
  tft.print(_buffer);                             // print atmospheric pressure from BMP-280
  tft.setCursor(80, 100);                         // move cursor to position (91,112)pixel
  tft.print(" hPa");                               // print unit of atmospheric pressure as hecto pascal
  EnvironmentCalculations::AltitudeUnit envAltUnit  =  EnvironmentCalculations::AltitudeUnit_Meters;
   EnvironmentCalculations::TempUnit     envTempUnit =  EnvironmentCalculations::TempUnit_Celsius;
  float altitude = EnvironmentCalculations::Altitude(pres, envAltUnit, referencePressure, outdoorTemp, envTempUnit);
   float seaLevel = EnvironmentCalculations::EquivalentSeaLevelPressure(barometerAltitude, temp, pres, envAltUnit, envTempUnit);


  delay(1000);                                    // wait 1 second before taking next sensor reading 
  
  
 
}

Co chcę osiągnąć to po przed uruchomieniem pogodynki wpisuję wysokość mojego zamieszkania i program powinien przeliczyć ciśnienie jakie jest na mojej wysokości nad poziomem morza. Zrobiłem już jedną pogodynkę kopia  gotowa jakiegoś greka i tam jak zmieniam wysokość zmienia się wartość ciśnienia.

Link do komentarza
Share on other sites

Ale czujnik zgodnie z prawami fizyki mierzy ciśnienie tam gdzie się znajduje, nie potrzebuje do tego żadnych danych, jak jest po zewnętrznej stronie 1337 hPa to tyle zwraca.

Z tego co widzę ten kod liczy z otrzymanego ciśnienia wysokość zakładając stałe ciśnienie na poziomie morza i znormalizowane ciśnienie atmosferyczne zakładając stałą wysokość. A potem nic z nimi nie robi?

Edytowano przez Chumanista
Link do komentarza
Share on other sites

Zarejestruj się lub zaloguj, aby ukryć tę reklamę.
Zarejestruj się lub zaloguj, aby ukryć tę reklamę.

jlcpcb.jpg

jlcpcb.jpg

Produkcja i montaż PCB - wybierz sprawdzone PCBWay!
   • Darmowe płytki dla studentów i projektów non-profit
   • Tylko 5$ za 10 prototypów PCB w 24 godziny
   • Usługa projektowania PCB na zlecenie
   • Montaż PCB od 30$ + bezpłatna dostawa i szablony
   • Darmowe narzędzie do podglądu plików Gerber
Zobacz również » Film z fabryki PCBWay

Prawa fizyki znam i jak działa BMP280 też właśnie w tym problem że jeśli zmieniam w szkicu float barometerAltitude = 100.3; wysokości nie zmienia mi ciśnienia

W wspomnianym wcześniej szkicu mam BMP180 i jak tam podam wysokość mojej lokalizacji to wskazuje  ciśnienie prawidłowe.

Link do komentarza
Share on other sites

#include <DallasTemperature.h>
#include <OneWire.h>
#include <DS18B20.h>
#include "DHT.h"
#include <LiquidCrystal.h>
#include <SFE_BMP180.h>
#include <Wire.h>
#define ONE_WIRE_BUS 9

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

SFE_BMP180 pressure;

float temperature;
#define ALTITUDE 140.0 // Altitude in Olsztyn, Poland

#define DHTPIN 8     // what pin we're connected to
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal lcd(7,6,5,4,3,2); 

void setup(void) 
{
  sensors.begin();
  lcd.begin(16, 2);
  lcd.print("Odczyt");
  dht.begin();
  pressure.begin();
}

void loop() 
{  
  sensors.requestTemperatures(); 

  lcd.print(sensors.getTempCByIndex(0));

  lcd.setCursor(1, 10);  
 float humidity, pressure; 
 humidity = dht.readHumidity()+10.0f;
 pressure = readPressureAndTemperature(); 
 delay(2000); 
 lcd.clear(); 
 
 char tempF[8]; 
 char humF[8];
 char pressF[8];
 
 dtostrf(temperature, 4, 1, tempF);
 dtostrf(humidity, 1, 0, humF);
 dtostrf(pressure, 4, 0, pressF);

 
 lcd.print("Tw.");             //Wyświetl Temperature 
 lcd.print(tempF);
 lcd.print((char)223);
 lcd.print("C  ");
 
 lcd.print("H.");            //Wyświetl wilgotność    
 lcd.print(humF);
 lcd.print("%");
 
 
 lcd.setCursor(0,1);          //Wyświetl ciśnienie
 lcd.print("P.");
 lcd.print(pressF);
 lcd.print("hPa ");
 lcd.setCursor(10, 1);       // temperatura zewnętrzna
 lcd.print("Tz.");
 
}

float readPressureAndTemperature()
{
  char status;
  double T,P,p0,a;

  status = pressure.startTemperature();
  if (status != 0)
  {
    delay(status);
    status = pressure.getTemperature(T);
    if (status != 0)
    { 
      temperature = T;
      status = pressure.startPressure(3);
      if (status != 0)
      {
        delay(status);
        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          p0 = pressure.sealevel(P,ALTITUDE);       
          return p0;
        }
      }
    }
  }
}

To jest szkic w którym jak zmienię ALTITUDE i zaprogramuję to wyświetla  ciśnienie jakie np. jest podane dla danej miejscowości, czyli chcę podać wysokość w której programuję szkic i aby zostało wyliczone ciśnienie.  W tej chwili w Olsztynie w internecie mam podane ciśnienie 1031 mbar a mi wyświetla 1017,9 hPa

Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.