Reading temperature data from DS18B20 sensor using nRF5340-DK

Hello everyone , I'm having trouble activating my DS18B20 temperature sensor (waterproof) with the nRF5340, SDK v2.3.0, and VS Code. I'm using the "zephyr/samples/sensor/ds18b20" template and have created the overlay file, but when I try to flash it, I get the error " no device found"  despite the wiring is correct 

Wiring : 

GND + GND (nrf5340)

VCC + VDD (nrf5340)

DATA + P1.10 (nrf5340)

I think that the problem is in the overlay file .

Thanks.

Here is my code

main.c

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* Copyright (c) 2022 Thomas Stranger
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/sensor.h>
/*
* Get a device structure from a devicetree node with compatible
* "maxim,ds18b20". (If there are multiple, just pick one.)
*/
static const struct device *get_ds18b20_device(void)
{
const struct device *const dev = DEVICE_DT_GET_ANY(maxim_ds18b20);
if (dev == NULL) {
/* No such node, or the node does not have status "okay". */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

prj.conf

Fullscreen
1
2
3
4
5
CONFIG_SENSOR=y
CONFIG_W1=y
CONFIG_LOG=y
CONFIG_SENSOR_LOG_LEVEL_DBG=y
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

C:\ncs\ds18b20\nrf5340dk_nrf5340_cpuapp.overlay

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// To get started, press Ctrl+Space to bring up the completion menu and view the available nodes.
// You can also use the buttons in the sidebar to perform actions on nodes.
// Actions currently available include:
// * Enabling / disabling the node
// * Adding the bus to a bus
// * Removing the node
// * Connecting ADC channels
// For more help, browse the DeviceTree documentation at https://docs.zephyrproject.org/latest/guides/dts/index.html
// You can also visit the nRF DeviceTree extension documentation at https://nrfconnect.github.io/vscode-nrf-connect/devicetree/nrfdevicetree.html
/*
* Copyright (c) 2022, Thomas Stranger
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Example configuration of a DS18B20 device on an Arduino serial bus.
* Requires external circuit to provide an open-drain interface.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Parents
  • Hi Wiem

    Do you have access to a logic analyzer, just to verify that there is communication over the pin?

    Its looks like you are missing a part of the overlay? Did you modifiy the overlay? This is how mine is looking

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    &arduino_serial {
    status = "okay";
    w1_0: w1-zephyr-serial-0 {
    compatible = "zephyr,w1-serial";
    #address-cells = <1>;
    #size-cells = <0>;
    status = "okay";
    ds18b20 {
    compatible = "maxim,ds18b20";
    family-code = <0x28>;
    resolution = <12>;
    status = "okay";
    };
    };
    };
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Regards

    Runar

  • Hello Runsiv .

    I used this file recently, but I have the same problem

  • Hi, 

    Do you have access to a logic analyzer, just to verify that there is communication over the pin?

    Did you modifiy the overlay file from the sample project in any way? 

    Regards

    Runar

  • Hi ,

    Yes the communication is perfect but i don't use the arduino serial , i use nrf5340 DK and i can't khnow how i configure the overlay file .

    Im am using this source I found on internet :

    docs.zephyrproject.org/.../README.html

    Thanks.

Reply Children
  • Hi, 

    Can you try to use the overlay file I posted? 

    What do you mean by perfect communication? From the error it looks like you don't communicate with the device

    For more information about overlay files I would recommend devAcadamy academy.nordicsemi.com/.../

    Regards

    Runar

  • Now i have this error:

    Found device "ds18b20" , getting sensor data 

    [00:00:00.436,187] <err> w1_serial: tx_rx_error reset_present

    [00:00:00.436,187] <err> DS18B20: No 1-Wire slaves connected

    Temp: 0.000000

    Regards.

  • What did you change? 

    Do you have a boards folder containing any files? Did you set up the project using the create new application wizard in VScode? 

    From the uart overlay in the sample project, I would try P1.01 instead of P1.10

    Regards

    Runar

  • Yes I configured the project using the create new application wizard in VScode and I'm not creating an overlay file, I did the configuration in the file
    "c:\ncs\v2.3.0\zephyr\boards\arm\nrf5340dk_nrf5340\nrf5340_cpuapp_common.dts" and when I add ( gpios = <&gpio0 10(GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; )
    i have this error: Property not mentioned in " max,ds18b20"
    Also when i add another digital pin i have the same error.

    Thanks.
  • Hi, 

    If possible I would like you to revert any changes you have done to the device tree for the nrf5340, to cite the link to devAcadamy I gave you yesterday "It is not recommended to modify the devicetree directly, so instead we use devicetree overlays to do this.". This is because if you do changes to your device tree you will affect all projects you make using that device. However if you use overlay files your "main" devicetree will not be affected. Lesson 2 and 3 in devAcadamy gives a good introduction to this. 

    Did you try to connect your sensor to pin 1.01 before you made changes to the devicetree?

    Regards

    Runar