On a Pi 4 I have the following lines in /boot/config.txt
:
dtoverlay=w1-gpio
gpio=4=op,pu
This should enable 1-wire on the default GPIO pin, which is 4, and then enable the internal pullup resistor.
The 1-wire device that I have is a DS18B20, and it's connected via a short cable with external power. No external pullup resistor is attached (e.g. 4.7k resistor.) Parasitic power is therefore not in use. This is a correctly functioning hardware configuration.
However the following command is required after boot in order to enable the internal pullup:
raspi-gpio set 4 pu
After which, everything works as expected.
Before that command is executed, various phantom devices periodically appear in scans as shown by dmesg
:
[ 60.240219] w1_master_driver w1_bus_master1: Attaching one wire slave 00.800000000000 crc 8c
[ 60.254632] w1_master_driver w1_bus_master1: Family 0 for 00.800000000000.8c is not registered.
In addition the pullup appears as disabled.
The 1-wire device works correctly with the internal pullup, but I haven't been able to configure the pullup on boot. I have tried some minor variations with no success. It seems like a band-aid solution to create a systemd unit just to set GPIO pins after boot, but that may be my only option. Is there something I can do with the device tree or GPIO boot option to obtain the expected behavior?
$ raspi-gpio get
BANK0 (GPIO 0 to 27):
GPIO 0: level=1 fsel=0 func=INPUT pull=UP
GPIO 1: level=1 fsel=0 func=INPUT pull=UP
GPIO 2: level=1 fsel=4 alt=0 func=SDA1 pull=UP
GPIO 3: level=1 fsel=4 alt=0 func=SCL1 pull=UP
GPIO 4: level=0 fsel=0 func=INPUT pull=NONE