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
00001 #include "mbed.h" 00002 #include "MSS.h" 00003 #include "BME280.h" 00004 00005 #define SPI_IF 1 00006 #define I2C_IF 2 00007 00008 #define BME280_I2C_ADDRESS 0x76 00009 00010 DigitalOut csb(PIN_CS0, 1) ; 00011 00012 int main() { 00013 float temp, hum, pres ; 00014 BME280 *bme280 = 0 ; 00015 int used_if = I2C_IF ; /* SPI_IF for SPI */ 00016 00017 if (used_if == I2C_IF) { 00018 bme280 = new BME280(PIN_SDA, PIN_SCL, BME280_I2C_ADDRESS) ; 00019 } else if (used_if == SPI_IF) { 00020 bme280 = new BME280(PIN_SCK, PIN_MISO, PIN_MOSI, PIN_CS0) ; 00021 } else { 00022 printf("Unsupported IF for BME280 [%d]\n", used_if) ; 00023 exit(EXIT_FAILURE) ; 00024 } 00025 00026 bme280->reset() ; 00027 wait(2) ; 00028 bme280->init() ; 00029 wait(1) ; 00030 printf("\n=== test BME280 for %s (%s) ===\n", BOARD_NAME, __DATE__) ; 00031 if (used_if == I2C_IF) { 00032 printf("IF = I2C, ") ; 00033 } else if (used_if == SPI_IF) { 00034 printf("IF = SPI, ") ; 00035 } 00036 printf("ID = 0x%02X (0x60 expected for BME280)\n", bme280->getID()) ; 00037 00038 printf("Temperature(C) , Humidity(%%), Pressure(hPa)\n") ; 00039 while(1) { 00040 bme280->trigger() ; 00041 while(bme280->busy()) { 00042 wait(0.1) ; 00043 } 00044 temp = bme280->getTemperature() ; 00045 hum = bme280->getHumidity() ; 00046 pres = bme280->getPressure() ; 00047 printf("%.2f, %.2f, %.2f\n", temp, hum, pres) ; 00048 wait(2) ; 00049 } 00050 }
Generated on Wed Jul 13 2022 02:46:27 by
1.7.2