1-Wire In todays article we will look at an interesting 1-Wire technology and at how it works together with Raspberry. After the brief introduction, you can look forward to a practical demostration of how to use 1-Wire temperature sensor DS18B20. 1-Wire is a device communications bus system developed by Dallas Smiconductors, simply put, it is a technology providing communication between multiple devices. 1-Wire always has one master device, which runs the communications with the slave devices. This technology is usually used for small and cheap sensors, such as thermometers and other similar devices, that only need low power and transmit only small amounts of data. 1-Wire can work on relatively large distances and needs only 3 wires. Those are power supply, that can be anyting from 3V to 5V, ground and data. Slave devices are all conencted to the same triple of wires. Raspberry and 1-Wire If you want to work with 1-Wire devices on your Raspberry, you first need to enable the 1-Wire protocol. You can do this in Raspberry’s configuration and you have multiple options how to do it. You can change the configuration through the raspi-config wizard. Simply open the console and write: sudo raspi-config Which will give you this screen: Select section 5 Interfacing options Select P7 1-Wire And select Yes to enable 1-Wire The other option is more straightforward. You can edit the configuration file directly from any text editor, for example nano. sudo nano /boot/config.txt Scroll to the bottom of the file and add a new line with: dtoverlay=w1-gpio Save and close the file (press Ctrl+X, Y - as yes to changes and press Enter to confirm). Now you are ready to go! Reboot you Raspberry: sudo shutdown -r And you can start connecting 1-Wire devices. Connecting 1-Wire devices to Raspberry Connecting 1-Wire devices to Raspberry is pretty easy, you only need 1 resistor with resistance between 4k7Ω and 10kΩ, that will be put between power supply and data line. That is it. For demonstration, we will use temperature sensors DS18B20. Get at least two, so we can see that 1-Wire is able to work with multiple devices, even in case they are of the same type. Multiple devices on one line As was said before, 1-Wire always has one master device, which runs the communication - this will be our Raspberry and can have multiple slave devices - those will be temperature sensors in our case and they are all connected to just one data line. You might be asking how will the Raspberry know, which temperature sensor is sending which data, if they both sit on the same wire and the answer is simple. Each 1-Wire device has its own internal ROM memory, that stores unique 64-bit long address or identifier if you want. Every time a sensor sends some data, it also includes its address, so Raspberry always knows, which sensor sent which data. DS18B20 temperature sensor For this tutorial, we are using DS18B20 temperature sensor which is a great sensor with high accuarcy and can handle big range of temperatures. All the details can be found in its datasheet, but lets just point out the important details: power supply from 3V to 5V measures temperatures from -55°C to +125°C (-67°F to +257°F) accuarcy is ±0.5°C for temperatures ranging from -10°C to +85°C It is also goot to know, which DS18B20 pins are for power supply, ground and data: You can buy this sensor on Ebay, its price starts around 1.5 USD. This sensor comes also in a waterproof version, usually with a 2m cable, which makes it ideal for measuring temperatures in pools or refrigirators. Detecting 1-Wire devices Lets get into wiring so we can finally see some real outputs. Grab your Raspberry, DS18B20 sensors and one 4k7Ω resistor. By default, the 1-Wire input pin on Rasperry is GPIO 4 in BCM numbering, but you can change that if you want. Go back to Raspberry’s config file: sudo nano /boot/config.txt And change the line with dtoverlay=w1-gpio to: dtoverlay=w1-gpio,gpiopin=X where X is the desired BCM pin number. Nertheless, for this example, we will work with the default settings. As was already mentioned before, wiring the sensors to the Raspberry is very simple, just connect the power and ground to corresponding sensor pins, connect GPIO4 with data pins and put the 4k7Ω resistor between the power and data line. Now we are ready to read the temperature data. All connected 1-Wire devices will create a folder named after its unique identifier in /sys/bus/w1/devices/. To see the folders, use your command line: ls /sys/bus/w1/devices/ In my case it gives me this output: 28-000009f8259a 28-000009f96000 w1_bus_master1 Lets ignore the w1_bus_master1, the rest of the folders are our sensors. The first two digits tell us, what kind of a sensor we are dealing with, 28 stands for DS18B20 temperature sensor, so everything is working as expected. Detecting all 1-Wire devices I have written a neat python script, that prints out data about all connected 1-Wire devices. You can find it on my
Raspberry Course Greetings! I am very glad that you ended up on my blog, mostly focused on programming and electronics. Since you clicked on this post I guess you are probably looking for some learing material to teach yourself how to run and control you
DHT sensors Have you ever wanted to build your own weather station? Then read further, because today we are going to look at how to measure temperature and humidity with our Raspberry! We are going to use DHT11/22 sensor, which you can get on Ebay for 1
Distance sensor JSN-SR04T If you are in need of measuring distances with your Raspberry, this tutorial is what you where looking for. In this article, we will look at a JSN-SR04T ultrasonic distance sensor. Which is an affordable sensor for your robotics
Raspberry pinouts If you are going to connect some electronics to your Raspberry, no matter if to power them, control them or read dat from them, you will need to use Raspberry’s pinouts, which are those small wires going out of the raspberry in the corn
Hamish Hawk (foto: Richard Simpson of Simpson Studios )