Advertisement
ivayloi

bpm280 usage

Oct 22nd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. /* https://github.com/ciastkolog/BMP280_STM32 */
  2. extern BMP280_HandleTypedef bmp280;
  3. ...
  4.  
  5. /*  Temperature sensor  */
  6.     bmp280_init_default_params(&bmp280.params);
  7.     bmp280.addr = BMP280_I2C_ADDRESS_0;
  8.     bmp280.i2c = &hi2c3;
  9.  
  10.     if (!bmp280_init(&bmp280, &bmp280.params)) {
  11.         printf("[FAIL] BMP280\n");
  12.     } else {
  13.         float pressure, temperature, humidity;
  14.         bool bme280p = bmp280.id == BME280_CHIP_ID;
  15.         HAL_Delay(100);
  16.  
  17.         if (!bmp280_read_float(&bmp280, &temperature, &pressure, &humidity)) {
  18.             printf("[FAIL] BMP280 Temperature/pressure reading failed\n");
  19.         } else {
  20.             if (bme280p) {
  21.                 printf(
  22.                         "[PASS] BME280: %.2fPa, %.2f°C, %.1f%%\n",
  23.                         pressure, temperature, humidity);
  24.             } else {
  25.                 printf("[PASS] BMP280 %.2fPa, %.2f°C\n", pressure, temperature);
  26.             }
  27.         }
  28.     }
  29.  
  30. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement