Skip to content
View in the app

A better way to browse. Learn more.

Armbian Community Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

DS18B20 Temperature Sensor / 1-Wire / FEX

Featured Replies

Hy

 

I'm currently trying to run a DS18B20 Temperature Sensor on the PA20 Port on my Neo Core 2.

The w1_gpio und w1_therm modules are loaded

image.png.8d9f665faab5e444c75b872dc995d87c.png

but still I can't see the senors in the /sys/bus/w1/devices/ folder. (28-xxxx)

image.png.a442d0ea98e7e81d0005cfe002855831.png

 

Now I read in different threads to edit the FEX file in the /boot/ folder. So I would bee to first covert the script.bin to the script.fex.

However I can't find any *.bin file in the /boot/ folder...

 

So is the PA20 Port the correct 1Wire port? And how can I change this port to eg. GPIOG11 if I can't find the script.bin in the /boot/ folder?

 

Andy

  • Author

hmm so I found something. With the Neo Core 2 I have a 64-bit SoCs so it does not use FEX files instead the dtbo files in the /boot/dtb/allwinner/overlay/ folder.

With fdtdump I can read the w1-gpio file where the port is written.

fdtdump sun50i-h5-w1-gpio.dtbo
/dts-v1/;
// magic:               0xd00dfeed
// totalsize:           0x31f (799)
// off_dt_struct:       0x38
// off_dt_strings:      0x2b4
// off_mem_rsvmap:      0x28
// version:             17
// last_comp_version:   16
// boot_cpuid_phys:     0x0
// size_dt_strings:     0x6b
// size_dt_struct:      0x27c

/ {
    compatible = "allwinner,sun50i-h5";
    fragment@0 {
        target = <0xffffffff>;
        __overlay__ {
            w1_pins {
                pins = "PD14";
                function = "gpio_in";
                linux,phandle = <0x00000001>;
                phandle = <0x00000001>;
            };
        };
    };
    fragment@1 {
        target-path = "/";
        __overlay__ {
            onewire@0 {
                compatible = "w1-gpio";
                pinctrl-names = "default";
                pinctrl-0 = <0x00000001>;
                gpios = <0xffffffff 0x00000003 0x0000000e 0x00000000>;
                status = "okay";
            };
        };
    };
    __symbols__ {
        w1_pins = "/fragment@0/__overlay__/w1_pins";
    };
    __fixups__ {
        pio = "/fragment@0:target:0", "/fragment@1/__overlay__/onewire@0:gpios:0";
    };
    __local_fixups__ {
        fragment@1 {
            __overlay__ {
                onewire@0 {
                    pinctrl-0 = <0x00000000>;
                };
            };
        };
    };
};

 

 

From the file I can see that the port used for the 1Wire interfaceis PD14 (GPIOD14) which on the Core 2 is used to reset the RTL8211E chip on the board:

image.png.8d035cd726e82298da42303794edddd7.png

 

So I definitely can't use this pin for my 1Wire interface.

Now what I didn't figure out is now how to change the PIN for the 1 Wire interface in the file.

 

 

I tired to copy the content of the w1-gpio file to a new w1-gpioPA20.dts file and then use the command

armbian-add-overlay <overlay_file.dts>

to put the dts in to the /boot/dtb/allwinner/overlay/ folder. 

Now in the /boot/overlay-user/ I can see the new w1-gpioPA20.dtbo File.

Also in the armbianEnv.txt there is now an additional entry where the w1-gpioPA20 gets launched

and during booting I can see that the module gets activated.

 

However still I don't see the DS18B20 now on the new pin in the /sys/bus/w1/devices/ folder.

Where did I make a mistake?

 

Andy

 

 

 

 

 

 

 

  • Author

cat /sys/kernel/debug/gpio

gpiochip1: GPIOs 0-223, parent: platform/1c20800.pinctrl, 1c20800.pinctrl:
 gpio-20  (                    |nanopi:blue:status  ) out lo
 gpio-102 (                    |gmac-3v3            ) out hi
 gpio-166 (                    |cd                  ) in  hi IRQ
 gpio-203 (                    |w1                  ) in  lo
 gpio-204 (                    |usb0_id_det         ) in  hi IRQ

gpiochip0: GPIOs 352-383, parent: platform/1f02c00.pinctrl, 1f02c00.pinctrl:
 gpio-354 (                    |usb0-vbus           ) out hi
 gpio-359 (                    |reset               ) out lo
 gpio-362 (                    |nanopi:green:pwr    ) out hi

 

dmesg | grep w1

[   16.082602] w1_master_driver w1_bus_master1: w1_search: max_slave_count 64 reached, will continue next search.
[   62.978597] w1_master_driver w1_bus_master1: Attaching one wire slave 00.800000000000 crc 8c
[   62.981824] w1_master_driver w1_bus_master1: Family 0 for 00.800000000000.8c is not registered.

 

  • Author

great it works!

Now I don't know why the 1Wire is now on PG11 and not PA20...

How can I set the port for the 1Wire interface then apparently the method I described above did not work... (DT overlay)

 

Andy

  • Author

hmm but will the overlays not work on top of the main DT, so overwriting the "old" settings?

  • Author

hmm sounds logic but I also tried PG7 but no success with this either...

 

3 hours ago, Andy said:

Now I don't know why the 1Wire is now on PG11 and not PA20...

 

16 minutes ago, Andy said:

hmm sounds logic but I also tried PG7 but no success with this either...

 

What are you changing exactly in the overlay? GPIO pin number is defined in the "gpios" property of the "onewire@0" block, not in the "w1_pins" block - it controls nothing by default unless you add bias-pull-up, bias-pull-down or drive-strength properties if you need to change the pin controller defaults for that pin.

  • Author

In the overlay I tried to change the default pin where the 1Wire interface is connected. So the default is PD14.

Then I tried to use the PA20 and because this didn't worked I also tried PG7.

so I nee to change the gpios = <0xffffffff 0x00000003 0x0000000e 0x00000000>; part in the "onewire@0" Block?

but is the 0xffffffff not the reference to the "w1_pins" block and there to the PD14 pin?

 

Andy

13 minutes ago, Andy said:

so I nee to change the gpios = <0xffffffff 0x00000003 0x0000000e 0x00000000>; part in the "onewire@0" Block?

but is the 0xffffffff not the reference to the "w1_pins" block and there to the PD14 pin?

Please look at the original (not decompiled) overlay: https://github.com/armbian/sunxi-DT-overlays/blob/master/sun50i-h5/sun50i-h5-w1-gpio.dts

In your decompiled overlay the first cell of the "gpios" property (0xffffffff) will be the reference to the pin controller node (from the "main" DT), the second cell (0x00000003) is the pin bank number (PD) and the third cell (0x0000000e) is the pin number in the bank (14).

 

Alternatively the pin number can be easily changed with the base overlay, as noted in the README in the overlays directory.

  • Author

oh wow thx now its clear and easy to change. Now I understand how the file is constructed.

Thx a lot for all the help, to all of you!!!

Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.