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