Arduino(4): Atmospheric Pressure (Altimeter) Sensing Module GY-BMP280

I have a G-SHOCK electronic watch with an altimeter function. The altimeter function of the watch should detect the atmospheric pressure and measure the height according to the change of the air pressure. However, the error is always large, sometimes it may be 20-30 meters. The actual function of this module is BMP280. According to the specifications, the relative accuracy is up to 1 meter. 

I originally used adafruit/Adafruit_BMP280_Library on Github. When I executed, I couldn't detect my BMP280 module. I wasn't sure if this module is working properly. After trying to find the Sense-BMx280 library, I can measure the pressure and temperature normally. Then have time to look slowly and see where the problem is?


[BMP280 Atmospheric Pressure (Altimeter) Sensing Module]

The specifications of GY-BMP280 high-precision atmospheric pressure sensing module are as follows:
  • Model: GY-BMP280-3.3
  • Using the chip: BMP280
  • Power supply: 3v
  • Communication method: standard IIC/SPI communication protocol
  • Air pressure range: 300-1100hPa
  • Adopt Shenjin PCB, machine welding process to ensure quality
  • Pin pitch: 2.54mm
The BMP280 air pressure sensor is designed for mobile applications. Its small size and low power consumption allow for use in battery powered mobile phones such as GPS modules or watches. BMP280 applications such as weather forecasting, altitude measurement, indoor navigation, fitness and sports. The digital pressure sensor BMP280 offers excellent performance with a relative accuracy of ±0 12 hPa (equivalent to ±1 m) and includes a pressure and temperature measurement function sensor that consumes only 2.7 μA.

[Install sSense-BMx280 Library]

The sSense-BMx280 library provides values ​​for reading at atmospheric pressure using BMP280 . 
• Download sSense-BMx280.zip first at itbrainpower.net. 
• Unzip the downloaded zip file and place it in the libraries directory under the Arduino main program. For my computer, Arduino is installed in C:\Program Files (x86)\Arduino, and the subdirectory has a library subdirectory. After downloading the unzipped directory, put it all in the libraries directory and restart Arduino.

[material]

• Arduino Uno x 1 
• GY-BMP280 x 1 
• Cable x 4

[Wiring and circuit diagram]

Arduino
GY-68 BMP180
3.3V (VCC)
VCC
GND
GND
A4 
SDA
A5 
SCL

[Code]

#include <sSense-BMx280I2C.h>
#include <Wire.h>
#define SERIAL_SPEED  19200

BMx280I2C::Settings settings(
   BME280::OSR_X1,
   BME280::OSR_X1,
   BME280::OSR_X1,
   BME280::Mode_Forced,
   BME280::StandbyTime_1000ms,
   BME280::Filter_Off,
   BME280::SpiEnable_False,
   0x76    // I2C address. I2C specific.
);

BMx280I2C ssenseBMx280(settings);

void setup()
{
  delay(5000);
  DebugPort.begin(SERIAL_SPEED);

  while(!DebugPort) {}        
  DebugPort.println("s-Sense BME/BMP280 I2C sensor.");

  Wire.begin();
  while(!ssenseBMx280.begin())
  {
    DebugPort.println("Could not find BME/BMP280 sensor!");
    delay(1000);
  }
  
  switch(ssenseBMx280.chipModel())
  {
     case BME280::ChipModel_BME280:
       DebugPort.println("Found BME280 sensor! Humidity available.");
       break;
     case BME280::ChipModel_BMP280:
       DebugPort.println("Found BMP280 sensor! No Humidity available.");
       break;
     default:
       DebugPort.println("Found UNKNOWN sensor! Error!");
  }

   // Change some settings before using.
   settings.tempOSR = BME280::OSR_X4;

   ssenseBMx280.setSettings(settings);
}


void loop()
{
   printBMx280Data(&DebugPort);
   delay(500);
}


void printBMx280Data(Stream* client)
{
   float temp(NAN), hum(NAN), pres(NAN);

   BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
   BME280::PresUnit presUnit(BME280::PresUnit_Pa);

   ssenseBMx280.read(pres, temp, hum, tempUnit, presUnit);

   client->print("Temp: ");
   client->print(temp);
   client->print(" "+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'));
   client->print("\t\tHumidity: ");
   client->print(hum);
   client->print("% RH");
   client->print("\t\tPressure: ");
   client->print(pres);
   client->println(" Pa");

   delay(1000);
}

Code2: The air pressure can be converted to height, but is it not sure whether the height is correct?
#include <BMx280_EnvCalc.h>
#include <sSense-BMx280I2C.h>
#include <Wire.h>
#define SERIAL_SPEED 19200

BMx280I2C ssenseBMx280;   // Default : forced mode, standby time = 1000 ms
                          // Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,

void setup()
{
  delay(5000);
  DebugPort.begin(SERIAL_SPEED);

  while(!DebugPort) {} // Wait

  Wire.begin();

  while(!ssenseBMx280.begin())
  {
    DebugPort.println("Could not find BME280 sensor!");
    delay(1000);
  }

  switch(ssenseBMx280.chipModel())
  {
     case BME280::ChipModel_BME280:
       DebugPort.println("Found BME280 sensor! Humidity available.");
       break;
     case BME280::ChipModel_BMP280:
       DebugPort.println("Found BMP280 sensor! No Humidity available.");
       break;
     default:
       DebugPort.println("Found UNKNOWN sensor! Error!");
  }
}

void loop()
{
   printBMx280Data(&DebugPort);
   delay(500);
}


void printBMx280Data( Stream* client )
{
   float temp(NAN), hum(NAN), pres(NAN);

   BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
   BME280::PresUnit presUnit(BME280::PresUnit_Pa);

   ssenseBMx280.read(pres, temp, hum, tempUnit, presUnit);

   client->print("Temp: ");
   client->print(temp);
   client->print(String(tempUnit == BME280::TempUnit_Celsius ? "C" :"F"));
   client->print("\t\tHumidity: ");
   client->print(hum);
   client->print("% RH");
   client->print("\t\tPressure: ");
   client->print(pres);
   client->print(" Pa");

   BMx280_EnvCalc::AltitudeUnit envAltUnit  =  BMx280_EnvCalc::AltitudeUnit_Meters;
   BMx280_EnvCalc::TempUnit     envTempUnit =  BMx280_EnvCalc::TempUnit_Celsius;

   float altitude = BMx280_EnvCalc::Altitude(pres, envAltUnit);
   float dewPoint = BMx280_EnvCalc::DewPoint(temp, hum, envTempUnit);
   float seaLevel = BMx280_EnvCalc::EquivalentSeaLevelPressure(altitude, temp, pres);
   // seaLevel = BMx280_EnvCalc::SealevelAlitude(altitude, temp, pres); // Deprecated. See EquivalentSeaLevelPressure().

   client->print("\r\nAltitude: ");
   client->print(altitude);
   client->print((envAltUnit == BMx280_EnvCalc::AltitudeUnit_Meters ? "m" : "ft"));
   client->print("\tDew point: ");
   client->print(dewPoint);
   client->print(String(envTempUnit == BMx280_EnvCalc::TempUnit_Celsius ? "C" :"F"));
   client->print("\t\tEquivalent Sea Level Pressure: ");
   client->print(seaLevel);
   client->println(" Pa\r\n");

   delay(1000);
}

[Results]

Code one execution result:


Code two execution result:


[Reference]

• Hackster.io:Arduino BMP280 Sensor How To

Post a Comment

Previous Post Next Post