Merge pull request #160 from sheinz/feature/bmp280
BMP280 pressure sensor driver and example.
This commit is contained in:
commit
22c480b583
6 changed files with 615 additions and 0 deletions
3
examples/bmp280/Makefile
Normal file
3
examples/bmp280/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
PROGRAM=BMP280_example
|
||||
EXTRA_COMPONENTS = extras/i2c extras/bmp280
|
||||
include ../../common.mk
|
88
examples/bmp280/bmp280_example.c
Normal file
88
examples/bmp280/bmp280_example.c
Normal file
|
@ -0,0 +1,88 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "espressif/esp_common.h"
|
||||
#include "esp/uart.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "bmp280/bmp280.h"
|
||||
|
||||
// In forced mode user initiate measurement each time.
|
||||
// In normal mode measurement is done continuously with specified standby time.
|
||||
// #define MODE_FORCED
|
||||
|
||||
const uint8_t scl_pin = 5;
|
||||
const uint8_t sda_pin = 4;
|
||||
|
||||
#ifdef MODE_FORCED
|
||||
static void bmp280_task_forced(void *pvParameters)
|
||||
{
|
||||
bmp280_params_t params;
|
||||
float pressure, temperature;
|
||||
|
||||
bmp280_init_default_params(¶ms);
|
||||
params.mode = BMP280_MODE_FORCED;
|
||||
|
||||
while (1) {
|
||||
while (!bmp280_init(¶ms, scl_pin, sda_pin)) {
|
||||
printf("BMP280 initialization failed\n");
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
}
|
||||
|
||||
while(1) {
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
if (!bmp280_force_measurement()) {
|
||||
printf("Failed initiating measurement\n");
|
||||
break;
|
||||
}
|
||||
while (bmp280_is_measuring()) {}; // wait for measurement to complete
|
||||
|
||||
if (!bmp280_read(&temperature, &pressure)) {
|
||||
printf("Temperature/pressure reading failed\n");
|
||||
break;
|
||||
}
|
||||
printf("Pressure: %.2f Pa, Temperature: %.2f C\n", pressure, temperature);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void bmp280_task_normal(void *pvParameters)
|
||||
{
|
||||
bmp280_params_t params;
|
||||
float pressure, temperature;
|
||||
|
||||
bmp280_init_default_params(¶ms);
|
||||
while (1) {
|
||||
while (!bmp280_init(¶ms, scl_pin, sda_pin)) {
|
||||
printf("BMP280 initialization failed\n");
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
}
|
||||
|
||||
while(1) {
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
if (!bmp280_read(&temperature, &pressure)) {
|
||||
printf("Temperature/pressure reading failed\n");
|
||||
break;
|
||||
}
|
||||
printf("Pressure: %.2f Pa, Temperature: %.2f C\n", pressure, temperature);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
|
||||
// Just some information
|
||||
printf("\n");
|
||||
printf("SDK version : %s\n", sdk_system_get_sdk_version());
|
||||
printf("GIT version : %s\n", GITSHORTREV);
|
||||
|
||||
#ifdef MODE_FORCED
|
||||
xTaskCreate(bmp280_task_forced, (signed char *)"bmp280_task", 256, NULL, 2, NULL);
|
||||
#else
|
||||
xTaskCreate(bmp280_task_normal, (signed char *)"bmp280_task", 256, NULL, 2, NULL);
|
||||
#endif
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue