In this project, you’ll learn to configure the one-wire interface on your Raspberry Pi to provide power and data from a single pin. You will be integrating this with sensors while learning some basics of Python programming.
You should start with a switched-on Raspberry Pi connected to mouse, keyboard and monitor, you can learn here how to do it using an Okdo Pi kit
The temperature sensor will be read by the Pi using what’s known as 1-wire interface. This is a single connection through which data is transfered.
In my case the One-Wire interface is listed as: 28-00000b79859d
The sensor stores the temperature in a file called w1_slave, to list its contents, type the following command and press Return.
In my case the temperature listed was 22375 which is the temperature in Celsisus without the decimal point. This should be read as 22.375° C
From the main menu select Programming/Thonny Pythone IDE
import os import glob import time os.system('modprobe w1-gpio') os.system('modprobe w1-therm') base_dir = '/sys/bus/w1/devices/' device_folder = glob.glob(base_dir + '28*') device_file = device_folder + '/w1_slave' def read_temp_raw(): f = open(device_file, 'r')
You should now see the temperature readings printed at the bottom of the window in both Celsius and Fahrenheit