# Sensors with one-wire connection

1-wire - is a system of communication between devices, developed by Dallas Semiconductor Corp, which provides low-speed data exchange and power by a single wire.

A distinctive feature of this bus is the ability to use only two wires: data and ground. To achieve this, the device includes a 800pF capacitor for storing power and powering the device when using the data line.

Let’s look at one of these things that I found at hand: DS18B20.

## Datasheet

First of all we read the documentation to understand whether this device is suitable and what its capabilities are. So:

• Can be powered from a data line from 3.0V to 5.0V. It’s good.
• The accuracy of $\pm 0.5^\circ C$ in the range from $-10^\circ C$ to $+85^\circ C$.
• Current consumption in the measurement mode: from $1mA$ to $1.5mA$.

Further in the documentation there is a circuit: which I do not like. GPIO output as we saw earlier consists of two transistors. If we set the output low (actually connect to the ground) and at the same time open the pull-up transistor in the proposed scheme, we get fried Raspberry Pi I do not want to take that risk.

## The simpler circuit

So, we put a $4.7k\Omega$ resistor, which gives $\frac{3.3V}{4.7e3}\Omega\approx0.7mA$, if the current is too small to measure the temperature, then we reduce the resistance.

## Software

Why GPIO4? Let’s read /boot/overlays/README:


Name:   w1-gpio
Info:   Configures the w1-gpio Onewire interface module.
Use this overlay if you *don't* need a GPIO to drive an external pullup.
Params: gpiopin                 GPIO for I/O (default "4")

pullup                  Non-zero, "on", or "y" to enable the parasitic
power (2-wire, power-on-data) feature

Name:   w1-gpio-pullup
Info:   Configures the w1-gpio Onewire interface module.
Use this overlay if you *do* need a GPIO to drive an external pullup.
Params: gpiopin                 GPIO for I/O (default "4")

pullup                  Non-zero, "on", or "y" to enable the parasitic
power (2-wire, power-on-data) feature

extpullup               GPIO for external pullup (default "5")



The overlay w1-gpio-pullup is not our option1, but w1-gpio looks attractive. So we will add next line into the file /boot/config.txt:


dtoverlay=w1-gpio,gpiopin=4



Attention

As it turned out, not all yogurts are equally useful (btw, yoghurts are not useful at all, in any way). Some of the DS18B20 are not very successful fakes. In particular, I got both +158ac2 chips that do not work in parasitic mode, that is, I will have to apply voltage to the chips separately:

Check the detection of the thermometer and the correctness of the readings:

$23.125^\circ C$ looks quite plausible

## Multiple sensors

This is the last thing I would like to try today, after all it’s still a tire. To begin with, we will make changes to the breadboard:

Let’s look:

The error $0.313$ fits into the declared accuracy $\pm 0.5^\circ C$.

1. If the transistor for a strong pull-up is opened, and the GPIO of the data channel is turned on as an output and at a low level (due to a driver error), then the Raspberry Pi will burn out.

2. As seen in the picture above the post.