Raspberry Pi Workshop Kit Tutorials – 7 Temperature Sensor

Опубликовано: 15 Июнь 2017
на канале: HiPi io
3,179
15

Welcome to the Raspberry Pi Workshop Tutorials, brought to you by ModMyPi, BuyaPi.ca, and PiShop.us. In this series, we’ll demonstrate nine projects that can be made using the YouTube Workshop Kit for Raspberry Pi. These projects are a great way to familiarize yourself with the Pi’s input and output functions, as well as creating programs in Python that we’ll use to control the Pi’s hardware.

Tutorial 7 - Temperature Sensor
Circuit Diagram: http://www.modmypi.com/download/led_b...
Tutorial 7 Download: http://www.modmypi.com/download/youtu...
View Tutorial Online: https://www.modmypi.com/blog/youtube-...

** Code Used In This Tutorial **

#!/usr/bin/python

import glob
from time import sleep

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines

def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c, temp_f

while True:
print(read_temp())
sleep(1)


На этой странице сайта вы можете посмотреть видео онлайн Raspberry Pi Workshop Kit Tutorials – 7 Temperature Sensor длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь HiPi io 15 Июнь 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 3,179 раз и оно понравилось 15 зрителям. Приятного просмотра!