Raspberry Pi 4 with 1-Wire Temperature Sensor and FreeBSD 13.1

In the net we find outdated instructions on how to use the 1-Wire temperature sensor DS18B20 of Maxim Integrated with FreeBSD. Nowadays, things turn out a tad simpler.

The Connections

Download the Datasheet of the DS18B20 sensor provided by Maxim Integrated. On page 1 you will find the pin assignment of the sensor.

  1. Connect pin 1 (GND) of the sensor to the physical pin 6 of Raspberry’s GPIO expansion header.
  2. Connect pin 2 (DQ = Data in/out) of the sensor to the physical pin 7 (GPIO 4) of RPI’s header.
  3. Connect pin 3 (VDD) of the sensor to the physical pin 1 (Power 3.3 V) of the RPI’s header.
  4. In parallel over connections 2 and 3 connect a pullup resistor in the range of 4.7 to 10 kΩ.

FreeBSD System Configuration

The device tree of the Raspberry Pi needs to be configured for the 1-Wire sensor on GPIO 4. This is done by a device tree overlay whose source can be downloaded from the Raspberry Linux repository on GitHub:


This must be compiled into a device tree overlay blob and placed into /boot/msdos/overlays/:

   dtc -I dts -O dtb -b0 -@ -o /boot/msdos/overlays/w1-gpio.dtbo w1-gpio-overlay.dts

Add the following line to /boot/msdos/config.txt:


Add the following lines to /boot/loader.conf:


Now restart the system.

For a temperature read out, enter the following command:

sysctl dev.ow_temp.0.temperature
 → dev.ow_temp.0.temperature: 20.687C

Copyright © Dr. Rolf Jansen - 2022-09-04 20:07:56

Discussion on Twitter: 1566526869444386819