Skip to main content
Engineering LibreTexts

Setting up the 1-wire interface for the RPi

  • Page ID
    40068
  • Setting up the 1-wire interface using the DS18B20 Temperature Sensor.

     

    smaller-ds18b20.png

     

    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;

    clipboard_e145f89bcf38333a047c409efd7375056.png

    Activate the 1-wire interface as shown here;

    clipboard_e46ec6faa618f1cac6f5b0abbab2c4ed2.png

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

    sudo raspi-config
    

    clipboard_ef689740626bf08d5d6d123fdce077166.png

    Activate the 1-wire interface as shown here;

    clipboard_ee6a8c3f354d0d0ab1844c7b7086618e3.png

    clipboard_e67e0856685c3c11153698be9fcc7c4e0.png

    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.

    clipboard_e80dd405f2cec899cf4fb392289952d86.png

     

     

     

    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.

     

     

     

     

     

     

     

     

    • Was this article helpful?