Jump to content

How to use 1-wire for DS18B20 on Odroid N2?


Moan

Recommended Posts

Hi. I recently purchased a few DS18B20 sensors.

I'm having troubles setting up 1-wire on the newest armbian:

root@odroidn2:~# uname -a
Linux odroidn2 5.8.5-meson64 #20.08.1 SMP PREEMPT Tue Sep 1 18:47:20 CEST 2020 aarch64 GNU/Linux

 

My DS18B20 adapter is connected to "GPIOX_7(#)" as suggested on Odroid forum: https://forum.odroid.com/viewtopic.php?p=305664#p305664

 

 n2_pinmap.png

 

Using the official Ubuntu 18.04 image with 4.9.230-76, I was able to find devices in "/sys/bus/w1/devices".

 

Now, I'm trying to do the same thing on Armbian.

I added to: /boot/armbianEnv.txt

overlays=w1-gpio
param_w1_pin=GPIOX_7
param_w1_pin_int_pullup=1

(not sure if GPIOX_7 is the correct name here. When can I find information about pin names?)

 

After reboot:

modprobe w1-gpio && modprobe w1-therm

 

root@odroidn2:~# ls -l /sys/bus/w1/devices
total 0

 

/sys/kernel/debug/gpio also shows nothing "onewire" related:

root@odroidn2:~# cat /sys/kernel/debug/gpio
gpiochip1: GPIOs 412-426, parent: platform/ff800000.sys-ctrl:pinctrl@14, aobus-banks:
 gpio-420 (                    |regulator-tflash_vdd) out hi
 gpio-421 (                    |TF_IO               ) out hi
 gpio-422 (                    |pwm                 ) out lo
 gpio-423 (                    |n2:blue             ) out lo

gpiochip0: GPIOs 427-511, parent: platform/ff634400.bus:pinctrl@40, periphs-banks:
 gpio-427 (                    )
 gpio-428 (                    )
 gpio-429 (                    )
 gpio-430 (                    )
 gpio-431 (                    )
 gpio-432 (                    )
 gpio-433 (                    )
 gpio-434 (                    )
 gpio-435 (                    )
 gpio-436 (                    )
 gpio-437 (                    )
 gpio-438 (                    )
 gpio-439 (                    )
 gpio-440 (                    )
 gpio-441 (                    )
 gpio-442 (                    )
 gpio-443 (                    )
 gpio-444 (                    )
 gpio-445 (                    )
 gpio-446 (                    )
 gpio-447 (                    |usb-hub-reset       ) out hi
 gpio-448 (                    |regulator-hub_5v    ) out hi
 gpio-449 (                    |regulator-usb_pwr_en) out lo
 gpio-450 (                    )
 gpio-451 (                    )
 gpio-452 (                    )
 gpio-453 (                    )
 gpio-454 (                    )
 gpio-455 (                    )
 gpio-456 (                    )
 gpio-457 (                    )
 gpio-458 (                    )
 gpio-459 (                    )
 gpio-460 (                    )
 gpio-461 (                    )
 gpio-462 (                    )
 gpio-463 (                    )
 gpio-464 (                    |reset               ) out hi ACTIVE LOW
 gpio-465 (                    )
 gpio-466 (                    )
 gpio-467 (                    )
 gpio-468 (                    )
 gpio-469 (                    )
 gpio-470 (                    )
 gpio-471 (                    )
 gpio-472 (                    )
 gpio-473 (                    )
 gpio-474 (                    |cd                  ) in  lo ACTIVE LOW
 gpio-475 (                    )
 gpio-476 (PIN_44              )
 gpio-477 (PIN_46              )
 gpio-478 (PIN_45              )
 gpio-479 (PIN_47              )
 gpio-480 (PIN_26              )
 gpio-481 (                    )
 gpio-482 (                    )
 gpio-483 (                    )
 gpio-484 (                    )
 gpio-485 (                    )
 gpio-486 (                    )
 gpio-487 (PIN_42              )
 gpio-488 (PIN_32              )
 gpio-489 (PIN_7               )
 gpio-490 (PIN_27              )
 gpio-491 (PIN_28              )
 gpio-492 (PIN_16              )
 gpio-493 (PIN_18              )
 gpio-494 (PIN_22              )
 gpio-495 (PIN_11              )
 gpio-496 (PIN_13              )
 gpio-497 (PIN_33              )
 gpio-498 (PIN_35              )
 gpio-499 (PIN_15              )
 gpio-500 (PIN_19              )
 gpio-501 (PIN_21              )
 gpio-502 (PIN_24              )
 gpio-503 (PIN_23              )
 gpio-504 (PIN_8               )
 gpio-505 (PIN_10              )
 gpio-506 (PIN_29              )
 gpio-507 (PIN_31              )
 gpio-508 (PIN_12              )
 gpio-509 (PIN_3               )
 gpio-510 (PIN_5               )
 gpio-511 (PIN_36              )

 

Any help would be very appreciated.

Link to comment
Share on other sites

On 9/8/2020 at 5:23 PM, Moan said:

Any help would be very appreciated.

