Setting up the 1-wire interface for the RPi
- Page ID
- 40068
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\dsum}{\displaystyle\sum\limits} \)
\( \newcommand{\dint}{\displaystyle\int\limits} \)
\( \newcommand{\dlim}{\displaystyle\lim\limits} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\(\newcommand{\longvect}{\overrightarrow}\)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\ket}[1]{\left| #1 \right>}\)
\(\newcommand{\bra}[1]{\left< #1 \right|}\)
\(\newcommand{\braket}[2]{\left< #1 \vphantom{#2} \right| \left. #2 \vphantom{#1} \right>}\)
\(\newcommand{\braopket}[3]{\left< #1 \vphantom{#2}\vphantom{#3} \right| #2 \vphantom{#1}\vphantom{#3} \left| #3 \vphantom{#1}\vphantom{#2} \right>}\)
\(\newcommand{\qmvec}[1]{\mathbf{\vec{#1}}}\)
\(\newcommand{\op}[1]{\hat{\mathbf{#1}}}\)
\(\newcommand{\expect}[1]{\langle #1 \rangle}\)
\(\newcommand{\dfn}[1]{\emph{\textbf{#1}}}\)
Setting up the 1-wire interface using the DS18B20 Temperature Sensor.

First enable the 1-wire interface on the RPi.
The following link demonstrates three methods for enabling 1-Wire Interface on the Raspberry Pi.
https://www.raspberrypi-spy.co.uk/2018/02/enable-1-wire-interface-raspberry-pi/
Methods, 1 and 2 use ‘sudo raspi-config’ or the GUI to enable 1-Wire.
Using ‘sudo raspi-config’ or the GUI will setup the default Pin 7 (GPIO4) port.
Method 3 shows how to enable 1-Wire Interface by editing the /boot/config.txt.
Understanding the manual editing of the /boot/config.txt file is essential for connecting two 1-Wire devices.
In the following example two gpiopins are initialized for 1-Wire interface, gpiopin=4 and gpiopin=5.
pi@aquaponics$ tail -6 /boot/config.txt [all] #dtoverlay=vc4-fkms-v3d dtoverlay=w1-gpio,gpiopin=4 dtoverlay=w1-gpio,gpiopin=5
If only one 1-Wire Interface is needed the following methods can be used;

Activate the 1-wire interface as shown here;

Enabling the 1-wire interface can also be accomplished remotely using ssh on the terminal.
sudo raspi-config

Activate the 1-wire interface as shown here;


After enabling the 1-Wire Interface by any method a reboot is required.
Attached the DS18B20 to the breadboard as shown in the following link;
https://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing?view=all
A 4.7K resistor is required, see wiring in the link above.
Attached 1-Wire devices can be listed with the following command;
ls /sys/bus/w1/devices/
For this example two DS18B20 sensors are shown.
pi@aquaponics$ ls /sys/bus/w1/devices/ 28-3c01b5569d9e 28-3c01b556bce8 w1_bus_master1 w1_bus_master2
The IDs for the two are 28-3c01b5569d9e and 28-3c01b556bce8.
These IDs are required for collecting data from the sensors.
The python script used in this example was found here;
https://www.raspberrypi-spy.co.uk/2013/03/raspberry-pi-1-wire-digital-thermometer-sensor/
The wget command can be used to download the python script.
wget https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/ds18b20.py
Note: in the python script ds18b20.py replace the device ID 28-00000482b243 with the ID for the device you are using.
The following link demonstrates how to setup one gpio port for several 1-wire devices.
https://raspberryautomation.com/connect-multiple-ds18b20-temperature-sensors-to-a-raspberry-pi/
The following fritzing diagram was found in the above link.

Note: when one of the two DS18B20 sensors failed the solution was to shut-down the RPi and reseat the pins into the breadboard. Both sensors were again showing up in the system.

