Skip to main content
Engineering LibreTexts

Setting up the 1-wire interface for the RPi

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \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{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#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.



    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

    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;

    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;

    The wget command can be used to download the python script.


    Note: in the python script 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.

    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.









    Setting up the 1-wire interface for the RPi is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?