Difference between revisions of "DS18B20"

From Review or Discard at Will
Jump to: navigation, search
(Code: add .py gpio version code)
Line 8: Line 8:
  
 
==Raspberry Pi==
 
==Raspberry Pi==
==Schematic==
+
===Schematic===
 
[[File:Rpi2-DS18B20.png|600px]]
 
[[File:Rpi2-DS18B20.png|600px]]
==Code==
+
===Code===
===RPi.GPIO version===
+
====RPi.GPIO version====
 
<source lang="bash">
 
<source lang="bash">
 
root@rpi2:~# python
 
root@rpi2:~# python
Line 23: Line 23:
 
</source>
 
</source>
  
 
+
====Setup 1 wire====
<source lang="text">
+
<source lang="bash">
 
# add this line to /boot/config.txt
 
# add this line to /boot/config.txt
 
dtoverlay=w1-gpio
 
dtoverlay=w1-gpio
Line 38: Line 38:
 
</source>
 
</source>
  
 
+
====Read and display====
 
<source lang="python">
 
<source lang="python">
  

Revision as of 15:54, 4 May 2017

DS18B20

DS18B20

Pinout

Ds18b20-pinout.jpg DS18B20 Image found here

Resources

1-Wire at wikipedia.

Raspberry Pi

Schematic

Rpi2-DS18B20.png

Code

RPi.GPIO version

root@rpi2:~# python
Python 2.7.3 (default, Jun 22 2016, 03:14:32)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.VERSION
'0.6.2'
>>>

Setup 1 wire

# 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

Read and display

#!/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


Resources

BBB

Resources

Arduino

Resources