Restarting the thermometer without having to power cycle the pi
Ok this is kinda alpha stages, but I have come up with a solution that
should work. When it drops out again I can test properly.
The problem is that for some reason, my almost certainly fake/knockoff DS18B20 drops out on occasion. The only way to reset it so far has been to power cycle the pi - and that's an annoyance.
Instead of powering it from the 3v3 rail, I have it powered from a GPIO pin, and since it uses a very minimal amount of current this is supposed to be ok.
I can then control that GPIO pin, and effectively cut power to the sensor without restarting the pi.
My thermometer is connected with the
DATA pin to GPIO4, the default 1-wire input line
VCC is connected to BCM 17 (physical 11)
GND is connected to any ground lead; I used physical 9 since it's right next to the others
In
/etc/rc.local I have:
Code:
#turn on GPIO Pin 17 to power the thermometer with 3.3V
/usr/bin/gpio -g mode 17 out
echo "GPIO pin BCM17 set to OUTPUT"
gpio readall | grep 'GPIO. 0' | grep '\(IN\|OUT\)'
/usr/bin/gpio -g write 17 1
echo "GPIO pin BCM 17 turned ON"
gpio readall | grep 'GPIO. 0' | grep '\(IN\|OUT\)'
(
gpio -g uses BCM numbering to refer to a particular pin)
(The
gpio readall lines are just there to provide some visual feedback of what's going on, they aren't strictly needed)
This is to make sure that on startup the pin is high (+3.3V), so that the thermometer is on at restart.
I have a bash script in the home folder that checks for the presence of my particular probe by checking if its directory is present, and power cycling the GPIO "VCC" pin for a few seconds if it is not:
Code:
#!/bin/bash
echo "Restarting that stupid thermometer"
DIR="/sys/bus/w1/devices/28-xxxxxxxxxx/" #folder for the themometer device
if [ -d "$DIR" ]; then
echo "directory at $DIR exists. No restart needed."
else
echo "directory $DIR exists"
gpio -g mode 17 out && echo "Pin 17 set to OUT mode"
gpio -g write 17 0 && echo "Pin 17 LOW - power off"
echo "Sleeping 3 seconds" && sleep 3
gpio -g write 17 1 && echo "Pin 17 HIGH - power on"
echo "listing devices dir" && ls /sys/bus/w1/devices/
fi
(replace 28-
xxxxxxxxxx with your specific probe hardware address)
I then have a cron job that calls this script on 00 minute of each hour.
crontab -e
Code:
#check and restart the thermometer
00 * * * * /home/pi/restart_therm.sh
Maybe I could actually do this another way, manually. If I create an output on pin 17 in reef-pi, I could then make an equipment entry and toggle that like you would an LED or relay signal within reef-pi. What would make this more fancy is if there was a way for reef-pi to detect a crazy temperature (eg > 80°C or < 0°C), and then call a macro to power cycle the thermometer equipment.
What I don't know is how to get reef-pi to "if some condition x then execute macro y". Yet.
Edit: crontab mistake