I tried adding a DS18B20 based on this sample: https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/sensor/ds18b20/arduino_serial.overlay . It redirects to the DS18B20 docs (page 10) that these sensors can be interfaced via a serial interface: https://www.analog.com/media/en/technical-documentation/data-sheets/ds18b20.pdf . If it isn’t possible in any other way I would do it like that. But just using a regular pin would be preferable. For that I tried this:

	ds18b20 {
		compatible = "maxim,ds18b20";
		gpios = <&gpio0 7 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>;
		pinctrl-names = "default";
		pinctrl-0 = <&ds18b20_pin>;
		status = "okay";
	};

	fragment@0 {
		target = <&gpio0>;
		__overlay__ {
			ds18b20_pin: ds18b20_pin {
				brcm,pins = <7>;
				brcm,function = <0>; // Input 
				brcm,pull = <2>; // Pull-up 
			};
		};
	};

But it is still not buildable. In the proj.conf I specifically added these settings:

# sensor config
CONFIG_SENSOR=y
CONFIG_GPIO=y
CONFIG_W1=y

I also was looking into interfacing multiple sensors, there I found some useful code: https://github.com/zephyrproject-rtos/zephyr/discussions/55743 but this also isn’t buildable. So now my overlay-file looks like this:

 / {
	dht22 {
		compatible = "aosong,dht";
		status = "okay";
		dio-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
		// dht22; // leave undefined to use dht11
	};


	// wire pins according to docs on pag 10 to rx and tx
	// https://www.analog.com/media/en/technical-documentation/data-sheets/ds18b20.pdf


	w1_0: w1-zephyr-serial-0 {
		compatible = "zephyr,w1-serial";
		#address-cells = <1>;
		#size-cells = <0>;
		status = "okay";

		testlabel: ds18b20 {
			compatible = "maxim,ds18b20";
			family-code = <0x28>;
			resolution = <12>;
			status = "okay";
		};
		testlabel2: ds18b202 {
		   compatible = "maxim,ds18b20";
		   family-code = <0x28>;
		   resolution = <12>;
		   status = "okay";
	   };
	};

};

There I get the error: zephyr/include/zephyr/device.h:84:41: error: '__device_dts_ord_DT_N_S_w1_zephyr_serial_0_S_ds18b20_BUS_ORD' undeclared here (not in a function)

