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.
Dependencies: mbed
main.cpp@1:a94ff5f08fd7, 2020-02-21 (annotated)
- Committer:
- altb2
- Date:
- Fri Feb 21 07:30:50 2020 +0000
- Revision:
- 1:a94ff5f08fd7
- Parent:
- 0:7c23db660183
- Child:
- 2:4d9204790be1
See Comments in Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
altb2 | 0:7c23db660183 | 1 | /* MS5611 Pressure sensor example |
altb2 | 0:7c23db660183 | 2 | Aerodyne Labs |
altb2 | 0:7c23db660183 | 3 | 2014 |
altb2 | 0:7c23db660183 | 4 | |
altb2 | 0:7c23db660183 | 5 | This example uses the MS511 Library to read the temperature and pressure readings |
altb2 | 0:7c23db660183 | 6 | from the MS5611 sensor. It has been modified from the MS507 sensor library with |
altb2 | 0:7c23db660183 | 7 | the different calculations that the MS5611 requires. Otherwise, this library is |
altb2 | 0:7c23db660183 | 8 | identical to the MS5607 |
altb2 | 1:a94ff5f08fd7 | 9 | ------------ |
altb2 | 1:a94ff5f08fd7 | 10 | IndNav: Made adaptions, even though, the original works well, problem: |
altb2 | 1:a94ff5f08fd7 | 11 | the original has a delay of 8ms from writing to reading (see line 73 in MS5611I2C.h) |
altb2 | 1:a94ff5f08fd7 | 12 | Solution: seperate write and read in 2 processes (hene's hint): |
altb2 | 1:a94ff5f08fd7 | 13 | - write at end of data_read thread, without waiting |
altb2 | 1:a94ff5f08fd7 | 14 | - at beginning of next call, read the data |
altb2 | 1:a94ff5f08fd7 | 15 | since there are 2 seperate reading/writings (one for pressure(altitude), one for Temperature -and we need both!) |
altb2 | 1:a94ff5f08fd7 | 16 | toggle the 2 processes, this results, that only every 2nd pressure/altitude value is a new value! |
altb2 | 1:a94ff5f08fd7 | 17 | |
altb2 | 1:a94ff5f08fd7 | 18 | altb 20.2.2020 |
altb2 | 0:7c23db660183 | 19 | */ |
altb2 | 0:7c23db660183 | 20 | #include "mbed.h" |
altb2 | 0:7c23db660183 | 21 | |
altb2 | 0:7c23db660183 | 22 | //Only uncomment the one needed. |
altb2 | 0:7c23db660183 | 23 | //#include "MS5611SPI.h" |
altb2 | 0:7c23db660183 | 24 | #include "MS5611I2C.h" |
altb2 | 0:7c23db660183 | 25 | |
altb2 | 0:7c23db660183 | 26 | Serial pc(USBTX, USBRX); // local terminal interface |
altb2 | 1:a94ff5f08fd7 | 27 | Timer timer; |
altb2 | 1:a94ff5f08fd7 | 28 | |
altb2 | 0:7c23db660183 | 29 | int main() { |
altb2 | 0:7c23db660183 | 30 | pc.baud(115200); // set up USB serial speed |
altb2 | 1:a94ff5f08fd7 | 31 | timer.reset(); |
altb2 | 1:a94ff5f08fd7 | 32 | timer.start(); |
altb2 | 0:7c23db660183 | 33 | //Only uncomment the I2C or SPI version. |
altb2 | 0:7c23db660183 | 34 | //MS5611SPI ms5611(p11, p12, p13, p10); |
altb2 | 0:7c23db660183 | 35 | //MS5611I2C ms5611(p9, p10, false); |
altb2 | 0:7c23db660183 | 36 | //PB_9 and PB_8 for Nucleo boards |
altb2 | 0:7c23db660183 | 37 | I2C i2c(PB_3,PB_10); |
altb2 | 0:7c23db660183 | 38 | MS5611I2C ms5611(i2c, false); |
altb2 | 0:7c23db660183 | 39 | //Print the Coefficients from the |
altb2 | 0:7c23db660183 | 40 | ms5611.printCoefficients(); |
altb2 | 0:7c23db660183 | 41 | while(1){ |
altb2 | 1:a94ff5f08fd7 | 42 | timer.reset(); |
altb2 | 1:a94ff5f08fd7 | 43 | // float dum2 = ms5611.getTemperature(); |
altb2 | 1:a94ff5f08fd7 | 44 | // float dum3 = ms5611.getAltitude(); |
altb2 | 1:a94ff5f08fd7 | 45 | // printf("10 Durchlaeufe: %f sec \r\n", T); |
altb2 | 1:a94ff5f08fd7 | 46 | // printf("Pressure = %.0f Pa \r\n", ms5611.getPressure()); |
altb2 | 1:a94ff5f08fd7 | 47 | // printf("Temperature = %.2f degC \r\n", ms5611.getTemperature()); |
altb2 | 1:a94ff5f08fd7 | 48 | ms5611.getAltitude_toggle_Temp_write(); |
altb2 | 1:a94ff5f08fd7 | 49 | wait_ms(100); |
altb2 | 1:a94ff5f08fd7 | 50 | printf("Altitude = %.2f m \r\n", ms5611.getAltitude_toggle_Temp_read()); |
altb2 | 1:a94ff5f08fd7 | 51 | float T = timer.read(); |
altb2 | 1:a94ff5f08fd7 | 52 | wait(1.0); |
altb2 | 0:7c23db660183 | 53 | } |
altb2 | 0:7c23db660183 | 54 | } |