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

/*
 * 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". */
		printk("\nError: no device found.\n");
		return NULL;
	}

	if (!device_is_ready(dev)) {
		printk("\nError: Device \"%s\" is not ready; "
		       "check the driver initialization logs for errors.\n",
		       dev->name);
		return NULL;
	}

	printk("Found device \"%s\", getting sensor data\n", dev->name);
	return dev;
}

void main(void)
{
	const struct device *dev = get_ds18b20_device();

	if (dev == NULL) {
		return;
	}

	while (1) {
		struct sensor_value temp;

		sensor_sample_fetch(dev);
		sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);

		printk("Temp: %d.%06d\n", temp.val1, temp.val2);
		k_sleep(K_MSEC(2000));
	}
}

prj.conf

CONFIG_SENSOR=y
CONFIG_W1=y

CONFIG_LOG=y
CONFIG_SENSOR_LOG_LEVEL_DBG=y

C:\ncs\ds18b20\nrf5340dk_nrf5340_cpuapp.overlay

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

 
 

	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";
		};
	};

Parents Reply Children
  • 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

  • Hi ,

    Yes i connected the sensor to pin 1.01 before and after l change to the devicetree and i have the same problem .

    Runsiv please help me i must activate this sensor before April 6,2023 .

    
    

    Regards.

Related