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