Difference between revisions of "DS18B20"
(add rpi python code) |
(→Code) |
||
Line 38: | Line 38: | ||
try: | try: | ||
while True: | while True: | ||
− | |||
tempfile = open("/sys/bus/w1/devices/28-80000028ac7c/w1_slave") | tempfile = open("/sys/bus/w1/devices/28-80000028ac7c/w1_slave") | ||
thetext = tempfile.read() | thetext = tempfile.read() | ||
Line 56: | Line 55: | ||
===Resources=== | ===Resources=== | ||
* [http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/ Simple Guide to the RPi GPIO Header and Pins] | * [http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/ Simple Guide to the RPi GPIO Header and Pins] | ||
− | |||
==BBB== | ==BBB== |
Revision as of 15:32, 4 May 2017
DS18B20
Contents
DS18B20
Pinout
Resources
1-Wire at wikipedia.
Raspberry Pi
Schematic
Code
# add this line to /boot/config.txt
dtoverlay=w1-gpio
modprobe w1-gpio
modprobe w1-therm
# device directory
cd /sys/bus/w1/devices
ls -l
# cd to your unique DS18B20 identifier
cat w1_slave
#!/usr/bin/env python
import time
import os
os.system("/sbin/modprobe w1-gpio")
os.system("/sbin/modprobe w1-therm")
try:
while True:
tempfile = open("/sys/bus/w1/devices/28-80000028ac7c/w1_slave")
thetext = tempfile.read()
tempfile.close()
tempdata = thetext.split("\n")[1].split(" ")[9]
temperature = float(tempdata[2:])
temperature = 9.0 / 5.0 * (temperature / 1000) + 32
print temperature
time.sleep(1)
except KeyboardInterrupt:
pass