SHARE
TWEET

ZUNO_BMP280.h

DARKHalf Oct 19th, 2016 147 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     BMP280.h
  3.     Bosch BMP280 pressure sensor library for the Arduino microcontroller.
  4.     This library uses I2C connection.
  5.  
  6.     Uses floating-point equations from BMP280 datasheet.
  7.  
  8.     modified by mhafuzul islam
  9.  
  10.     version 1.01         16/9/2014 initial version
  11.    
  12.     Our example code uses the "pizza-eating" license. You can do anything
  13.     you like with this code. No really, anything. If you find it useful,
  14.     buy me italian pizza someday.
  15. */
  16.  
  17. #ifndef BMP280_h
  18. #define BMP280_h
  19.  
  20. #include "Arduino.h"
  21.  
  22. // #define _debugSerial
  23. // #define _debugTestData
  24.  
  25. class BMP280
  26. {
  27.     public:
  28.         BMP280(); // base type
  29.  
  30.         char begin();
  31.         char begin(int sdaPin, int sclPin);
  32.             // call pressure.begin() to initialize BMP280 before use
  33.             // returns 1 if success, 0 if failure (i2C connection problem.)
  34.                
  35.         short getOversampling(void);
  36.         char  setOversampling(short oss);
  37.        
  38.         char startMeasurment(void);
  39.             // command BMP280 to start a pressure measurement
  40.             // oversampling: 0 - 3 for oversampling value
  41.             // returns (number of ms to wait) for success, 0 for fail
  42.        
  43.         //char calcTemperature(double &T, double &uT);
  44.             // calculation the true temperature from the given uncalibrated Temperature
  45.            
  46.         //char calcPressure(double &P, double uP);
  47.             //calculation for measuring pressure.
  48.            
  49.         double sealevel(double P, double A);
  50.             // convert absolute pressure to sea-level pressure
  51.             // P: absolute pressure (mbar)
  52.             // A: current altitude (meters)
  53.             // returns sealevel pressure in mbar
  54.  
  55.         double altitude(double P, double P0);
  56.             // convert absolute pressure to altitude (given baseline pressure; sea-level, runway, etc.)
  57.             // P: absolute pressure (mbar)
  58.             // P0: fixed baseline pressure (mbar)
  59.             // returns signed altitude in meters
  60.  
  61.         char getError(void);
  62.             // If any library command fails, you can retrieve an extended
  63.             // error code using this command. Errors are from the wire library:
  64.             // 0 = Success
  65.             // 1 = Data too long to fit in transmit buffer
  66.             // 2 = Received NACK on transmit of address
  67.             // 3 = Received NACK on transmit of data
  68.             // 4 = Other error
  69.            
  70.         char getTemperatureAndPressure(double& T,double& P);
  71.  
  72.     private:
  73.    
  74.        
  75.  
  76.         char readInt(char address, double &value);
  77.             // read an signed int (16 bits) from a BMP280 register
  78.             // address: BMP280 register address
  79.             // value: external signed int for returned value (16 bits)
  80.             // returns 1 for success, 0 for fail, with result in value
  81.  
  82.         char readUInt(char address, double &value);
  83.             // read an unsigned int (16 bits) from a BMP280 register
  84.             // address: BMP280 register address
  85.             // value: external unsigned int for returned value (16 bits)
  86.             // returns 1 for success, 0 for fail, with result in value
  87.  
  88.         char readBytes(unsigned char *values, char length);
  89.             // read a number of bytes from a BMP280 register
  90.             // values: array of char with register address in first location [0]
  91.             // length: number of bytes to read back
  92.             // returns 1 for success, 0 for fail, with read bytes in values[] array
  93.            
  94.         char writeBytes(unsigned char *values, char length);
  95.             // write a number of bytes to a BMP280 register (and consecutive subsequent registers)
  96.             // values: array of char with register address in first location [0]
  97.             // length: number of bytes to write
  98.             // returns 1 for success, 0 for fail
  99.        
  100.         //char getUnPT(double &uP, double &uT);
  101.             //get uncalibrated UP and UT value.
  102.            
  103.         char readCalibration();
  104.             // Retrieve calibration data from device:
  105.             // The BMP280 includes factory calibration data stored on the device.
  106.             // Each device has different numbers, these must be retrieved and
  107.             // used in the calculations when taking measurements.
  108.    
  109.                
  110.         //int dig_T2 , dig_T3 , dig_T4 , dig_P2 , dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9;
  111.         //unsigned int dig_P1 , dig_T1 ;
  112.         double dig_T1, dig_T2 , dig_T3 , dig_T4 , dig_P1, dig_P2 , dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9;
  113.         short oversampling, oversampling_t;
  114.         double t_fine;
  115.         char error;
  116. };
  117.  
  118. #define BMP280_ADDR 0x76 // 7-bit address
  119.  
  120. #define BMP280_REG_CONTROL 0xF4
  121. #define BMP280_REG_RESULT_PRESSURE 0xF7         // 0xF7(msb) , 0xF8(lsb) , 0xF9(xlsb) : stores the pressure data.
  122. #define BMP280_REG_RESULT_TEMPRERATURE 0xFA     // 0xFA(msb) , 0xFB(lsb) , 0xFC(xlsb) : stores the temperature data.
  123.  
  124. #define BMP280_COMMAND_TEMPERATURE 0x2E
  125. #define BMP280_COMMAND_PRESSURE0 0x25            
  126. #define BMP280_COMMAND_PRESSURE1 0x29          
  127. #define BMP280_COMMAND_PRESSURE2 0x2D    
  128. #define BMP280_COMMAND_PRESSURE3 0x31    
  129. #define BMP280_COMMAND_PRESSURE4 0x5D    
  130.  
  131. #endif
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top