Fine.bobdee wrote: . . .
I'm installing a heating system, controlled by the Pi. I have DS18B20 temperature sensors connected to the Pi's GPIO4 (WiringPi 7). That pin is hardwired for the DS18B20, but you can daisy chain several (they are each addressable by their unique ID numbers). Enough DS18B20s will let the controller collect readings of room temp, solar panel temp, hot water cylinder etc.
Seems, like me, your hardware is sufficiently organised.I have a prototype wired up on a breadboard (with 7 leds where the relay will go) and a little bash script to record the room temperature, switch on the circuits as required, and display a nice little text-only screen to show ambient temperature and what's currently on/off. I can SSH into the Pi to set it up and modify it, and I'm going to provide a webpage (served up by a Lighttpd server on the Pi) to give me a means of checking and setting the whole system from any device on the network - even my Android smartphone.
I started with Dartmouth Basic, then to Forth, via compiled Basic to Delphi. PDP8's, homebrew 8085 kits, then Sinclairs, now use other-peoples bright ideas for PCs and now Linux.All very neat. Clearly bash is OK for proof-of-concept but a little too klunky for production use, so I want to switch to FP. And I say FP not Lazarus because I don't want the processing overhead of windows, buttons, graphic object event handlers etc for a program that just sits and gets on with its job quietly. FP is perfect for it (I used to code in Turbo Pascal back in the last century).
Very similar paths, my primary one is for egg incubators, for endangered-species rehab and release, hence the need to measure temperatures and control rotator motors and heaters. A second need is for humidity control (increasing it) and producing warm vapour.BTW I am also hoping to develop this into something I can use for teaching 11-year olds at school. Does it look like we are treading a similar path...?
Code: Select all
#!/bin/bash
NONE='\033[00m'
RED='\033[01;31m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
PURPLE='\033[01;35m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
AtYx ()
#Force Cursor Position <ESC>[{ROW};{COLUMN}f ...so 8,10 would be: echo '\033[8;12f'
{
if test ${4+defined}; then echo -e "$4"; fi
echo -e -n "\033[$1;$2f$3\033[20;30f${NONE}"
}
clear
echo -e " ${UNDERLINE}The Heat Bank project${NONE}\n"
echo ""
echo -e " ${RED}Wood burning stove${NONE}, ${CYAN}Gas boiler${NONE} and ${YELLOW}solar hot water${NONE} contol panel."
# NEED TO END THE ESCAPED STUFF WITH: tput sgr0
setup ()
{
AtYx 20 30 "SETTING UP" "${YELLOW}"
S=1
for i in 8 9 0 2 3 12 14 ; do
AtYx $(( 5 + $S )) 10 "Pump $S status is [ ]" "${PURPLE}"
((S++))
gpio mode $i out ;
done
}
setup
temp=`cat /sys/bus/w1/devices/28-00000492b470/w1_slave | tail -n 1 | cut -d= -f2`
mytemp=`echo "scale=2; $temp/1000" | bc`
AtYx 22 3 "Temp is: $mytemp deg. C"
while true; do
S=1
for i in 8 9 0 2 3 12 14 ; do
AtYx $(( 5 + $S )) 28 "OFF" "${RED}"
((S++))
gpio write $i 0
sleep 0.3
done
AtYx 20 30 "ALL TURNED OFF" "${RED}"
sleep 1
S=1
for i in 8 9 0 2 3 12 14 ; do
AtYx $(( 5 + $S )) 28 "ON " "${GREEN}"
((S++))
gpio write $i 1
sleep 0.3
done
AtYx 20 30 "ALL TURNED ON " "${GREEN}"
sleep 1
done
Code: Select all
Program ShowDS18B20_temp; //polls a named temperature sensor and displays the temp in centigrade
Uses Crt, Unix;
Var temp,MySensor:string;
Function DS18B20_temp(ID:string) : string;
Var f:text; i:integer; s:string; tempfound:boolean; //c:char; l:longint; temperature:string;
begin
tempfound:=false; i:=0;
repeat
Assign (f,'/sys/bus/w1/devices/28-' + ID + '/w1_slave');
Reset(f); Readln(f,s); tempfound:=pos ('YES',s)>0;
if tempfound then begin
Readln(f,s); i:=pos('t=',s) + 2;
DS18B20_temp:=Copy(s,i,2) + '.' + Copy(s,i+2,2);
end;
i:=succ(i);
until tempfound or (i=30);
end;
begin
MySensor:='00000492b470';
temp:=DS18B20_temp(MySensor);
Writeln('Temp at probe "' + MySensor + '" is: ' + temp + 'C');
end.