The Raspberry Pi has a 1-wire bus which can be enabled on GPIO4. It provides low-speed data, signaling, and power over a single conductor. This is commonly used on the Pi to connect low-cost sensors devices such as the DS18B20 temperature sensor.
Step 1 – Enable 1-wire Interface
The default Raspbian image disables the interface by default so before you can use it we must make a configuration change. This can be done using either of three methods. I’ll describe all methods but the first one is probably easier and quicker.
Method 1 – Using “Raspi-config” on Command Line
From the command line or Terminal window start by running the following command :
This will launch the raspi-config utility. Select “Interfacing Options” :
Highlight the “1-wire” option and activate “<Select>” :
Select and activate “<Yes>” :
Highlight and activate “<Ok>” :
When prompted to reboot highlight and activate “<Yes>” :
The Raspberry Pi will reboot and the interface will be enabled ready for use.
Method 2 – Using “Raspberry Pi Configuration”
If your Pi boots to the desktop you can either open a Terminal window and use Method 2 or use the graphical tool “Raspberry Pi Configuration”. This is found under : Menu > Preferences > Raspberry Pi Configuration
Then you simply need to select the “Interfaces” tab and set 1-Wire to “Enabled” :
Click the “OK” button. If prompted to reboot select “Yes” so that the changes will take effect.
The 1-Wire interface will be enabled when the Raspberry Pi has rebooted.
Method 3 – Enabling By Editing A File Manually
This process assumes you are using the latest Raspbian build from the official downloads page. You can update your current image using :
sudo apt-get update sudo apt-get upgrade
To enable the interface on the Pi we need to make a modification to a system file :
sudo nano /boot/config.txt
Add the following line at the bottom :
Use CTRL-X, then Y, then RETURN to save the file and exit.
This will use Pin 7 (GPIO4) by default.
Reboot using the following :
Listing Attached 1-Wire Devices
With the interface enabled you can list all discovered devices using the following command :
A full list of tutorials featuring this interface can be found by clicking here.
Reading temperature with the popular DS18B20 temperature sensor is explained in the Using DS18B20 Digital Temperature Sensors with the Raspberry Pi post.
Finally, there is more technical information about 1-Wire interfaces on the Wikipedia page if you are interested.