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.
baro_main.cpp@6:d4c401190320, 2019-09-15 (annotated)
- Committer:
- tenvinc
- Date:
- Sun Sep 15 13:13:10 2019 +0000
- Revision:
- 6:d4c401190320
- Parent:
- 4:26530d450402
add main.cpp from spo2 sample
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tenvinc | 4:26530d450402 | 1 | #include "mbed.h" |
tenvinc | 4:26530d450402 | 2 | #include "MAX14720.h" |
tenvinc | 4:26530d450402 | 3 | #include "MAX30205.h" |
tenvinc | 4:26530d450402 | 4 | #include "BMP280.h" |
tenvinc | 4:26530d450402 | 5 | #include "USBSerial.h" |
tenvinc | 4:26530d450402 | 6 | //#include "MAX30001.h" |
tenvinc | 4:26530d450402 | 7 | //#include "QuadSpiInterface.h" |
tenvinc | 4:26530d450402 | 8 | //#include "S25FS512.h" |
tenvinc | 4:26530d450402 | 9 | //#include "MAX30101.h" |
tenvinc | 4:26530d450402 | 10 | |
tenvinc | 4:26530d450402 | 11 | //Define all I2C addresses |
tenvinc | 4:26530d450402 | 12 | #define MAX30205_I2C_SLAVE_ADDR_TOP (0x92) |
tenvinc | 4:26530d450402 | 13 | #define MAX30205_I2C_SLAVE_ADDR_BOTTOM (0x90) |
tenvinc | 4:26530d450402 | 14 | #define MAX14720_I2C_SLAVE_ADDR (0x54) |
tenvinc | 4:26530d450402 | 15 | #define BMP280_I2C_SLAVE_ADDR (0xEC) |
tenvinc | 4:26530d450402 | 16 | |
tenvinc | 4:26530d450402 | 17 | |
tenvinc | 4:26530d450402 | 18 | #define HVOUT_VOLTAGE 4500 // set to 4500 mV |
tenvinc | 4:26530d450402 | 19 | |
tenvinc | 4:26530d450402 | 20 | // Define with Maxim VID and a Maxim assigned PID, set to version 0x0001 and non-blocking |
tenvinc | 4:26530d450402 | 21 | USBSerial usbSerial(0x0b6a, 0x0100, 0x0001, false); |
tenvinc | 4:26530d450402 | 22 | |
tenvinc | 4:26530d450402 | 23 | // I2C Masters |
tenvinc | 4:26530d450402 | 24 | I2C i2c1(I2C1_SDA, I2C1_SCL); |
tenvinc | 4:26530d450402 | 25 | I2C i2c2(I2C2_SDA, I2C2_SCL); |
tenvinc | 4:26530d450402 | 26 | |
tenvinc | 4:26530d450402 | 27 | // Top local Temperature Sensor |
tenvinc | 4:26530d450402 | 28 | MAX30205 MAX30205_top(&i2c1, MAX30205_I2C_SLAVE_ADDR_TOP); |
tenvinc | 4:26530d450402 | 29 | |
tenvinc | 4:26530d450402 | 30 | // Botttom local Temperature Sensor |
tenvinc | 4:26530d450402 | 31 | MAX30205 MAX30205_bottom(&i2c1, MAX30205_I2C_SLAVE_ADDR_BOTTOM); |
tenvinc | 4:26530d450402 | 32 | |
tenvinc | 4:26530d450402 | 33 | // Barometric Pressure Sensor |
tenvinc | 4:26530d450402 | 34 | BMP280 bmp280_pres(&i2c1, BMP280_I2C_SLAVE_ADDR); |
tenvinc | 4:26530d450402 | 35 | |
tenvinc | 4:26530d450402 | 36 | //PMIC |
tenvinc | 4:26530d450402 | 37 | MAX14720 max14720(&i2c2,MAX14720_I2C_SLAVE_ADDR); |
tenvinc | 4:26530d450402 | 38 | |
tenvinc | 4:26530d450402 | 39 | ///// External Flash |
tenvinc | 4:26530d450402 | 40 | //S25FS512 s25fs512(&quadSpiInterface); |
tenvinc | 4:26530d450402 | 41 | |
tenvinc | 4:26530d450402 | 42 | /// PWM used as fclk for the MAX30001 |
tenvinc | 4:26530d450402 | 43 | PwmOut pwmout(P1_7); |
tenvinc | 4:26530d450402 | 44 | |
tenvinc | 4:26530d450402 | 45 | |
tenvinc | 4:26530d450402 | 46 | DigitalOut led(LED1); |
tenvinc | 4:26530d450402 | 47 | |
tenvinc | 4:26530d450402 | 48 | |
tenvinc | 4:26530d450402 | 49 | void turnOff() |
tenvinc | 4:26530d450402 | 50 | { |
tenvinc | 4:26530d450402 | 51 | //write the power down command to PMIC |
tenvinc | 4:26530d450402 | 52 | max14720.shutdown(); |
tenvinc | 4:26530d450402 | 53 | } |
tenvinc | 4:26530d450402 | 54 | int main() |
tenvinc | 4:26530d450402 | 55 | { |
tenvinc | 4:26530d450402 | 56 | |
tenvinc | 4:26530d450402 | 57 | // Override the default value of boostEn to BOOST_ENABLED |
tenvinc | 4:26530d450402 | 58 | max14720.boostEn = MAX14720::BOOST_ENABLED; |
tenvinc | 4:26530d450402 | 59 | // Note that writing the local value does directly affect the part |
tenvinc | 4:26530d450402 | 60 | // The buck-boost regulator will remain off until init is called |
tenvinc | 4:26530d450402 | 61 | max14720.init(); |
tenvinc | 4:26530d450402 | 62 | // Turn LED signal on to make buck-boost output visible |
tenvinc | 4:26530d450402 | 63 | max14720.boostSetVoltage(HVOUT_VOLTAGE); |
tenvinc | 4:26530d450402 | 64 | led = 0; |
tenvinc | 4:26530d450402 | 65 | |
tenvinc | 4:26530d450402 | 66 | // Initialise the BMP280 |
tenvinc | 4:26530d450402 | 67 | bmp280_pres.init(BMP280::OVERSAMPLING_X16_P, BMP280::OVERSAMPLING_X2_T, BMP280::FILT_4, BMP280::NORMAL_MODE, BMP280::T_62_5); |
tenvinc | 4:26530d450402 | 68 | |
tenvinc | 4:26530d450402 | 69 | //Temperature sensor variables |
tenvinc | 4:26530d450402 | 70 | uint16_t rawTemp_top; |
tenvinc | 4:26530d450402 | 71 | uint16_t rawTemp_bottom ; |
tenvinc | 4:26530d450402 | 72 | float celsius_top, celsius_bottom; |
tenvinc | 4:26530d450402 | 73 | float fahrenheit_top, fahrenheit_bottom; |
tenvinc | 4:26530d450402 | 74 | |
tenvinc | 4:26530d450402 | 75 | //barometric sensor variables |
tenvinc | 4:26530d450402 | 76 | char bmp280_rawData = 0; |
tenvinc | 4:26530d450402 | 77 | float Temp_degC, Press_Pa, Press_Bar; |
tenvinc | 4:26530d450402 | 78 | |
tenvinc | 4:26530d450402 | 79 | |
tenvinc | 4:26530d450402 | 80 | //Endless loop |
tenvinc | 4:26530d450402 | 81 | while(1) |
tenvinc | 4:26530d450402 | 82 | { |
tenvinc | 4:26530d450402 | 83 | /* Temperature Sensor Settings */ |
tenvinc | 4:26530d450402 | 84 | |
tenvinc | 4:26530d450402 | 85 | //Read Temperature |
tenvinc | 4:26530d450402 | 86 | MAX30205_top.readTemperature(&rawTemp_top); |
tenvinc | 4:26530d450402 | 87 | MAX30205_bottom.readTemperature(&rawTemp_bottom); |
tenvinc | 4:26530d450402 | 88 | // Read BMP280 Temp. and Pressure |
tenvinc | 4:26530d450402 | 89 | bmp280_pres.ReadCompDataRaw(&bmp280_rawData); |
tenvinc | 4:26530d450402 | 90 | bmp280_pres.ToFloat(&bmp280_rawData, &Temp_degC, &Press_Pa); |
tenvinc | 4:26530d450402 | 91 | // Convert to Celsius |
tenvinc | 4:26530d450402 | 92 | celsius_top = MAX30205_top.toCelsius(rawTemp_top); |
tenvinc | 4:26530d450402 | 93 | celsius_bottom = MAX30205_bottom.toCelsius(rawTemp_bottom); |
tenvinc | 4:26530d450402 | 94 | |
tenvinc | 4:26530d450402 | 95 | // Convert to Fahrenheit |
tenvinc | 4:26530d450402 | 96 | fahrenheit_top = MAX30205_top.toFahrenheit(celsius_top); |
tenvinc | 4:26530d450402 | 97 | fahrenheit_bottom = MAX30205_bottom.toFahrenheit(celsius_bottom); |
tenvinc | 4:26530d450402 | 98 | |
tenvinc | 4:26530d450402 | 99 | /* Barometric Sensor Settings */ |
tenvinc | 4:26530d450402 | 100 | |
tenvinc | 4:26530d450402 | 101 | Press_Bar = Press_Pa / 100000; |
tenvinc | 4:26530d450402 | 102 | |
tenvinc | 4:26530d450402 | 103 | /* Printing various sensor values */ |
tenvinc | 4:26530d450402 | 104 | usbSerial.printf("***** MAX30205 Temperature Sensor Reading *****\n\r"); |
tenvinc | 4:26530d450402 | 105 | usbSerial.printf("Top Temperature: %.2f\370 C\n\rBottom Temperature: %.2f\370 C \n\rTop Temperature in Farenheit: %.2f\370 F\n\rBottom Temperature in Farenheit %.2f\370 F\n\n\r", celsius_top, celsius_bottom, fahrenheit_top, fahrenheit_bottom); |
tenvinc | 4:26530d450402 | 106 | |
tenvinc | 4:26530d450402 | 107 | usbSerial.printf("***** BMP280 Barometric Sensor Reading *****\n\r"); |
tenvinc | 4:26530d450402 | 108 | usbSerial.printf("Temp_degC : %.2f , Press_Bar is %.2f , Press_pa is %.2f\n\n\r",Temp_degC, Press_Bar, Press_Pa); |
tenvinc | 4:26530d450402 | 109 | |
tenvinc | 4:26530d450402 | 110 | usbSerial.printf("-------------------------------------------------\n\n\n\r"); |
tenvinc | 4:26530d450402 | 111 | |
tenvinc | 4:26530d450402 | 112 | wait(0.2); |
tenvinc | 4:26530d450402 | 113 | |
tenvinc | 4:26530d450402 | 114 | |
tenvinc | 4:26530d450402 | 115 | |
tenvinc | 4:26530d450402 | 116 | } |
tenvinc | 4:26530d450402 | 117 | } |