1-wire DS18B20 Thermometer on Jetson Xavier AGX

Hello,
I have read all the threads about connecting DS18B20 to Jetson Xavier AGX and none of them have been successful.

In all branches, the guys from Nvidia suggest recompiling the kernel with support for CONFIG_W1_SLAVE_THERM, CONFIG_W1 and dtb.

But only one branch successed , but it uses the PyDigiTemp library (but not the method with rebuilding the kernel) topic with PyDigiTemp

My questions:

  1. Has anyone managed to rebuild the kernel according to the instructions so that the DS18B20 works?
  2. If successful, what wiring diagram should be used to connect the DS18B20 to Jetson after recompiling the kernel and dtb? Which pins should I use?

We don’t have experience with this DS18B20 thermometer, you may check other developer thred to see if can help: Configuring DS18B20 temperature sensor using python on Jetson Nano - Jetson & Embedded Systems / Jetson Nano - NVIDIA Developer Forums

After a lot of research, I found a solution to get 1-wire to work with the w1-gpio driver on a Jetson AGX Xavier with a DS18B20.

Important!!! Jetson AGX support 1-ware only for specific pins connected to tegra_aon_gpio like 16 pin.

Screenshot 2024-02-20 at 15.40.50

Other pins did not work.

To get gpio PIN number use cat /sys/kernel/debug/gpio
For example pin 16 have ID=GPIO3_PBB.00gpio-313 (PBB.00 |onewire@0 ) out hi
So pin 16 = gpio-313 (number used next in w1-gpio-cl module command)
Different Jetson models and JetPack versions use different gpio numbers!

To make it work, there are 2 options.
In both cases, you must compile the kernel with w1 support.

  1. Option to use w1-master driver from Linux kernel + dtb patch.
  2. Option to use w1-gpio-cl module GitHub - pstolarz/w1-gpio-cl: Command line configured kernel mode 1-wire bus master driver. w1-gpio standard Linux module enhancement/substitution. - it’s better. And work for Jetson Nano, NX, etc.

To compile the Linux kernel with the w1-gpio driver:

  1. Download the sources of the kernel you are using.
    For example JP5.2.1 https://developer.download.nvidia.com/embedded/L4T/r35_Release_v2.1/sources/public_sources.tbz2

  2. Add lines to file Linux_for_Tegra/sources/kernel/kernel-5.10/arch/arm64/configs/tegra_defconfig

CONFIG_W1=y
CONFIG_W1_MASTER_GPIO=y
CONFIG_W1_SLAVE_THERM=y

NVIDIA please add these lines as default for Linux_for_Tegra.
Because it’s only 1 KB to kernel, but in this case we don’t need to rebuild the kernel to support w1.

  1. To build use Linux_for_Tegra/sources/nvbuild.sh -o ./kernel_out

Now kernel in Linux_for_Tegra/sources/kernel_out/arch/arm64/boot/Image

  1. Copy the new kernel file into jetson and replace /boot/Image with it and reboot. No need to flash it. Just replace the file.
    Your system now supports the 1-wire driver.

Option to use w1-master with dtb patch ( Hard way)

Dtb is used to select the pin you use for 1-wire. In the example TEGRA194_MAIN_GPIO(B, 0) this is pin 16 GPIO3_PBB.00 = (B, 0)

Add to file Linux_for_Tegra/sources/hardware/nvidia/platform/t19x/galen/kernel-dts/tegra194-p2888-0001-p2822-0000.dts

/ {
            onewire@0 {
                compatible = "w1-gpio";
                gpios = <&tegra_aon_gpio TEGRA194_MAIN_GPIO(B, 0) GPIO_ACTIVE_HIGH>; // 40-pin conn., pin 16
                status = "okay";
            };
};

Compile dtb with Linux_for_Tegra/sources/nvbuild.sh -o ./kernel_out and flash them using SDK Manager.

I also tested a dtb overlay for this. It’s better this way and you don’t need to flash dtb.

Option to use w1-gpio-cl

Compile w1-gpio-cl according to instructions from github.

For Jetson I used:

  1. Copy the kernel sources from (1) to jetson.

Call make tegra_defconfig modules_prepare in sources.

  1. In w1-gpio-cl sources
export KERNEL_SRC=/home/jetson/Linux_for_Tegra/kernel/kernel-5.10 # path to kernel sources from (1)

make

make install
  1. To start w1-gpio-cl on 16 pin call sudo modprobe -v w1-gpio-cl m1="gdt=313,od"

Result:

Now ls /sys/devices/w1_bus_master1 shows all DS18B20.
For example my DS18B20 ID name like 28-937abc0164ff
And temperature cat /sys/devices/w1_bus_master1/28-937abc0164ff/temperature26437 this is 26.437 ℃

PS. Wiring diagram like Raspberry pi. With a 4.7k resistor from VCC to the data pin.

raspberry-pi-ds18b20-connections

Great! Thanks for your sharing to the community!