I’m pretty new to devicetrees. I was looking through the devicetree docs https://docs.zephyrproject.org/latest/build/dts/index.html but it’s so much information I don’t even know what would be the best place to start looking for solutions. Also the troubleshooting section: https://docs.zephyrproject.org/latest/build/dts/troubleshooting.html only vaguely says what the issue could be. For example in the generated zephyr.dts status="okay" is set.

    Seems like you’re half way there.

    If I were you I’d try to get the sensor working with the serial interface and one chip first, then move on to more complex configurations.

    I’d recommend checking out the documentation on the 1-wire interface here: https://docs.zephyrproject.org/latest/hardware/peripherals/w1.html

    You may want to refer to the changes in the overlay specifically for the nRF52 since that will apply to the nRF9160 as well: (zephyr/samples/sensor/ds18b20/boards/nrf52840dk_nrf52840.overlay)

    #include "serial_overlay.dtsi"
    
    &pinctrl {
    	uart1_default: uart1_default {
    		group1 {
    			psels = <NRF_PSEL(UART_RX, 1, 1)>;
    			bias-pull-up;
    		};
    		group2 {
    			psels = <NRF_PSEL(UART_TX, 1, 2)>;
    			/* max. 5mA drive strength: */
    			nordic,drive-mode = <NRF_DRIVE_H0D1>;
    		};
    	};
    };

    I’m assuming the different groups help facilitate jumping between setting a pin to TX and RX.

    I hope that helps!

      it seems that now it’s fine. I got another error that you can’t use uart0 and uart1 at the same time. This builds without issues:

      / {
      	dht22 {
      		compatible = "aosong,dht";
      		status = "okay";
      		dio-gpios = <&gpio0 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
      		// dht22; // leave undefined to use dht11
      	};
      };
      
      /*
       * Example configuration of a DS18b20 device on an Arduino serial bus, using
       * the zephyr-serial 1-Wire driver.
       * Open drain configuration allows communication by simply connecting the bus
       * line to the UART RX pin as well as the TX pin
       * An external pull-up should be added anyways.
       */
      
      // wire pins according to docs on pag 10e to rx and tx
      // https: //www.analog.com/media/en/technical-documentation/data-sheets/ds18b20.pdf
      
      &pinctrl {
      	uart0_default: uart0_default {
      		group1 {
      			psels = <NRF_PSEL(UART_RX, 1, 1)>;
      			bias-pull-up;
      		};
      		group2 {
      			psels = <NRF_PSEL(UART_TX, 1, 2)>;
      			// max. 5mA drive strength:
      			nordic,drive-mode = <NRF_DRIVE_H0D1>;
      		};
      	};
      };
      
      // arduino_serial -> uart0
      // see: https: //devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/peripherals/posts/working-around-missing-shield-labels-on-the-nrf9160dk
      &uart0 {
      	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";
      		};
      	};
      };

        jgartner I got another error that you can’t use uart0 and uart1 at the same time.

        Generally this means that you have another interface (I2C, SPI etc) enabled on the same bus number. I.e you can’t have I2C1 and UART1 enabled at the same time.

          5 days later

          So when I was writing this code I hadn’t had the opportunity to test it right away. I did try arround some other things but nothing seems to work. Oddly enough, the pins aren’t getting any voltage. This is how I wired it up:

          my wiring

          But if i measure the voltage between either RX/TX and GND I get 0V. If I attach one of the pins that are on RX/TX now to 3.3V this also doesn’t help in getting any results. Additionally the serial connection isn’t working when I override the RX and TX pins (see &pincrtl from a previous message) in the devicetree. This makes it hard - if not impossible - to debug any errors.

          I tried wiring it up as descibed docs on page 10. Maybe i need a fourth pin for that? So that I have RX, TX, Vcc and GND?

            I use a DS18B20 on a nRF9160 feather v5 with success since summer 2023.
            You may check the one-wire-? files in my project, maybe that helps to find the difference.
            In order to use a “single wire” (=> OneWire) the I/O pin is in “open drain” mode (see wikipedia 1-Wire ). It requires a 4K7 pull up resistor to VDD. I guess, your 0V is mainly caused by missing such an pull up.
            Hope that helps, or at least gives some ideas on how to continue.
            As I started, the In the end nRF9160 feather v5 works with a DS18B20, so I guess, it’s a small issue on your side.

              Thanks @AchimKraus your devicetrees helped me a lot! In combination with a w1 scanner and by assigning each sensor one of the found values source here I was able to get the ROM values of each sensor. But when I measure it I get a result of 85 °C, indicating that there are some communication issues. I tested the exact setup I have with an raspberry pi (i took the wires from the feather and put it into the raspberry pi). On the pi everything works fine. I additionally added some capacitors to increase power stability but with no effect.

              This is the serial output I get:

              [00:00:15.264,251] <inf> main: Device found; family: 0x28, serial: 0x28ff6deda217043b
              [00:00:15.284,576] <dbg> DS18B20: ds18b20_configure: Init DS18B20: ROM=28ff6deda217043b
              
              85.0 Cel
              [00:00:16.090,362] <inf> main: Device found; family: 0x28, serial: 0x28ff59bea21704f0
              [00:00:16.110,687] <dbg> DS18B20: ds18b20_configure: Init DS18B20: ROM=28ff59bea21704f0
              
              85.0 Cel
              [00:00:16.916,381] <inf> main: Device found; family: 0x28, serial: 0x28ffe949a2170516
              [00:00:16.936,798] <dbg> DS18B20: ds18b20_configure: Init DS18B20: ROM=28ffe949a2170516
              
              85.0 Cel
              [00:00:17.720,825] <inf> main: Number of devices found on bus: 3

              And this the code i created:

              void w1_search_callback(struct w1_rom rom, void* voiderment)
              {
                  LOG_INF("Device found; family: 0x%02x, serial: 0x%016llx", rom.family, w1_rom_to_uint64(&rom));
              
                  const struct device *therm = DEVICE_DT_GET_ANY(maxim_ds18b20);
              
                  while (!device_is_ready(therm))
                  {
                      LOG_ERR("Device %s is not ready\n", therm->name);
                  }
              
                  struct sensor_value temperature;
                  w1_rom_to_sensor_value(&rom,&temperature);
                  sensor_attr_set(therm,SENSOR_CHAN_ALL,SENSOR_ATTR_W1_ROM,&temperature);
              
                  int fetch_result_code = sensor_sample_fetch(therm);
              
                  if (fetch_result_code != 0)
                  {
                      LOG_ERR("Sensor fetch failed: %d\n", fetch_result_code);
                      return;
                  }
              
                  fetch_result_code = sensor_channel_get(therm, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
                  if (fetch_result_code != 0)
                  {
                      LOG_ERR("get failed: %d\n", fetch_result_code);
                      return;
                  }
              
                  double thermDouble = sensor_value_to_double(&temperature);
              
                  printf("%.1f Cel\n", thermDouble);
              }
              
              
              // w1 scanner source: https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/drivers/w1/scanner/src/main.c
              static void w1_scanner(struct Measurement* msmnt)
              {
                  const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(w1_0));
              
                  if (!device_is_ready(dev))
                  {
                      LOG_ERR("Device not ready");
                      return;
                  }
              
                  int w1_devices_amount = w1_get_slave_count(dev);
                  w1_search_rom(dev, w1_search_callback, msmnt);
              
              
                  LOG_INF("Number of devices found on bus: %d", w1_devices_amount);
              }

              Do you have any idea why I would the able to retrieve the ROM values but a measurement isn’t possible? I’m pretty stuck event though it fells like it’s just a small mistake.

                I’m not common to have more than one sensors. So I would start with one, and see if that works.

                Terms and Conditions | Privacy Policy