Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 2:34a32898cd23, committed 2017-08-25
- Comitter:
- mcm
- Date:
- Fri Aug 25 14:16:15 2017 +0000
- Parent:
- 1:01aeefb5f4cf
- Commit message:
- The library is ready, it was tested successfully and it works as expected.
Changed in this revision
BMP085.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/BMP085.h Fri Aug 25 13:30:28 2017 +0000 +++ b/BMP085.h Fri Aug 25 14:16:15 2017 +0000 @@ -19,6 +19,83 @@ #include "mbed.h" +/** + Example: + +#include "mbed.h" +#include "BMP085.h" + +BMP085 myBarometricSensor ( I2C_SDA, I2C_SCL, BMP085::BMP085_ADDRESS, 400000 ); +Serial pc ( USBTX, USBRX ); // tx, rx + + +Ticker serial; + +DigitalOut myled(LED1); + +BMP085::Vector_cal_coeff_t myCalCoeff; +BMP085::Vector_temp_f myUT; +BMP085::Vector_pressure_f myUP; +BMP085::Vector_compensated_data_f myTrueData; + +uint32_t myState = 0; + +void sendDATA ( void ) +{ + switch ( myState ) { + case 0: + // Trigger a new temperature measurement + myBarometricSensor.BMP085_TriggerTemperature (); + myState = 1; + break; + + case 1: + // Read the uncompensated temperature data and trigger a new pressure measurement + myBarometricSensor.BMP085_ReadRawTemperature ( &myUT ); + myBarometricSensor.BMP085_TriggerPressure ( BMP085::PRESSURE_STANDARD_MODE ); + myState = 2; + break; + + case 2: + // Read the uncompensated pressure data, calculate the compensated temperature and pressure and send it through the UART + myled = 1; + myBarometricSensor.BMP085_ReadRawPressure ( &myUP ); + + myTrueData = myBarometricSensor.BMP085_CalculateCompensated_Temperature_Pressure ( myCalCoeff, myUT, myUP, BMP085::PRESSURE_STANDARD_MODE ); + + pc.printf( "Temperature: %0.1f\nPressure: %ld\r\n", ( float )myTrueData.Temperature/10, myTrueData.Pressure ); + myled = 0; + myState = 0; + break; + + default: + myState = 0; + break; + } + +} + + +int main() +{ + pc.baud ( 115200 ); + + myBarometricSensor.BMP085_GetCalibrationCoefficients ( &myCalCoeff ); + + // Print the calibration coefficients + pc.printf( "AC1: %ld\nAC2: %ld\nAC3: %ld\nAC4: %ld\nAC5: %ld\nAC6: %ld\nB1: %ld\nB2: %ld\nMB: %ld\nMC: %ld\nMD: %ld\r\n", + myCalCoeff.AC1, myCalCoeff.AC2, myCalCoeff.AC3, myCalCoeff.AC4, myCalCoeff.AC5, myCalCoeff.AC6, myCalCoeff.B1, + myCalCoeff.B2, myCalCoeff.MB, myCalCoeff.MC, myCalCoeff.MD ); + + + serial.attach( &sendDATA, 1 ); // the address of the function to be attached ( sendDATA ) and the interval ( 1s ) + + // Let the callbacks take care of everything + while(1) sleep(); +} +*/ + + /*! Library for the BMP085 Digital Pressure Sensor. */ @@ -29,7 +106,7 @@ * @brief DEFAULT ADDRESSES */ typedef enum { - BMP085_ADDRESS = 0x77 + BMP085_ADDRESS = ( 0x77 << 1 ) } BMP085_address_t; @@ -135,43 +212,43 @@ - /** Create an BMP085 object connected to the specified I2C pins. - * - * @param sda I2C data pin - * @param scl I2C clock pin - * @param addr I2C slave address - * @param freq I2C frequency in Hz. - */ + /** Create an BMP085 object connected to the specified I2C pins. + * + * @param sda I2C data pin + * @param scl I2C clock pin + * @param addr I2C slave address + * @param freq I2C frequency in Hz. + */ BMP085 ( PinName sda, PinName scl, uint32_t addr, uint32_t freq ); /** Delete BMP085 object. */ ~BMP085(); - + /** It gets the calibration coefficients. */ BMP085_status_t BMP085_GetCalibrationCoefficients ( Vector_cal_coeff_t* myCalCoeff ); - + /** It triggers a new temperature mesurement. */ BMP085_status_t BMP085_TriggerTemperature ( void ); - + /** It reads the raw temperature value. */ BMP085_status_t BMP085_ReadRawTemperature ( Vector_temp_f* myRawTemperature ); - + /** It reads the compensated/true temperature. NOT RECOMMENDED, use BMP085_CalculateCompensated_Temperature_Pressure instead! */ BMP085_status_t BMP085_ReadCompensatedTemperature ( Vector_temp_f* myTrueTemperature, Vector_cal_coeff_t myCalCoeff ); - + /** It triggers a new pressure mesurement. */ BMP085_status_t BMP085_TriggerPressure ( BMP085_pressure_osrs_t myResolution ); - + /** It reads the raw pressure value. */ BMP085_status_t BMP085_ReadRawPressure ( Vector_pressure_f* myRawPressure ); - + /** It calculates the compensated/true temperature and pressure values. */ Vector_compensated_data_f BMP085_CalculateCompensated_Temperature_Pressure ( Vector_cal_coeff_t myCalCoeff, Vector_temp_f myRawTemperature, Vector_pressure_f myRawPressure,