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

Nrf9160DK + BME280

Hi

I start in programming on nrf9160 DK with a sensor BME280.
I followed the tutorial "getting started part 2" (https://devzone.nordicsemi.com/nordic/cellular-iot-guides/b/getting-started-cellular/posts/nrf-connect-sdk-tutorial---part-2#h79sk0f70607qwcyitkx2xn61bmh9mo).

the program is uploaded to the nrf9160DK via segger. I can't read the temperature values.

I read in Lte monitor: Could not get BME280 device.

can someone help me?

  • # 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})
    

    this is the CMakeLists.

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

    nrf9160_pca10090.overlay

    CONFIG_STDOUT_CONSOLE=y
    CONFIG_I2C_2=y
    CONFIG_SENSOR=y
    CONFIG_BME280=y
    

    prj.conf

    /*
     * 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.c

  • Hi.

    The reason why the application is not able to "find" the device might be that the nRF91 is not able to communicate with the sensor.

    Is it connected to the correct pins?

    Have you used a logic analyzer or oscilloscope to verify that the communication between the nRF91 and the sensor looks fine?

    Best regards,

    Didrik

  • Hi,

    I am using the BME280 Shuttle Board. I connected the pin P0.12 (nrf9160) with the pin 17 (Bme280 shuttle board) and the pin P0.11 and the pin P0.11 (nrf9160) with the pin 18 (Bme280 shuttle board). Naturally the Vdd (nrf9160) with the pin 1 (Bme280 shuttle board) and the GND (nrf9160) with the pin 3 (Bme280 shuttle board)
    I used the oscilloscope but I did not see anything on the pins P0.12 and P0.11.
    Is nrf9160 well programmed?

  • Are you building your application as secure (board name nrf9160_pca10090) or non-secure (board name nrf9160_pca10090ns)?

    If you are building the application as non-secure, you must also add your changes to the overlay file in ncs/nrf/samples/nrf9160/spm (note that the overlay file must be for the secure variant of the board, i.e. nrf9160_pca10090.overlay).

    Also, if you are using Segger Embedded Studio, you should load the project again after changing overlay files, CMake files, or configuration files to make sure that your changes are taking effect.

Related