Skip to content

Commit

Permalink
Support for DS180 temp sensor added
Browse files Browse the repository at this point in the history
  • Loading branch information
cymplecy committed Jan 17, 2014
1 parent 1ba0610 commit b62a750
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 25 deletions.
2 changes: 2 additions & 0 deletions ds.sh
@@ -0,0 +1,2 @@
sudo modprobe w1-gpio
sudo modprobe w1-therm
Binary file modified install_scratchgpio4.sh
Binary file not shown.
Binary file modified installer/install_scratchgpio4.sh
Binary file not shown.
Binary file modified installer/payload.tar.gz
Binary file not shown.
10 changes: 10 additions & 0 deletions installer/payload/scratchgpio_handler4.py
Expand Up @@ -2096,6 +2096,16 @@ def run(self):
sensor_name = 'ipaddress'
bcast_str = 'sensor-update "%s" %s' % (sensor_name, "ip"+ipaddr)
self.send_scratch_command(bcast_str)

if self.bFind("gettemp"): #find temp address
dsSensorId = sghGC.findDS180()
print "ds:", dsSensorId
if dsSensorId <> "":
print "getting temp"
temperature = sghGC.getDS180Temp(dsSensorId)
sensor_name = 'temperature'
bcast_str = 'sensor-update "%s" %s' % (sensor_name, str(temperature))
self.send_scratch_command(bcast_str)



Expand Down
35 changes: 35 additions & 0 deletions installer/payload/sgh_GPIOController.py
Expand Up @@ -287,6 +287,41 @@ def pinServod(self, pin, value):
def stopServod(self):
os.system("sudo pkill -f servod")

def findDS180(self):
dsSensorId = ""
print ("Starting DS180")
try:
os.system('sudo modprobe w1-gpio')
os.system('sudo modprobe w1-therm')
possSensors = os.listdir('/sys/bus/w1/devices')
#print possSensors
for loop in possSensors:
if loop[:2] == "28":
dsSensorId = loop
except:
pass
print dsSensorId
return dsSensorId

def getDS180Temp(self,dsSensorId):
temperature = -300.0
try:
tfile = open("/sys/bus/w1/devices/"+ dsSensorId +"/w1_slave")
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
tfile.close()
# Split the text with new lines (\n) and select the second line.
secondline = text.split("\n")[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(" ")[9]
# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:]) / 1000.0
except:
pass
print temperature
return temperature




Expand Down
10 changes: 10 additions & 0 deletions scratchgpio_handler4.py
Expand Up @@ -2096,6 +2096,16 @@ def run(self):
sensor_name = 'ipaddress'
bcast_str = 'sensor-update "%s" %s' % (sensor_name, "ip"+ipaddr)
self.send_scratch_command(bcast_str)

if self.bFind("gettemp"): #find temp address
dsSensorId = sghGC.findDS180()
print "ds:", dsSensorId
if dsSensorId <> "":
print "getting temp"
temperature = sghGC.getDS180Temp(dsSensorId)
sensor_name = 'temperature'
bcast_str = 'sensor-update "%s" %s' % (sensor_name, str(temperature))
self.send_scratch_command(bcast_str)



Expand Down
35 changes: 35 additions & 0 deletions sgh_GPIOController.py
Expand Up @@ -287,6 +287,41 @@ def pinServod(self, pin, value):
def stopServod(self):
os.system("sudo pkill -f servod")

def findDS180(self):
dsSensorId = ""
print ("Starting DS180")
try:
os.system('sudo modprobe w1-gpio')
os.system('sudo modprobe w1-therm')
possSensors = os.listdir('/sys/bus/w1/devices')
#print possSensors
for loop in possSensors:
if loop[:2] == "28":
dsSensorId = loop
except:
pass
print dsSensorId
return dsSensorId

def getDS180Temp(self,dsSensorId):
temperature = -300.0
try:
tfile = open("/sys/bus/w1/devices/"+ dsSensorId +"/w1_slave")
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
tfile.close()
# Split the text with new lines (\n) and select the second line.
secondline = text.split("\n")[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(" ")[9]
# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:]) / 1000.0
except:
pass
print temperature
return temperature




Expand Down
62 changes: 37 additions & 25 deletions temptest2.py
@@ -1,27 +1,39 @@
#!/usr/bin/env python

import time

sensorids = ["28-00000534e8db", "28-00000534e8db"]
avgtemperatures = []
for sensor in range(len(sensorids)):
temperatures = []
for polltime in range(0,5):
tfile = open("/sys/bus/w1/devices/"+ sensorids[sensor] +"/w1_slave")
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
tfile.close()
# Split the text with new lines (\n) and select the second line.
secondline = text.split("\n")[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(" ")[9]
# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:])
# Put the decimal point in the right place and display it.
temperatures.append(temperature / 1000)
time.sleep(1)
temperatures = sorted(temperatures)
#del temperatures[6]
#del temperatures[0]
avgtemperatures.append(sum(temperatures) / float(len(temperatures)))
import os

os.system('sudo modprobe w1-gpio')
os.system('sudo modprobe w1-therm')
possSensors = os.listdir('/sys/bus/w1/devices')
#print possSensors
dsSensorId = "28"
for loop in possSensors:
if loop[:2] == "28":
dsSensorId = loop

temperatures = []

for polltime in range(0,5):
tfile = open("/sys/bus/w1/devices/"+ dsSensorId +"/w1_slave")
# Read all of the text in the file.
text = tfile.read()
# Close the file now that the text has been read.
tfile.close()
# Split the text with new lines (\n) and select the second line.
secondline = text.split("\n")[1]
# Split the line into words, referring to the spaces, and select the 10th word (counting from 0).
temperaturedata = secondline.split(" ")[9]
# The first two characters are "t=", so get rid of those and convert the temperature from a string to a number.
temperature = float(temperaturedata[2:]) / 1000.0
# Put the decimal point in the right place and display it.

print avgtemperatures
temperatures.append(temperature )
print temperature
# time.sleep(1)
temperatures = sorted(temperatures)
#del temperatures[6]
#del temperatures[0]
avgtemperature =(sum(temperatures) / float(len(temperatures)))

print "average" , avgtemperature

0 comments on commit b62a750

Please sign in to comment.