├── examples ├── README.md ├── BMP180_altitude_example │ └── BMP180_altitude_example.ino └── SFE_BMP180_example │ └── SFE_BMP180_example.ino ├── src ├── README.md ├── SFE_BMP180.h └── SFE_BMP180.cpp ├── LICENSE.md ├── library.properties ├── .gitattributes ├── keywords.txt ├── README.md └── .gitignore /examples/README.md: -------------------------------------------------------------------------------- 1 | SparkFun Example Sketches 2 | --------------------------- 3 | 4 | 5 | Basic Arduino Example Sketches that work with the SparkFun BMP180 Library. 6 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | This folder should contain the .cpp and .h files for the library. 2 | 3 | If backward compatibility is needed, source code should be placed in the library root folder and in a "utilyt" folder. 4 | 5 | Check out the [library specification](https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification) for more details. -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | License Information 3 | ------------------- 4 | 5 | The hardware is released under [Creative Commons Share-alike 3.0](http://creativecommons.org/licenses/by-sa/3.0/). 6 | 7 | All other code is open source so please feel free to do anything you want with it; you buy me a beer if you use this and we meet someday ([Beerware license](http://en.wikipedia.org/wiki/Beerware)). 8 | 9 | 10 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Sparkfun BMP180 2 | version=1.1.2 3 | author=SparkFun Electronics 4 | maintainer=SparkFun Electronics 5 | sentence=Sparkfun examples for the Bosch BMP180 barometric pressure sensor 6 | paragraph=Example code for the Sparkfun Bosch BMP180 barometric pressure sensor breakout board. 7 | category=Signal Input/Output 8 | url=https://github.com/sparkfun/BMP180_Breakout 9 | architectures=* 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map for SFE_BMP180 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SFE_BMP180 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | startTemperature KEYWORD2 17 | getTemperature KEYWORD2 18 | startPressure KEYWORD2 19 | getPressure KEYWORD2 20 | sealevel KEYWORD2 21 | altitude KEYWORD2 22 | 23 | ####################################### 24 | # Constants (LITERAL1) 25 | ####################################### 26 | 27 | BMP180_ADDR LITERAL1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **NOTE:** *This product has been retired from our catalog. If you are looking for more up-to-date info, please check out some of these resources to see how other users are still hacking and improving on this product.* 2 | * *[SparkFun Forum](https://forum.sparkfun.com/)* 3 | * *[Comments Here on GitHub](https://github.com/sparkfun/BMP180_Breakout_Arduino_Library/issues)* 4 | * *[IRC Channel](https://www.sparkfun.com/news/263)* 5 | 6 | SparkFun BMP180_Breakout Arduino Library 7 | ======================================== 8 | 9 | ![BMP180 Breakout](https://dlnmh9ip6v2uc.cloudfront.net/images/products/1/1/8/2/4/11824-01.jpg) 10 | 11 | [*SEN-11824*](https://www.sparkfun.com/products/11824) 12 | 13 | This archive contains an Arduino library and example sketch showing how to use this sensor. The library must be installed onto your computer in order for the example code to work correctly. 14 | 15 | Repository Contents 16 | ------------------- 17 | 18 | * **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE. 19 | * **/src** - Source files for the library (.cpp, .h). 20 | * **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE. 21 | * **library.properties** - General library properties for the Arduino package manager. 22 | 23 | Documentation 24 | -------------- 25 | 26 | * **[*Installing an Arduino Library* Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library. 27 | * **[Product Repository](https://github.com/sparkfun/BMP180_Breakout)** - Main repository (including hardware files) for the BMP180 Breakout. 28 | * **[Hookup Guide](https://learn.sparkfun.com/tutorials/bmp180-barometric-pressure-sensor-hookup)** - Basic hookup guide for the BMP180 Breakout. 29 | 30 | Products that use this Library 31 | --------------------------------- 32 | 33 | * [SEN-11824](https://www.sparkfun.com/products/11824) - BMP180 Barometric Pressure Sensor Breakout 34 | 35 | 36 | Version History 37 | --------------- 38 | * [V_1.1.2](https://github.com/sparkfun/BMP180_Breakout_Arduino_Library/tree/V_1.1.2) - Small patch on integers, cleaning up library files. 39 | * [V_1.1.1](https://github.com/sparkfun/BMP180_Breakout_Arduino_Library/tree/V_1.1.1) - Updated library.properties file 40 | * [V_1.1.0](https://github.com/sparkfun/BMP180_Breakout_Arduino_Library/tree/V_1.1.0) - Updated to new library structure 41 | * V_1.0.0 - Untracked version 42 | 43 | License Information 44 | ------------------- 45 | 46 | This product is _**open source**_! 47 | 48 | The **code** is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round! 49 | 50 | Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release anything derivative under the same license. 51 | 52 | Distributed as-is; no warranty is given. 53 | 54 | \- Your friends at SparkFun. 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## SparkFun Useful stuff 3 | ################# 4 | 5 | ## AVR Development 6 | *.eep 7 | *.elf 8 | *.lst 9 | *.lss 10 | *.sym 11 | *.d 12 | *.o 13 | *.srec 14 | *.map 15 | 16 | ## Notepad++ backup files 17 | *.bak 18 | 19 | ## BOM files 20 | *bom* 21 | 22 | ################# 23 | ## Eclipse 24 | ################# 25 | 26 | *.pydevproject 27 | .project 28 | .metadata 29 | bin/ 30 | tmp/ 31 | *.tmp 32 | *.bak 33 | *.swp 34 | *~.nib 35 | local.properties 36 | .classpath 37 | .settings/ 38 | .loadpath 39 | 40 | # External tool builders 41 | .externalToolBuilders/ 42 | 43 | # Locally stored "Eclipse launch configurations" 44 | *.launch 45 | 46 | # CDT-specific 47 | .cproject 48 | 49 | # PDT-specific 50 | .buildpath 51 | 52 | 53 | ############# 54 | ## Eagle 55 | ############# 56 | 57 | # Ignore the board and schematic backup files 58 | *.b#? 59 | *.s#? 60 | 61 | 62 | ################# 63 | ## Visual Studio 64 | ################# 65 | 66 | ## Ignore Visual Studio temporary files, build results, and 67 | ## files generated by popular Visual Studio add-ons. 68 | 69 | # User-specific files 70 | *.suo 71 | *.user 72 | *.sln.docstates 73 | 74 | # Build results 75 | [Dd]ebug/ 76 | [Rr]elease/ 77 | *_i.c 78 | *_p.c 79 | *.ilk 80 | *.meta 81 | *.obj 82 | *.pch 83 | *.pdb 84 | *.pgc 85 | *.pgd 86 | *.rsp 87 | *.sbr 88 | *.tlb 89 | *.tli 90 | *.tlh 91 | *.tmp 92 | *.vspscc 93 | .builds 94 | *.dotCover 95 | 96 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 97 | #packages/ 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opensdf 104 | *.sdf 105 | 106 | # Visual Studio profiler 107 | *.psess 108 | *.vsp 109 | 110 | # ReSharper is a .NET coding add-in 111 | _ReSharper* 112 | 113 | # Installshield output folder 114 | [Ee]xpress 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish 128 | 129 | # Others 130 | [Bb]in 131 | [Oo]bj 132 | sql 133 | TestResults 134 | *.Cache 135 | ClientBin 136 | stylecop.* 137 | ~$* 138 | *.dbmdl 139 | Generated_Code #added for RIA/Silverlight projects 140 | 141 | # Backup & report files from converting an old project file to a newer 142 | # Visual Studio version. Backup files are not needed, because we have git ;-) 143 | _UpgradeReport_Files/ 144 | Backup*/ 145 | UpgradeLog*.XML 146 | 147 | 148 | ############ 149 | ## Windows 150 | ############ 151 | 152 | # Windows image file caches 153 | Thumbs.db 154 | 155 | # Folder config file 156 | Desktop.ini 157 | 158 | 159 | ############# 160 | ## Python 161 | ############# 162 | 163 | *.py[co] 164 | 165 | # Packages 166 | *.egg 167 | *.egg-info 168 | dist 169 | build 170 | eggs 171 | parts 172 | bin 173 | var 174 | sdist 175 | develop-eggs 176 | .installed.cfg 177 | 178 | # Installer logs 179 | pip-log.txt 180 | 181 | # Unit test / coverage reports 182 | .coverage 183 | .tox 184 | 185 | #Translations 186 | *.mo 187 | 188 | #Mr Developer 189 | .mr.developer.cfg 190 | 191 | # Mac crap 192 | .DS_Store 193 | -------------------------------------------------------------------------------- /src/SFE_BMP180.h: -------------------------------------------------------------------------------- 1 | /* 2 | SFE_BMP180.h 3 | Bosch BMP180 pressure sensor library for the Arduino microcontroller 4 | Mike Grusin, SparkFun Electronics 5 | 6 | Uses floating-point equations from the Weather Station Data Logger project 7 | http://wmrx00.sourceforge.net/ 8 | http://wmrx00.sourceforge.net/Arduino/BMP085-Calcs.pdf 9 | 10 | Forked from BMP085 library by M.Grusin 11 | 12 | version 1.0 2013/09/20 initial version 13 | Verison 1.1.2 - Updated for Arduino 1.6.4 5/2015 14 | 15 | Our example code uses the "beerware" license. You can do anything 16 | you like with this code. No really, anything. If you find it useful, 17 | buy me a (root) beer someday. 18 | */ 19 | 20 | #ifndef SFE_BMP180_h 21 | #define SFE_BMP180_h 22 | 23 | #if defined(ARDUINO) && ARDUINO >= 100 24 | #include "Arduino.h" 25 | #else 26 | #include "WProgram.h" 27 | #endif 28 | 29 | class SFE_BMP180 30 | { 31 | public: 32 | SFE_BMP180(); // base type 33 | 34 | char begin(); 35 | // call pressure.begin() to initialize BMP180 before use 36 | // returns 1 if success, 0 if failure (bad component or I2C bus shorted?) 37 | 38 | char startTemperature(void); 39 | // command BMP180 to start a temperature measurement 40 | // returns (number of ms to wait) for success, 0 for fail 41 | 42 | char getTemperature(double &T); 43 | // return temperature measurement from previous startTemperature command 44 | // places returned value in T variable (deg C) 45 | // returns 1 for success, 0 for fail 46 | 47 | char startPressure(char oversampling); 48 | // command BMP180 to start a pressure measurement 49 | // oversampling: 0 - 3 for oversampling value 50 | // returns (number of ms to wait) for success, 0 for fail 51 | 52 | char getPressure(double &P, double &T); 53 | // return absolute pressure measurement from previous startPressure command 54 | // note: requires previous temperature measurement in variable T 55 | // places returned value in P variable (mbar) 56 | // returns 1 for success, 0 for fail 57 | 58 | double sealevel(double P, double A); 59 | // convert absolute pressure to sea-level pressure (as used in weather data) 60 | // P: absolute pressure (mbar) 61 | // A: current altitude (meters) 62 | // returns sealevel pressure in mbar 63 | 64 | double altitude(double P, double P0); 65 | // convert absolute pressure to altitude (given baseline pressure; sea-level, runway, etc.) 66 | // P: absolute pressure (mbar) 67 | // P0: fixed baseline pressure (mbar) 68 | // returns signed altitude in meters 69 | 70 | char getError(void); 71 | // If any library command fails, you can retrieve an extended 72 | // error code using this command. Errors are from the wire library: 73 | // 0 = Success 74 | // 1 = Data too long to fit in transmit buffer 75 | // 2 = Received NACK on transmit of address 76 | // 3 = Received NACK on transmit of data 77 | // 4 = Other error 78 | 79 | private: 80 | 81 | char readInt(char address, int16_t &value); 82 | // read an signed int (16 bits) from a BMP180 register 83 | // address: BMP180 register address 84 | // value: external signed int for returned value (16 bits) 85 | // returns 1 for success, 0 for fail, with result in value 86 | 87 | char readUInt(char address, uint16_t &value); 88 | // read an unsigned int (16 bits) from a BMP180 register 89 | // address: BMP180 register address 90 | // value: external unsigned int for returned value (16 bits) 91 | // returns 1 for success, 0 for fail, with result in value 92 | 93 | char readBytes(unsigned char *values, char length); 94 | // read a number of bytes from a BMP180 register 95 | // values: array of char with register address in first location [0] 96 | // length: number of bytes to read back 97 | // returns 1 for success, 0 for fail, with read bytes in values[] array 98 | 99 | char writeBytes(unsigned char *values, char length); 100 | // write a number of bytes to a BMP180 register (and consecutive subsequent registers) 101 | // values: array of char with register address in first location [0] 102 | // length: number of bytes to write 103 | // returns 1 for success, 0 for fail 104 | 105 | int16_t AC1,AC2,AC3,VB1,VB2,MB,MC,MD; 106 | uint16_t AC4,AC5,AC6; 107 | double c5,c6,mc,md,x0,x1,x2,y0,y1,y2,p0,p1,p2; 108 | char _error; 109 | }; 110 | 111 | #define BMP180_ADDR 0x77 // 7-bit address 112 | 113 | #define BMP180_REG_CONTROL 0xF4 114 | #define BMP180_REG_RESULT 0xF6 115 | 116 | #define BMP180_COMMAND_TEMPERATURE 0x2E 117 | #define BMP180_COMMAND_PRESSURE0 0x34 118 | #define BMP180_COMMAND_PRESSURE1 0x74 119 | #define BMP180_COMMAND_PRESSURE2 0xB4 120 | #define BMP180_COMMAND_PRESSURE3 0xF4 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /examples/BMP180_altitude_example/BMP180_altitude_example.ino: -------------------------------------------------------------------------------- 1 | /* SFE_BMP180 altitude example sketch 2 | 3 | This sketch shows how to use the Bosch BMP180 pressure sensor 4 | as an altimiter. 5 | https://www.sparkfun.com/products/11824 6 | 7 | Like most pressure sensors, the BMP180 measures absolute pressure. 8 | Since absolute pressure varies with altitude, you can use the pressure 9 | to determine your altitude. 10 | 11 | Because pressure also varies with weather, you must first take a pressure 12 | reading at a known baseline altitude. Then you can measure variations 13 | from that pressure 14 | 15 | Hardware connections: 16 | 17 | - (GND) to GND 18 | + (VDD) to 3.3V 19 | 20 | (WARNING: do not connect + to 5V or the sensor will be damaged!) 21 | 22 | You will also need to connect the I2C pins (SCL and SDA) to your 23 | Arduino. The pins are different on different Arduinos: 24 | 25 | Any Arduino pins labeled: SDA SCL 26 | Uno, Redboard, Pro: A4 A5 27 | Mega2560, Due: 20 21 28 | Leonardo: 2 3 29 | 30 | Leave the IO (VDDIO) pin unconnected. This pin is for connecting 31 | the BMP180 to systems with lower logic levels such as 1.8V 32 | 33 | Have fun! -Your friends at SparkFun. 34 | 35 | The SFE_BMP180 library uses floating-point equations developed by the 36 | Weather Station Data Logger project: http://wmrx00.sourceforge.net/ 37 | 38 | Our example code uses the "beerware" license. You can do anything 39 | you like with this code. No really, anything. If you find it useful, 40 | buy me a beer someday. 41 | 42 | V10 Mike Grusin, SparkFun Electronics 10/24/2013 43 | V1.1.2 Updates for Arduino 1.6.4 5/2015 44 | */ 45 | 46 | // Your sketch must #include this library, and the Wire library. 47 | // (Wire is a standard library included with Arduino.): 48 | 49 | #include 50 | #include 51 | 52 | // You will need to create an SFE_BMP180 object, here called "pressure": 53 | 54 | SFE_BMP180 pressure; 55 | 56 | double baseline; // baseline pressure 57 | 58 | void setup() 59 | { 60 | Serial.begin(9600); 61 | Serial.println("REBOOT"); 62 | 63 | // Initialize the sensor (it is important to get calibration values stored on the device). 64 | 65 | if (pressure.begin()) 66 | Serial.println("BMP180 init success"); 67 | else 68 | { 69 | // Oops, something went wrong, this is usually a connection problem, 70 | // see the comments at the top of this sketch for the proper connections. 71 | 72 | Serial.println("BMP180 init fail (disconnected?)\n\n"); 73 | while(1); // Pause forever. 74 | } 75 | 76 | // Get the baseline pressure: 77 | 78 | baseline = getPressure(); 79 | 80 | Serial.print("baseline pressure: "); 81 | Serial.print(baseline); 82 | Serial.println(" mb"); 83 | } 84 | 85 | void loop() 86 | { 87 | double a,P; 88 | 89 | // Get a new pressure reading: 90 | 91 | P = getPressure(); 92 | 93 | // Show the relative altitude difference between 94 | // the new reading and the baseline reading: 95 | 96 | a = pressure.altitude(P,baseline); 97 | 98 | Serial.print("relative altitude: "); 99 | if (a >= 0.0) Serial.print(" "); // add a space for positive numbers 100 | Serial.print(a,1); 101 | Serial.print(" meters, "); 102 | if (a >= 0.0) Serial.print(" "); // add a space for positive numbers 103 | Serial.print(a*3.28084,0); 104 | Serial.println(" feet"); 105 | 106 | delay(500); 107 | } 108 | 109 | 110 | double getPressure() 111 | { 112 | char status; 113 | double T,P,p0,a; 114 | 115 | // You must first get a temperature measurement to perform a pressure reading. 116 | 117 | // Start a temperature measurement: 118 | // If request is successful, the number of ms to wait is returned. 119 | // If request is unsuccessful, 0 is returned. 120 | 121 | status = pressure.startTemperature(); 122 | if (status != 0) 123 | { 124 | // Wait for the measurement to complete: 125 | 126 | delay(status); 127 | 128 | // Retrieve the completed temperature measurement: 129 | // Note that the measurement is stored in the variable T. 130 | // Use '&T' to provide the address of T to the function. 131 | // Function returns 1 if successful, 0 if failure. 132 | 133 | status = pressure.getTemperature(T); 134 | if (status != 0) 135 | { 136 | // Start a pressure measurement: 137 | // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait). 138 | // If request is successful, the number of ms to wait is returned. 139 | // If request is unsuccessful, 0 is returned. 140 | 141 | status = pressure.startPressure(3); 142 | if (status != 0) 143 | { 144 | // Wait for the measurement to complete: 145 | delay(status); 146 | 147 | // Retrieve the completed pressure measurement: 148 | // Note that the measurement is stored in the variable P. 149 | // Use '&P' to provide the address of P. 150 | // Note also that the function requires the previous temperature measurement (T). 151 | // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.) 152 | // Function returns 1 if successful, 0 if failure. 153 | 154 | status = pressure.getPressure(P,T); 155 | if (status != 0) 156 | { 157 | return(P); 158 | } 159 | else Serial.println("error retrieving pressure measurement\n"); 160 | } 161 | else Serial.println("error starting pressure measurement\n"); 162 | } 163 | else Serial.println("error retrieving temperature measurement\n"); 164 | } 165 | else Serial.println("error starting temperature measurement\n"); 166 | } 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /examples/SFE_BMP180_example/SFE_BMP180_example.ino: -------------------------------------------------------------------------------- 1 | /* SFE_BMP180 library example sketch 2 | 3 | This sketch shows how to use the SFE_BMP180 library to read the 4 | Bosch BMP180 barometric pressure sensor. 5 | https://www.sparkfun.com/products/11824 6 | 7 | Like most pressure sensors, the BMP180 measures absolute pressure. 8 | This is the actual ambient pressure seen by the device, which will 9 | vary with both altitude and weather. 10 | 11 | Before taking a pressure reading you must take a temparture reading. 12 | This is done with startTemperature() and getTemperature(). 13 | The result is in degrees C. 14 | 15 | Once you have a temperature reading, you can take a pressure reading. 16 | This is done with startPressure() and getPressure(). 17 | The result is in millibar (mb) aka hectopascals (hPa). 18 | 19 | If you'll be monitoring weather patterns, you will probably want to 20 | remove the effects of altitude. This will produce readings that can 21 | be compared to the published pressure readings from other locations. 22 | To do this, use the sealevel() function. You will need to provide 23 | the known altitude at which the pressure was measured. 24 | 25 | If you want to measure altitude, you will need to know the pressure 26 | at a baseline altitude. This can be average sealevel pressure, or 27 | a previous pressure reading at your altitude, in which case 28 | subsequent altitude readings will be + or - the initial baseline. 29 | This is done with the altitude() function. 30 | 31 | Hardware connections: 32 | 33 | - (GND) to GND 34 | + (VDD) to 3.3V 35 | 36 | (WARNING: do not connect + to 5V or the sensor will be damaged!) 37 | 38 | You will also need to connect the I2C pins (SCL and SDA) to your 39 | Arduino. The pins are different on different Arduinos: 40 | 41 | Any Arduino pins labeled: SDA SCL 42 | Uno, Redboard, Pro: A4 A5 43 | Mega2560, Due: 20 21 44 | Leonardo: 2 3 45 | 46 | Leave the IO (VDDIO) pin unconnected. This pin is for connecting 47 | the BMP180 to systems with lower logic levels such as 1.8V 48 | 49 | Have fun! -Your friends at SparkFun. 50 | 51 | The SFE_BMP180 library uses floating-point equations developed by the 52 | Weather Station Data Logger project: http://wmrx00.sourceforge.net/ 53 | 54 | Our example code uses the "beerware" license. You can do anything 55 | you like with this code. No really, anything. If you find it useful, 56 | buy me a beer someday. 57 | 58 | V10 Mike Grusin, SparkFun Electronics 10/24/2013 59 | V1.1.2 Updates for Arduino 1.6.4 5/2015 60 | */ 61 | 62 | // Your sketch must #include this library, and the Wire library. 63 | // (Wire is a standard library included with Arduino.): 64 | 65 | #include 66 | #include 67 | 68 | // You will need to create an SFE_BMP180 object, here called "pressure": 69 | 70 | SFE_BMP180 pressure; 71 | 72 | #define ALTITUDE 1655.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters 73 | 74 | void setup() 75 | { 76 | Serial.begin(9600); 77 | Serial.println("REBOOT"); 78 | 79 | // Initialize the sensor (it is important to get calibration values stored on the device). 80 | 81 | if (pressure.begin()) 82 | Serial.println("BMP180 init success"); 83 | else 84 | { 85 | // Oops, something went wrong, this is usually a connection problem, 86 | // see the comments at the top of this sketch for the proper connections. 87 | 88 | Serial.println("BMP180 init fail\n\n"); 89 | while(1); // Pause forever. 90 | } 91 | } 92 | 93 | void loop() 94 | { 95 | char status; 96 | double T,P,p0,a; 97 | 98 | // Loop here getting pressure readings every 10 seconds. 99 | 100 | // If you want sea-level-compensated pressure, as used in weather reports, 101 | // you will need to know the altitude at which your measurements are taken. 102 | // We're using a constant called ALTITUDE in this sketch: 103 | 104 | Serial.println(); 105 | Serial.print("provided altitude: "); 106 | Serial.print(ALTITUDE,0); 107 | Serial.print(" meters, "); 108 | Serial.print(ALTITUDE*3.28084,0); 109 | Serial.println(" feet"); 110 | 111 | // If you want to measure altitude, and not pressure, you will instead need 112 | // to provide a known baseline pressure. This is shown at the end of the sketch. 113 | 114 | // You must first get a temperature measurement to perform a pressure reading. 115 | 116 | // Start a temperature measurement: 117 | // If request is successful, the number of ms to wait is returned. 118 | // If request is unsuccessful, 0 is returned. 119 | 120 | status = pressure.startTemperature(); 121 | if (status != 0) 122 | { 123 | // Wait for the measurement to complete: 124 | delay(status); 125 | 126 | // Retrieve the completed temperature measurement: 127 | // Note that the measurement is stored in the variable T. 128 | // Function returns 1 if successful, 0 if failure. 129 | 130 | status = pressure.getTemperature(T); 131 | if (status != 0) 132 | { 133 | // Print out the measurement: 134 | Serial.print("temperature: "); 135 | Serial.print(T,2); 136 | Serial.print(" deg C, "); 137 | Serial.print((9.0/5.0)*T+32.0,2); 138 | Serial.println(" deg F"); 139 | 140 | // Start a pressure measurement: 141 | // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait). 142 | // If request is successful, the number of ms to wait is returned. 143 | // If request is unsuccessful, 0 is returned. 144 | 145 | status = pressure.startPressure(3); 146 | if (status != 0) 147 | { 148 | // Wait for the measurement to complete: 149 | delay(status); 150 | 151 | // Retrieve the completed pressure measurement: 152 | // Note that the measurement is stored in the variable P. 153 | // Note also that the function requires the previous temperature measurement (T). 154 | // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.) 155 | // Function returns 1 if successful, 0 if failure. 156 | 157 | status = pressure.getPressure(P,T); 158 | if (status != 0) 159 | { 160 | // Print out the measurement: 161 | Serial.print("absolute pressure: "); 162 | Serial.print(P,2); 163 | Serial.print(" mb, "); 164 | Serial.print(P*0.0295333727,2); 165 | Serial.println(" inHg"); 166 | 167 | // The pressure sensor returns abolute pressure, which varies with altitude. 168 | // To remove the effects of altitude, use the sealevel function and your current altitude. 169 | // This number is commonly used in weather reports. 170 | // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m. 171 | // Result: p0 = sea-level compensated pressure in mb 172 | 173 | p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO) 174 | Serial.print("relative (sea-level) pressure: "); 175 | Serial.print(p0,2); 176 | Serial.print(" mb, "); 177 | Serial.print(p0*0.0295333727,2); 178 | Serial.println(" inHg"); 179 | 180 | // On the other hand, if you want to determine your altitude from the pressure reading, 181 | // use the altitude function along with a baseline pressure (sea-level or other). 182 | // Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb. 183 | // Result: a = altitude in m. 184 | 185 | a = pressure.altitude(P,p0); 186 | Serial.print("computed altitude: "); 187 | Serial.print(a,0); 188 | Serial.print(" meters, "); 189 | Serial.print(a*3.28084,0); 190 | Serial.println(" feet"); 191 | } 192 | else Serial.println("error retrieving pressure measurement\n"); 193 | } 194 | else Serial.println("error starting pressure measurement\n"); 195 | } 196 | else Serial.println("error retrieving temperature measurement\n"); 197 | } 198 | else Serial.println("error starting temperature measurement\n"); 199 | 200 | delay(5000); // Pause for 5 seconds. 201 | } 202 | -------------------------------------------------------------------------------- /src/SFE_BMP180.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | SFE_BMP180.cpp 3 | Bosch BMP180 pressure sensor library for the Arduino microcontroller 4 | Mike Grusin, SparkFun Electronics 5 | 6 | Uses floating-point equations from the Weather Station Data Logger project 7 | http://wmrx00.sourceforge.net/ 8 | http://wmrx00.sourceforge.net/Arduino/BMP085-Calcs.pdf 9 | 10 | Forked from BMP085 library by M.Grusin 11 | 12 | version 1.0 2013/09/20 initial version 13 | Verison 1.1.2 - Updated for Arduino 1.6.4 5/2015 14 | 15 | Our example code uses the "beerware" license. You can do anything 16 | you like with this code. No really, anything. If you find it useful, 17 | buy me a (root) beer someday. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | SFE_BMP180::SFE_BMP180() 27 | // Base library type 28 | { 29 | } 30 | 31 | 32 | char SFE_BMP180::begin() 33 | // Initialize library for subsequent pressure measurements 34 | { 35 | double c3,c4,b1; 36 | 37 | // Start up the Arduino's "wire" (I2C) library: 38 | 39 | Wire.begin(); 40 | 41 | // The BMP180 includes factory calibration data stored on the device. 42 | // Each device has different numbers, these must be retrieved and 43 | // used in the calculations when taking pressure measurements. 44 | 45 | // Retrieve calibration data from device: 46 | 47 | if (readInt(0xAA,AC1) && 48 | readInt(0xAC,AC2) && 49 | readInt(0xAE,AC3) && 50 | readUInt(0xB0,AC4) && 51 | readUInt(0xB2,AC5) && 52 | readUInt(0xB4,AC6) && 53 | readInt(0xB6,VB1) && 54 | readInt(0xB8,VB2) && 55 | readInt(0xBA,MB) && 56 | readInt(0xBC,MC) && 57 | readInt(0xBE,MD)) 58 | { 59 | 60 | // All reads completed successfully! 61 | 62 | // If you need to check your math using known numbers, 63 | // you can uncomment one of these examples. 64 | // (The correct results are commented in the below functions.) 65 | 66 | // Example from Bosch datasheet 67 | // AC1 = 408; AC2 = -72; AC3 = -14383; AC4 = 32741; AC5 = 32757; AC6 = 23153; 68 | // B1 = 6190; B2 = 4; MB = -32768; MC = -8711; MD = 2868; 69 | 70 | // Example from http://wmrx00.sourceforge.net/Arduino/BMP180-Calcs.pdf 71 | // AC1 = 7911; AC2 = -934; AC3 = -14306; AC4 = 31567; AC5 = 25671; AC6 = 18974; 72 | // VB1 = 5498; VB2 = 46; MB = -32768; MC = -11075; MD = 2432; 73 | 74 | /* 75 | Serial.print("AC1: "); Serial.println(AC1); 76 | Serial.print("AC2: "); Serial.println(AC2); 77 | Serial.print("AC3: "); Serial.println(AC3); 78 | Serial.print("AC4: "); Serial.println(AC4); 79 | Serial.print("AC5: "); Serial.println(AC5); 80 | Serial.print("AC6: "); Serial.println(AC6); 81 | Serial.print("VB1: "); Serial.println(VB1); 82 | Serial.print("VB2: "); Serial.println(VB2); 83 | Serial.print("MB: "); Serial.println(MB); 84 | Serial.print("MC: "); Serial.println(MC); 85 | Serial.print("MD: "); Serial.println(MD); 86 | */ 87 | 88 | // Compute floating-point polynominals: 89 | 90 | c3 = 160.0 * pow(2,-15) * AC3; 91 | c4 = pow(10,-3) * pow(2,-15) * AC4; 92 | b1 = pow(160,2) * pow(2,-30) * VB1; 93 | c5 = (pow(2,-15) / 160) * AC5; 94 | c6 = AC6; 95 | mc = (pow(2,11) / pow(160,2)) * MC; 96 | md = MD / 160.0; 97 | x0 = AC1; 98 | x1 = 160.0 * pow(2,-13) * AC2; 99 | x2 = pow(160,2) * pow(2,-25) * VB2; 100 | y0 = c4 * pow(2,15); 101 | y1 = c4 * c3; 102 | y2 = c4 * b1; 103 | p0 = (3791.0 - 8.0) / 1600.0; 104 | p1 = 1.0 - 7357.0 * pow(2,-20); 105 | p2 = 3038.0 * 100.0 * pow(2,-36); 106 | 107 | /* 108 | Serial.println(); 109 | Serial.print("c3: "); Serial.println(c3); 110 | Serial.print("c4: "); Serial.println(c4); 111 | Serial.print("c5: "); Serial.println(c5); 112 | Serial.print("c6: "); Serial.println(c6); 113 | Serial.print("b1: "); Serial.println(b1); 114 | Serial.print("mc: "); Serial.println(mc); 115 | Serial.print("md: "); Serial.println(md); 116 | Serial.print("x0: "); Serial.println(x0); 117 | Serial.print("x1: "); Serial.println(x1); 118 | Serial.print("x2: "); Serial.println(x2); 119 | Serial.print("y0: "); Serial.println(y0); 120 | Serial.print("y1: "); Serial.println(y1); 121 | Serial.print("y2: "); Serial.println(y2); 122 | Serial.print("p0: "); Serial.println(p0); 123 | Serial.print("p1: "); Serial.println(p1); 124 | Serial.print("p2: "); Serial.println(p2); 125 | */ 126 | 127 | // Success! 128 | return(1); 129 | } 130 | else 131 | { 132 | // Error reading calibration data; bad component or connection? 133 | return(0); 134 | } 135 | } 136 | 137 | 138 | char SFE_BMP180::readInt(char address, int16_t &value) 139 | // Read a signed integer (two bytes) from device 140 | // address: register to start reading (plus subsequent register) 141 | // value: external variable to store data (function modifies value) 142 | { 143 | unsigned char data[2]; 144 | 145 | data[0] = address; 146 | if (readBytes(data,2)) 147 | { 148 | value = (int16_t)((data[0]<<8)|data[1]); 149 | //if (*value & 0x8000) *value |= 0xFFFF0000; // sign extend if negative 150 | return(1); 151 | } 152 | value = 0; 153 | return(0); 154 | } 155 | 156 | 157 | char SFE_BMP180::readUInt(char address, uint16_t &value) 158 | // Read an unsigned integer (two bytes) from device 159 | // address: register to start reading (plus subsequent register) 160 | // value: external variable to store data (function modifies value) 161 | { 162 | unsigned char data[2]; 163 | 164 | data[0] = address; 165 | if (readBytes(data,2)) 166 | { 167 | value = (((uint16_t)data[0]<<8)|(uint16_t)data[1]); 168 | return(1); 169 | } 170 | value = 0; 171 | return(0); 172 | } 173 | 174 | 175 | char SFE_BMP180::readBytes(unsigned char *values, char length) 176 | // Read an array of bytes from device 177 | // values: external array to hold data. Put starting register in values[0]. 178 | // length: number of bytes to read 179 | { 180 | char x; 181 | 182 | Wire.beginTransmission(BMP180_ADDR); 183 | Wire.write(values[0]); 184 | _error = Wire.endTransmission(); 185 | if (_error == 0) 186 | { 187 | Wire.requestFrom(BMP180_ADDR,length); 188 | while(Wire.available() != length) ; // wait until bytes are ready 189 | for(x=0;x