Overlays on meson64 are tough and not well supported in Armbian.

Even different Amlogic SoCs pinctrl are not compatible between them.

 

I've took a quick look at my OdroidN2, and it seems that GPIOX_7 is pin 72.

So, I've created a quick overlay source provided below, although I didn't attached any DS18B20, it seems to work :

/dts-v1/;

/ {
	compatible = "amlogic,meson-gxbb";

	fragment@0 {
		target-path = [ 2f 00 ];

		__overlay__ {

			onewire@0 {
				compatible = "w1-gpio";
				pinctrl-names = "default";
				gpios = < 0xffffffff 0x48 0x06 >;
				status = "okay";
				phandle = < 0x01 >;
			};
		};
	};

	__symbols__ {
		w1 = "/fragment@0/__overlay__/onewire@0";
	};

	__fixups__ {
		gpio = "/fragment@0/__overlay__/onewire@0:gpios:0";
	};
};

Executing the command "cat /sys/kernel/debug/gpio" provided me the following output, and as we can see the w1 bus appeared :

gpiochip1: GPIOs 412-426, parent: platform/ff800000.sys-ctrl:pinctrl@14, aobus-banks:
 gpio-420 (                    |regulator-tflash_vdd) out hi 
 gpio-421 (                    |TF_IO               ) out lo 
 gpio-423 (                    |n2:blue             ) out lo 

gpiochip0: GPIOs 427-511, parent: platform/ff634400.bus:pinctrl@40, periphs-banks:
 gpio-442 (                    |PHY reset           ) out hi ACTIVE LOW
 gpio-447 (                    |usb-hub-reset       ) in  hi 
 gpio-448 (                    |regulator-hub_5v    ) out hi 
 gpio-449 (                    |regulator-usb_pwr_en) out lo 
 gpio-464 (                    |reset               ) out hi ACTIVE LOW
 gpio-474 (                    |cd                  ) in  hi ACTIVE LOW
 gpio-499 (                    |onewire@0           ) out hi 

Hoping this helped ...

Link to comment
Share on other sites

I spend some time to get a DS18B20 sensor working on my Odroid C2 and actually it has been working fine for the last year.

 

I activated the overlay in armbianEnv.txt

overlay_prefix=meson
overlays=w1-gpio

Most work was to figure out which pin to configure. I selected pin #7, which is GPIOX.21 (by looking at the layout) and hardware pin 113 (by looking at the header file). I guess, numbers are going to look different for the N2.

https://wiki.odroid.com/odroid-c2/hardware/expansion_connectors

https://github.com/Xilinx/linux-xlnx/blob/master/include/dt-bindings/gpio/meson-gxbb-gpio.h

 

I configured the pin and that was it.

fdtget /boot/dtb/amlogic/overlay/meson-w1-gpio.dtbo /fragment@0/__overlay__/onewire@0 gpios
fdtput /boot/dtb/amlogic/overlay/meson-w1-gpio.dtbo /fragment@0/__overlay__/onewire@0 gpios 18 113 0

 

You can then query the temperature via the filesystem. Very convenient.

cat /sys/bus/w1/devices/28-00000a2ab1aa/hwmon/hwmon1/temp1_input

 

Edited by Helmut
Link to comment
Share on other sites

Thank you for the replies!

 

I was able to solve the problem thanks to "tobetter" from odroid forum: https://forum.odroid.com/viewtopic.php?p=305720#p305720

 

I have it fully working on kernel 5.8. What I did was:

Adding the following to /boot/armbianEnv.txt:

overlay_resize=16384
overlays="moan_onewire"
dtb_loadaddr="0x10000000"
dtbo_addr_r="0x11000000"
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u,0x1058:0x25ee:u

 

Editing /boot/boot.ini:


# Moan Onewire Fix:

fdt addr ${dtb_loadaddr}

if test "x{overlays}" != "x"; then
    fdt resize ${overlay_resize}
    for overlay in ${overlays}; do
        #load mmc ${devno}:1 ${dtbo_addr_r} boot/dtb/amlogic/overlays/odroidn2/${overlay}.dtbo \
        #load mmc ${devno}:1 ${dtbo_addr_r} boot/dtb/amlogic/overlay/${overlay}.dtbo \
        load mmc ${devno}:1 ${dtbo_addr_r} boot/${overlay}.dtbo \
            && fdt apply ${dtbo_addr_r}
    done
fi
# End of Moan Onewire Fix

if test "${kernelimage}" = "zImage"; then

...

 

Pasting file: "moan_onewire.dtbo" to /boot:

https://www33.zippyshare.com/v/U5WiziQl/file.html

 

This is a file from the official kernel 4.9.something.  It started to work on PIN 19 (GGPIOX_8).

 

I tried many combinations of file /boot/armbianEnv.txt, including the one suggested by @Helmut, however it newer showed w1/onewire or anything like that in "cat /sys/kernel/debug/gpio". Also folder "/sys/bus/w1/" was not created on reboot (until modprobe). So something wasn't loading. Now it works nicely for me:

 

CWowQFf.png

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines