My Technology Trail avatar

raspi02 temperature test Python code

mytechtrail

Published: 14 May 2019 › Updated: 14 May 2019raspi02 temperature test Python code

raspi02 temperature test Python code

raspi02 temperature test Python code

Here is the Python code that I am testing on raspi02 for monitoring temperatures

#!/usr/bin/python

MIN_TEMP = -100
temp1 = "/sys/bus/w1/devices/28-00000379fea9/w1_slave"
temp2 = "/sys/bus/w1/devices/28-00000620f19e/w1_slave"
temp3 = "/sys/bus/w1/devices/28-000004475127/w1_slave"

def read_temp1():
# open/read/close the file with the temperature
temp1file = open(temp1)
text = temp1file.read()
temp1file.close()

# split the two lines
lines = text.split("\n")

# make sure the crc is valid
if lines[0].find("YES") > 0:
# get the 9th (10th) chunk of text and lose the t= bit
temp = float((lines[1].split(" ")[9])[2:])
# add a decimal point
temp /= 1000
temp = round(temp,2)
return temp
return MIN_TEMP-1

def read_temp2():
# open/read/close the file with the temperature
temp2file = open(temp2)
text = temp2file.read()
temp2file.close()

# split the two lines
lines = text.split("\n")

# make sure the crc is valid
if lines[0].find("YES") > 0:
# get the 9th (10th) chunk of text and lose the t= bit
temp = float((lines[1].split(" ")[9])[2:])
# add a decimal point
temp /= 1000
temp = round(temp,2)
return temp
return MIN_TEMP-1

def read_temp3():
# open/read/close the file with the temperature
temp3file = open(temp3)
text = temp3file.read()
temp3file.close()

# split the two lines
lines = text.split("\n")

# make sure the crc is valid
if lines[0].find("YES") > 0:
# get the 9th (10th) chunk of text and lose the t= bit
temp = float((lines[1].split(" ")[9])[2:])
# add a decimal point
temp /= 1000
temp = round(temp,2)
return temp
return MIN_TEMP-1

print("Battery", read_temp1())

print("outside", read_temp2())

print("Outside Deck", read_temp3())

Yes, this code needs a lot of work. That is part of my learning process, throw some test code together and then rework it until it looks and runs more efficiently.

Until next time.

Leave raspi02 temperature test Python code to:

Written by

Projects I am working on, Raspberry Pi, Python and Ham Radio.

Read more #ulog posts


Best Posts From My Technology Trail

We have not curated any of mytechtrail's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From My Technology Trail