This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF9160 with BME280 sensor

I am trying to test a BME280  sensor on the nRF9160. I followed the steps where I created a folder (board) and added the nrf9160_pca10090.overlay and add couple of line in the prj.conf. I am building with build -b nrf9160_pca10090ns(non-secure). I get an error while building. I didnt connect the sensor but the code should build without the sensor am I wrong ?

same error with segger

In file included from /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.c:24:0:
3> /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.h:114:2: error: #error "BME280 device type not specified"
3> /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.c:370:22: warning: unused variable 'data' [-Wunused-variable]
3> In file included from ../../../../include/drivers/sensor.h:23:0,
3>                  from /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.c:11:
3> /home/ahmed/v1.2.0/zephyr/drivers/sensor/bme280/bme280.c:398:29: error: 'DT_INST_0_BOSCH_BME280_LABEL' undeclared here (not in a function); did you mean 'DT_INST_0_SOC_NV_FLASH_LABEL'?
3> ../../../../include/device.h:106:11: note: in definition of macro 'DEVICE_AND_API_INIT'
4> Compiling 'nrf_cc310_platform_mutex_zephyr.c'
5> Compiling 'nrf_cc310_platform_abort_zephyr.c'
8> Compiling 'sys_clock_init.c'
Build failed

I will add the codes form the files as well to make it easier.

&i2c2 {
    status = "ok";
    sda-pin = <12>;
    scl-pin = <11>;
    
    bme280@76 {
        compatible = "bosch,bme280";
        reg = <0x76>;
        label = "BME280";
    };
};
Overlay

CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_BME280=y
CONFIG_I2C_2=y
prj.conf

# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(bme280)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
CMake

/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <device.h>
#include <drivers/sensor.h>

void main(void)
{
	struct device *dev = device_get_binding("BME280");

	if (dev == NULL) {
		printk("Could not get BME280 device\n");
		return;
	}

	printk("dev %p name %s\n", dev, dev->config->name);

	while (1) {
		struct sensor_value temp, press, humidity;

		sensor_sample_fetch(dev);
		sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
		sensor_channel_get(dev, SENSOR_CHAN_PRESS, &press);
		sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &humidity);

		printk("temp: %d.%06d; press: %d.%06d; humidity: %d.%06d\n",
		      temp.val1, temp.val2, press.val1, press.val2,
		      humidity.val1, humidity.val2);

		k_sleep(K_MSEC(1000));
	}
}
main

Related