1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/tests/driver_bmx280/main.c

116 lines
3.2 KiB
C
Raw Normal View History

2016-10-14 08:32:41 +02:00
/*
* Copyright (C) 2016 Kees Bakker, SODAQ
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup tests
* @{
*
* @file
* @brief Test application for the BME280 temperature, pressure
* and humidity sensor.
*
* @author Kees Bakker <kees@sodaq.com>
*
* @}
*/
#include <stdlib.h>
2016-10-14 08:32:41 +02:00
#include <stdio.h>
#include <inttypes.h>
2017-02-27 16:12:58 +01:00
#include "bmx280_params.h"
#include "bmx280.h"
2016-10-14 08:32:41 +02:00
#include "xtimer.h"
#define MAINLOOP_DELAY (2 * 1000 * 1000u) /* 2 seconds delay between printf's */
int main(void)
{
2017-02-27 16:12:58 +01:00
bmx280_t dev;
2016-10-14 08:32:41 +02:00
int result;
2017-02-27 16:12:58 +01:00
puts("BMX280 test application\n");
2016-10-14 08:32:41 +02:00
printf("+------------Initializing------------+\n");
2017-02-27 16:12:58 +01:00
result = bmx280_init(&dev, &bmx280_params[0]);
2016-10-14 08:32:41 +02:00
if (result == -1) {
puts("[Error] The given i2c is not enabled");
return 1;
}
if (result == -2) {
2017-02-27 16:12:58 +01:00
printf("[Error] The sensor did not answer correctly at address 0x%02X\n", bmx280_params[0].i2c_addr);
2016-10-14 08:32:41 +02:00
return 1;
}
printf("Initialization successful\n\n");
printf("+------------Calibration Data------------+\n");
printf("dig_T1: %u\n", dev.calibration.dig_T1);
printf("dig_T2: %i\n", dev.calibration.dig_T2);
printf("dig_T3: %i\n", dev.calibration.dig_T3);
printf("dig_P1: %u\n", dev.calibration.dig_P1);
printf("dig_P2: %i\n", dev.calibration.dig_P2);
printf("dig_P3: %i\n", dev.calibration.dig_P3);
printf("dig_P4: %i\n", dev.calibration.dig_P4);
printf("dig_P5: %i\n", dev.calibration.dig_P5);
printf("dig_P6: %i\n", dev.calibration.dig_P6);
printf("dig_P7: %i\n", dev.calibration.dig_P7);
printf("dig_P8: %i\n", dev.calibration.dig_P8);
printf("dig_P9: %i\n", dev.calibration.dig_P9);
2017-02-27 16:12:58 +01:00
#if defined(MODULE_BME280)
2016-10-14 08:32:41 +02:00
printf("dig_H1: %u\n", dev.calibration.dig_H1);
printf("dig_H2: %i\n", dev.calibration.dig_H2);
printf("dig_H3: %i\n", dev.calibration.dig_H3);
printf("dig_H4: %i\n", dev.calibration.dig_H4);
printf("dig_H5: %i\n", dev.calibration.dig_H5);
printf("dig_H6: %i\n", dev.calibration.dig_H6);
2017-02-27 16:12:58 +01:00
#endif
2016-10-14 08:32:41 +02:00
printf("\n+--------Starting Measurements--------+\n");
while (1) {
int16_t temperature;
uint32_t pressure;
2017-02-27 16:12:58 +01:00
#if defined(MODULE_BME280)
2016-10-14 08:32:41 +02:00
uint16_t humidity;
2017-02-27 16:12:58 +01:00
#endif
2016-10-14 08:32:41 +02:00
/* Get temperature in centi degrees Celsius */
2017-02-27 16:12:58 +01:00
temperature = bmx280_read_temperature(&dev);
2016-10-14 08:32:41 +02:00
/* Get pressure in Pa */
2017-02-27 16:12:58 +01:00
pressure = bmx280_read_pressure(&dev);
2016-10-14 08:32:41 +02:00
2017-02-27 16:12:58 +01:00
#if defined(MODULE_BME280)
2016-10-14 08:32:41 +02:00
/* Get pressure in %rH */
humidity = bme280_read_humidity(&dev);
2017-02-27 16:12:58 +01:00
#endif
2016-10-14 08:32:41 +02:00
printf("Temperature [°C]: %d.%d\n"
2016-10-14 08:32:41 +02:00
"Pressure [Pa]: %lu\n"
2017-02-27 16:12:58 +01:00
#if defined(MODULE_BME280)
2016-10-14 08:32:41 +02:00
"Humidity [%%rH]: %u.%02u\n"
2017-02-27 16:12:58 +01:00
#endif
2016-10-14 08:32:41 +02:00
"\n+-------------------------------------+\n",
temperature / 100, abs(temperature % 100) / 10,
2017-02-27 16:12:58 +01:00
#if defined(MODULE_BME280)
2016-10-14 08:32:41 +02:00
(unsigned long)pressure,
2017-02-27 16:12:58 +01:00
(unsigned int)(humidity / 100), (unsigned int)(humidity % 100)
#else
(unsigned long)pressure
#endif
);
2016-10-14 08:32:41 +02:00
xtimer_usleep(MAINLOOP_DELAY);
}
return 0;
}