Raspberry Pi 4 1-Wire Not Working

Hello,

First time poster and new to Balena OS in general so I apologize in advanced if this topic isn’t in the right place. I’m having trouble getting a Raspberry Pi 4 setup with a 1-wire ds18b20. After setting up a simple circuit I followed the instructions here https://www.balena.io/docs/learn/develop/hardware/i2c-and-spi/ to enable the 1-wire interface.

Nothing is showing in the /sys/bus/w1/devices folder and it seems like the config.txt file never saves the appended line dtoverlay=w1-gpio - I’ve tried powering off the Pi and editing the resin-boot/config.txt file directly on a different computer and I have also tried with the Pi powered up, remounting the filesystem with read+write and editing the config.txt that way too.

The circuit with the ds18b20 has been tested on a Raspberry Pi 3 and Raspberry Pi zero both running Rasbian Buster and it worked fine for both of these devices, and also worked fine when running Balena OS, just not the RPi4 while running Balena OS. I understand Balena somewhat recently started supporting the RPi4 so maybe this interface isn’t completely configured yet? I should mention too when running modprobe w1-gpio && modprobe w1-therm there is no output so those modules seem to be enabled ok, just not showing any w1 devices.

Hey,

Could you share your Dockerfile/docker-compose.yml files.

I assume you’re adding the dtoverlay via the balenaCloud dashboard as BALENA_HOST_CONFIG_dtoverlay ?

Hey richbayliss,

Thanks for the reply. I don’t currently have the RPi4 setup with balenaCloud, didn’t think that was a requirement. Below are the contents of my DockerFile and docker-compose.yml

DockerFile
FROM balenalib/raspberry-pi-debian-python:3.7
WORKDIR /usr/src/app
COPY requirements.txt .
COPY templates/ templates/
COPY frontend/build frontend/build
COPY frontend/public frontend/public
RUN pip install --upgrade pip
RUN apt-get update
&& apt-get install -y --no-install-recommends gcc build-essential libssl-dev libffi-dev python3-dev python3-gpiozero
RUN pip install --no-cache-dir -r requirements.txt
RUN modprobe w1-gpio && modprobe w1-therm
COPY . .
CMD [“python”, “main_gui.py”]

docker-compose.yml

zclimate:
build: ./
expose:
- “8080”
- “5000”
ports:
- “8080”
- “5000”

Hi, thanks for sending the Dockerfile.
It seems the first problem that you mention is not being able to modify the config.txt file with the DT overlay.
You should be able to do this without being connected to BalenaCloud my mounting the SD card on a different computer and editing /resin-boot/config.txt and adding the following line:

dtoverlay=w1-gpio

Remember to cleanly unmount the SD card so that the change gets written to disk. You can try to re-insert the SD card into the reader to verify that the file was modified.

On boot, you should be able to see the change by doing:

cat /mnt/boot/config.txt

Let us know if that works,

Hey alexgg,

Thanks for that info. I did try all of that already and it seems like my changes are being removed on boot? Here’s exactly what I did, I powered off the RPi4 and removed the SD card. Inserted SD card into my Ubuntu machine and made the edits like you mentioned on /resin-boot/config.txt

I saved the file, closed the file, safely removed the SD card. Re-inserted SD card to check my changes were still there and they were. So far so good, but when I went to boot and run the cat command I get this:

root@zclhub:~# cat /mnt/boot/config.txt
gpu_mem=16
enable_uart=1
dtoverlay=vc4-fkms-v3d
arm_64bit=1
dtparam=i2c_arm=on
dtparam=spi=on
dtparam=audio=on
disable_splash=1

I did this process 3 times before I wrote this reply to you so I’m sure I didn’t do anything wrong. I’m not sure why my changes are getting removed after I boot up the Pi.

Hi, the docs here do reference modifying config.txt before the first boot so it is possible they are being overriden by the device supervisor https://www.balena.io/docs/reference/OS/advanced/. Perhaps you could try using the device supervisor API to set the configuration value that way https://www.balena.io/docs/reference/supervisor/supervisor-api/#get-v1devicehost-config. Or you could try reprovisioning the device and making the edit before you boot.

garethtdavies thanks for this I missed that part of the docs. I did a fresh install using Etcher, made my changes to the config.txt file and all is working now with the ds18b20. Thanks again to the balena team for helping me out with this.

1 Like