Automated chilli watering system part 3 - Temperature


This post is part of a series


Temperature

This part is entirely option, if it looks too complicated, feel free to skip this part and do without temperature monitoring

For this part of the project I used the following 3 wire sensors https://www.amazon.de/gp/product/B00CHEZ250/ref=oh_aui_detailpage_o08_s00?ie=UTF8

In one way, this was kind of complicated as it requires a kernel module to be loaded in order to use, but rest assured, its quite simple

Just add the following line to /boot/config.txt and reboot

dtoverlay=w1-gpio

I actual fact, as I wanted to use a different GPIO pin than the default, I went with this

dtoverlay=w1-gpio,gpiopin=21

Once this is in place 8and you have rebooted) you will see that /sys/bus/w1/devices/ has been populated and you will need to use your own device IDs that you find in the directory

Below is a simple script I created to checking two sensors.

/usr/local/bin/get-probe-temps.py
#!/usr/bin/python
#
# This depends on a kernel module and the gpio port
# defaults to port 4. It seems as if it can be changed
# by altering the /boot/config.txt to add this
#    dtoverlay=w1-gpio,gpiopin=21
#

import os
import sys
import time
from time import gmtime, strftime

# commented out as its now done at boot time
# os.system('modprobe w1-gpio')
# os.system('modprobe w1-therm')

temp_sensor1 = '/sys/bus/w1/devices/28-0416c2345eff/w1_slave'
temp_sensor2 = '/sys/bus/w1/devices/28-0516c00e7dff/w1_slave'


def temp_raw(val):
	f = open(val, 'r')
	lines = f.readlines()
	f.close
	return lines

def read_temp(sensor):
	lines = temp_raw(sensor)
	while lines[0].strip()[-3:] != 'YES':
		time.sleep(0.2)
		lines = temp_raw()
	temp_output = lines[1].find('t=')
	if temp_output != -1:
		temp_string = lines[1].strip()[temp_output+2:]
		temp_c = float(temp_string) / 1000
		return temp_c

if sys.argv[1]=='one':
	one = read_temp(temp_sensor1)
	print one

if sys.argv[1]=='two':
        two = read_temp(temp_sensor2)
        print two

Its called with a simple

python /usr/local/bin/get-probe-temps.py "one"

or

python /usr/local/bin/get-probe-temps.py "one"

Reference

See also