Here's a link to the video of the blinds in action. I could not have done it without the help from the members of this forum, you all rock!
http://www.instructables.com/id/Computer-Controlled-Window-Blinds/
Here's the code, first the 28x2 on the control board:
Next the 08m on the control board:
Third, the 14m on the window unit. Each unit is given a unique letter as an identifier, so window 1 is "A", window 2 is "B", etc.
And last, the 08m on the window boards, used to add a local push button for control.
I hope this helps anyone attempting something similar, or as a reference for getting good results from the Sparkfun 434 mhz pairs.
Now I just need to make one correction on the PCB (notice the white tape covering the ripped up trace?) and then I can buy the boards for my other windows.
Feel free to ask any questions, and I'll do my best to answer.
Brian
http://www.instructables.com/id/Computer-Controlled-Window-Blinds/
Here's the code, first the 28x2 on the control board:
Code:
'28x2 program for computer interface and blind control
'by Brian (kd5crs)
'12/3/09
'version 10 adds U to the start of each transmission. v9 works great.
symbol transmit = c.2
symbol receive = c.3
symbol TVonoroff = 0
symbol green_led = b.6
symbol p08m28talk = a.1
symbol wloc = b0
symbol wcom = b1
symbol TVadc = b3
symbol counter = w7
symbol coro = b6
symbol LDR1d = b7
symbol LDR2d = b8
symbol Tempd = b9
symbol Blank1 = b10
symbol Blank2 = b11
symbol TVison = b12
symbol LDR1dHund = b30
symbol LDR1dTens = b31
symbol LDR1dOnes = b32
symbol LDR2dHund = b33
symbol LDR2dTens = b34
symbol LDR2dOnes = b35
symbol TempdHund = b36
symbol TempdTens = b37
symbol TempdOnes = b38
symbol trycount = b42
symbol tossit = b25
high green_led
pause 200
low green_led
pause 200
high green_led
pause 200
low green_led
pause 200
high green_led
pause 200
low green_led
Blank1 = 0
Blank2 = 0
'pause 10
'sertxd("Cube interface is online",13,10)
adcsetup = 1
disconnect
gosub NOACK
HOLDINGPATTERN:
trycount = 0
serrxd [5000,TVCHECK],("CI"),wloc,wcom
sertxd("W")
pause 5
sertxd("OK",#0,13,10)
pause 100
goto MAIN
MAIN:
pause 10
serout transmit,N1200_8,(0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55) ' preamble to lock link the tx/rx
pause 5 ' lock link and preamble solution by wolfgang ;0) cheers
serout transmit,N1200_8,("GG",$FF,wloc,$FF,wcom,$00,$00)
pause 5
pause 10
high p08m28talk
'pause 100
high green_led
serin receive,N1200_8,("GG"),tossit,wloc,tossit,coro,tossit,LDR1d,tossit,LDR2d,tossit,Tempd,tossit
low p08m28talk
pause 100
low green_led
gosub ACK
goto HOLDINGPATTERN
ACK:
'if TVison > 2 then BADDATA
'if wloc > 18 then BADDATA
'if coro > 2 then BADDATA
'if Blank1 > 1 then BADDATA
'if Blank2 > 1 then BADDATA
bintoascii LDR1d,LDR1dHund,LDR1dTens,LDR1dOnes
bintoascii LDR2d,LDR2dHund,LDR2dTens,LDR2dOnes
bintoascii Tempd,TempdHund,TempdTens,TempdOnes
'23 bytes
sertxd("-",#TVison,"-",wloc,"-",#coro,"-",LDR1dHund,LDR1dTens,LDR1dOnes,"-",LDR2dHund,LDR2dTens,LDR2dOnes,"-",TempdHund,TempdTens,TempdOnes,"-",#Blank1,"-",#Blank2,13,10)
low green_led
'sertxd("Command successful",13,10)
pause 10
'hsersetup B2400_8,%111
return
NOACK:
low green_led
sertxd("0000000000000000NOACK",13,10)
'sertxd(#TVison,32,#wloc,32,#coro,32,#LDR1d,32,#LDR2d,32,#Tempd,32,#Blank1,32,#Blank2,13,10)
pause 10
high green_led
pause 100
low green_led
pause 100
high green_led
pause 100
low green_led
pause 100
high green_led
pause 100
low green_led
pause 10
return
TVCHECK:
readadc10 TVonoroff,TVadc
pause 10
if TVadc > 35 then
gosub TVON
else
gosub TVOFF
endif
sertxd("W")
pause 5
sertxd("TV",#TVison,13,10)
goto HOLDINGPATTERN
TVON:
'sertxd("TV is on",13,10)
TVison = 1
pause 10
return
TVOFF:
'sertxd("TV is off",13,10)
TVison = 2
pause 10
return
BADDATA:
sertxd("The data is bad. 0000",13,10)
goto HOLDINGPATTERN
Next the 08m on the control board:
Code:
'v2 Change from 5 to 2.5 seconds
symbol p28reset = 4
symbol p08m28talk = pin3
symbol p08mLED = 2
high p28reset
MAIN:
high p08mLED
pause 100
low p08mLED
pause 100
high p08mLED
pause 100
low p08mLED
pause 100
high p08mLED
pause 100
low p08mLED
do while p08m28talk = 0
loop
high p08mLED
pause 2500
if p08m28talk = 1 then
goto RESET28
elseif p08m28talk = 0 then
goto MAIN
endif
goto MAIN
RESET28:
low p28reset
pause 5
high p28reset
low p08mLED
goto MAIN
Third, the 14m on the window unit. Each unit is given a unique letter as an identifier, so window 1 is "A", window 2 is "B", etc.
Code:
'14m program for blinds/sensor board
'version 9, adds U to start of transmissions
'by Brian (kd5crs)
'12/3/09
symbol transmit = 5
symbol receive = 2
symbol green_led = 4
symbol wloc = b0
symbol wcom = b1
symbol ack = b2
symbol coro = b6
symbol LDR1d = b7
symbol LDR2d = b8
symbol Tempd = b9
symbol open1 = "A"
symbol open2 = "L"
symbol open3 = "M"
symbol open4 = "N"
symbol close1 = "B"
symbol status1 ="C"
symbol servo_pin = 3
symbol temp_pin = 1
symbol LDR1 = 0
symbol LDR2 = 4
symbol WindowName = b3
symbol switchpin = pin3
symbol lastposition = b4
symbol servoposition = b5
symbol tossit = b10
'This section defines the window name
WindowName = "A"
'high green_led
'pause 500
'low green_led
read 0,lastposition
if switchpin = 1 then BSWITCH
goto BSTATUS
HOLDINGPATTERN:
high green_led
serin receive,N1200_4,("GG"),tossit,wloc,tossit,wcom,tossit
low green_led
' WindowName is individual window, X is both living room windows, U is all windows
if wloc = WindowName or wloc = "U" or wloc = "X" then MAIN
' if wloc = WindowName then
' goto MAIN
' elseif wloc = "U" then
' goto MAIN
' elseif wloc = "X" then
' goto MAIN
' endif
goto HOLDINGPATTERN
MAIN:
high green_led
pause 500
low green_led
' pause 100
' high green_led
' pause 100
' low green_led
' if wcom = open1 then BOPEN
if wcom = close1 then BCLOSE
if wcom = status1 then BSTATUS
select case wcom
case open1
servoposition = 210
coro = 1
goto BOPEN
case open2
servoposition = 105
coro = 2
goto BOPEN
case open3
servoposition = 95
coro = 3
goto BOPEN
case open4
servoposition = 85
coro = 4
goto BOPEN
endselect
goto MAIN
BOPEN:
' coro = 1
write 0,1
'if wloc = "U" or wloc = "X" then goto HOLDINGPATTERN
gosub SENDIT
servo servo_pin,servoposition
pause 2000
low servo_pin
goto HOLDINGPATTERN
BCLOSE:
coro = 5
write 0,2
'if wloc = "U" or wloc = "X" then goto HOLDINGPATTERN
gosub SENDIT
servo servo_pin,75
pause 2000
low servo_pin
goto HOLDINGPATTERN
BSTATUS:
readadc LDR1,LDR1d
readadc LDR2,LDR2d
readtemp temp_pin, Tempd
gosub SENDIT
goto HOLDINGPATTERN
'BCHECK:
' if coro = 1 then
' goto BOPEN
' elseif coro = 2 then
' goto BCLOSE
' endif
' goto HOLDINGPATTERN
SENDIT:
serout transmit,N1200_4,(0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55) ' preamble to lock link the tx/rx
pause 5 ' lock link and preamble solution by wolfgang
serout transmit,N1200_4,("GG","U",wloc,"U",coro,"U",LDR1d,"U",LDR2d,"U",Tempd,"U")
pause 5
return
BSWITCH:
select case lastposition
case 1
goto BCLOSE
case 2
servoposition = 210
goto BOPEN
endselect
goto BCLOSE
And last, the 08m on the window boards, used to add a local push button for control.
Code:
'p08m button chip for window blinds
'by Brian (kd5crs)
symbol pinfor14 = 0
symbol pin14power = 1
symbol pushbutton = pin4
high pin14power
pause 2000 ' if power outage, 14 will ignore. if button, 14 will execute
high pinfor14
MAIN:
if pushbutton = 1 then PB
goto MAIN
PB:
low pin14power
pause 10
high pin14power
goto MAIN
I hope this helps anyone attempting something similar, or as a reference for getting good results from the Sparkfun 434 mhz pairs.
Now I just need to make one correction on the PCB (notice the white tape covering the ripped up trace?) and then I can buy the boards for my other windows.
Feel free to ask any questions, and I'll do my best to answer.
Brian