Raspberry Pi & Dallas 1-Wire

The Raspberry Pi has several different serial buses exposed on its GPIO (General Purpose Input/Output) pins, including SPI and I2C but there is no 1-Wire interface. In modern Linux Kernels there is a driver module for 'bit-banging' a 1-Wire interface using a single GPIO pin. In the Raspbian 'wheezy' release the GPIO-4 pin is used.

If all you want to do is to connect a few DS1820 temperature sensors, then very little additional hardware is required and not specific interface board or adapter is required. The 4K7Ω resistor pulling up the data pin (GPIO pin 4) is required (only one required), as the internal pull-up of the RPi gives provides ~50KΩ, which is too much for the sensors.

You must also not use the temperature sensors in parasitic power mode and connect all 3 pins of all the devices. Don't use the DS18x20-P version of this device as the 'P' stands for Parasitic and means that the Vcc pin is not connected.

Pin 4 on the GPIO header is often used by digital I/O boards. It cannot be used for both.

These commands set up the RPi (make sure kernel modules are loaded) to use the 1-Wire capability:
sudo modprobe wire
sudo modprobe w1-gpio
sudo modprobe w1-therm

Loading the modules like this means they will not persist after a reboot. If you need these modules after rebooting your system, then you will have to add them to the end of the file: /etc/modules

List the number of device on the 1-Wire bus:
cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slave_count
This showed 1 device on the bus.

List the devices and IDs on the 1-Wire bus:
cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves
Showed the following device ID:

To test the sensor is working, we read the sensor file using the ID discovered above:
cat /sys/bus/w1/devices/10-0008014d52a6/w1_slave
This displayed the following:
2b 00 4b 46 ff ff 03 10 4e : crc=4e YES
2b 00 4b 46 ff ff 03 10 4e t=21562

The number after the t= is the temperature in milli-degree Celcius.
So this sensor is reading the temperature as 21.562°C.

Testing 1-Wire temperature sensors
We theen removed the power and added a second and third DS1820 sensor.

cat /sys/bus/w1/devices/w1_bus_master1/w1_master_slaves
Shows the following device IDs:
10-0008014d255c = 2nd sensor (Conservatory Temperature)
10-0008014d52a6 = 1st sensor (Conservatory Temperature Floor)
10-0008014d3305 = 3rd sensor (Conservatory Temperature Ceiling)

Get 'Conservatory Temperature':
cat /sys/bus/w1/devices/10-0008014d255c/w1_slave
= 22.250°C

Get 'Conservatory Temperature Floor':
cat /sys/bus/w1/devices/10-0008014d52a6/w1_slave
= 22.312°C

Get 'Conservatory Temperature Ceiling':
cat /sys/bus/w1/devices/10-0008014d3305/w1_slave
= 22.187°C

This shows that with all three sensors in the same (test) location, they produce nice consistent measurements.

1-Wire USB Adptors

DS9490R 1-Wire USB adapter
The 1-Wire DS9490R USB adapter occupies one of the available USB ports and also may require a USB hub, depending on loading.

1-Wire I2C Adptors

The advantage of I2C 1-Wire adapters is that they don't use up one of the valuable USB ports.

AB Electronics 1-Wire-Pi

AB Elecronics 1-wire Pi
The AB Electronics 1-Wire Pi costs £13 each.

Sheep Walk Electronics RPI1

The RPI1 is a very simple PCB consisting of a header to connect to the GPIO connector on your Pi, a 4K7Ω resistor, a DS18B20 temperature sensor and an RJ45 socket and 3-pin screw terminal to allow you to connect your 1-Wire devices.

Sheep Walk Electronics RPI2

The RPI2 is based around a DS2482-100 I2C to 1-Wire IC. It costs £14 but is available at lower cost in kit form.

Sheep Walk Electronics RPI3

The RPI3 is DS2482-800 based 8-channel 1-Wire Master with optional DS1307 RTC. It costs £29 (£32 with the RTC). A device like this would allow you to have a single Raspberry Pi in your loft with a seperate 1-Wire network leading to each room in your house.





We have written our own Java class for reading 1-wire temperature sensors attached to our slave HCS processors (download Java source code)

Share ...
We are on ...
Facebook Twitter
YouTube Flickr Follow us on Pinterest