Shop OBEX P1 Docs P2 Docs Learn Events
basic stamp thermostat project — Parallax Forums

basic stamp thermostat project

thikyelathikyela Posts: 8
edited 2009-06-23 21:38 in BASIC Stamp
Hello,

I seem to be having some difficulty writing code for my thermostat project. What i am trying to do is, when one of the momentary contact switches (pushbuttons) gets closed, it will send the user to the proper sub program. The stamp does not like the line directly beneath the 'do'. I have a switch (and resistor) wired up from Vdd to pin 4 (Coolpin). I'm not sure what syntax rule i'm breaking. Am i not allowed to use 'high' in this fashion? If not, what would be a better way of going about it?


DO
IF CoolPin = high THEN <
PAUSE 500
GOSUB cool:
ELSEIF HeatPin = high THEN
PAUSE 500
GOSUB heat:
ELSEIF ReturnLCD = high THEN
SEROUT lcdpin, baudlcd, [noparse][[/noparse]"Invalid"]
PAUSE 500
GOSUB main_menu:
ENDIF
LOOP


Thank you,
Scott

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-26 18:50
    HIGH is a statement, not a value. An I/O pin has the value 1 if it's a logic high or 0 if it's a logic low. You can also assign the value 1 or 0 to something declared as an I/O pin. It's not exactly the same as using a HIGH or LOW statement since that sets the I/O pin to output mode in addition to setting its value. Read the chapter in the Stamp Basic Syntax and Reference Manual on all this (pages 81-85 and 99-102) and the chapters on the HIGH, LOW, INPUT, OUTPUT statements.
  • thikyelathikyela Posts: 8
    edited 2009-05-26 20:19
    Thanks. Had a look through the manual and I changed the code to this...


    DO
    IF CoolPin = 1 THEN
    PAUSE 500
    GOSUB cool:
    ELSEIF HeatPin = 1 THEN
    PAUSE 500
    GOSUB heat:
    ELSEIF ReturnLCD = 1 THEN
    SEROUT lcdpin, baudlcd, [noparse][[/noparse]"Invalid"]
    PAUSE 500
    GOSUB main_menu:
    ENDIF
    LOOP

    I wired from Vdd to a pushbutton, and from that side of the button i ran a 220 ohm resistor to p4(coolpin) and 10k resistor to ground. It still does not seem to recognize that the button was pressed. Any ideas?

    Thanks again
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-26 22:14
    thikyela

    Welcome to the Forum


    Let get your menu to work first before we do any thing else



    Look_Here··at page 90 it show how to wire up a switch to a Basic Stamp Pin

    If you have· wired it right you should see which ever button that is pushed with that routine in the DEBUG screen

    Once you get this to work then move on to the next thing would be to write you heat and cool routine

    Try this routine and see what you have

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    coolin·· ·PIN··· 1········ ' Use·the pin # that you have the switch wired to
    heatin·· PIN··· 0········· ' Use·the pin # that you have the switch wired to

    '·You could just use one switch to switch between routine but if you· did that then your IF THEN·ELSE THEN statements would be just a little different


    ·DO
    PAUSE 500
    DEBUG CLS
    DEBUG HOME, ? coolin, ? heatin
    IF Coolin = 0 THEN················· ' You may need to·change this to "0" instead of "1"
    GOSUB cool:
    ELSEIF Heatin = 0 THEN
    GOSUB heat:
    ENDIF
    LOOP

    ·
    Cool:
    DEBUG CLS
    PAUSE 500
    DEBUG HOME, ? coolin
    PAUSE 500
    RETURN

    heat:
    DEBUG CLS
    PAUSE 500
    DEBUG HOME, ? heatin
    PAUSE 500
    RETURN


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/26/2009 10:59:41 PM GMT
  • thikyelathikyela Posts: 8
    edited 2009-05-26 23:40
    Ok, thanks for the suggestions. I started by changing the pins to PIN format vs. CON. Not sure if that affected the outcome, though. Then I realized that when i pushed the button I had wired, in the 'Cool' subroutine there was an exit pin that I had not wired yet, and was getting pulled high automatically (I think..?), immediately returning me to where I began. So for now, that's fixed.

    Thanks again, folks

    Scott
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-27 00:41
    Scott
    ·
    I started by changing the pins to PIN format vs. CON. Not sure if that affected the outcome, though

    You can use·coolin· PIN·· 0·· OR···· coolin··· ·CON··· 0········ ·ether one will work

    If you leave a pin FLOATING·that you are going to use as an INPUT it will stay at a "1" or change back and forth " 0 " to a " 1 "


    I have one suggestion for you is when you use a switch or switches to change routines

    You need to test the routine with the switch or switches with ·something·like·what I have in the example that I gave you

    so you can see if

    One .....>>>> You have your switch or switches working or not
    Two .....>>>> You should use the DEBUG command to debug your code Routines to see if they are working right or not
    Three .....>>> Once you have your Menu working set it a side and just work on the Cool Routine get it working right
    ···················· Then work on the Heat Routine and get that work right
    ····················· Then work on the rest of the routines then put it all together
    Four .........>>>·When you have let say the cool routine·and the heat routine working and all other that you are going to use·make
    ······················them·a·SUB··ROUTINES and call them up when you need them
    ····················· It take less memory space doing·it that way·and easyer to follow your own ·code


    These are only suggestions and what·I have here is how·I write my·the code routines

    In the Attachment bellow·is a project that I had a lot of trouble getting some routine to work right
    I had to·trouble shoot why it was not working· right with DEBUG Statements

    I hope this helps

    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/27/2009 12:59:56 AM GMT
  • thikyelathikyela Posts: 8
    edited 2009-05-29 15:11
    Looks like a headache...
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-29 20:27
    It was a headache... but if you take one routine at a time and get it to work then work on the next routine and so on

    Yes it take time this project took·about three week working on it 4 to 6 hour a week

    What i do also is save your routine that you make and keep them they come in handy latter in other projects

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • thikyelathikyela Posts: 8
    edited 2009-06-11 14:34
    Hello again,

    I've got most of the code written for the heat / cool functions. They work well enough. I do however want to add the ability to turn the backlight of the LCD screen off after a certain period of time (3-4 seconds).

    I used a FOR...NEXT loop in some areas, like the main menu, since it simply loops through over and over, and nothing changes. But I realize that I won't be able to do this easily in the change temperature subroutines, since the program doesn't follow a straight path through the code.

    I then considered using a makeshift timer outside of the program, like an RC circuit, coupled with a diac and SCR. Problem is, I don't think they make diacs with breakover voltage less than ~20V. If I could find one @4V or so, compatible with the stamp's 5V HIGH state, I think it would work.

    My question is, does anybody have any other strategies for starting and stopping a timer sequence, within or outside of the Pbasic program?

    I have a sample of my cool routine below, thanks guys!
    Scott

    Cool:

    GOSUB BLon 'turns backlight on
    PAUSE 250
    DO
    ' HIGH timerstart
    ' HIGH timertrig
    ' LOW timerdone
    'Considering an RC time ckt here, hopefully turn the timer on and off at will, regardless
    ' IF timerdone = 1 then
    'of where the program is currently looping
    ' GOSUB BLOff
    ' LOW timertrig
    ' low timerstart
    ' endif

    GOSUB read_ds1620: 'takes temp
    GOSUB ClearLCD
    GOSUB ChangeSetPt
    SEROUT lcdpin, baudlcd, [noparse][[/noparse]"SetPt=",DEC setpoint,2,"F-", "Cool",149,
    "Temp is ",DEC temperature,2,"F" ]



    IF temperature > setpoint THEN
    DO WHILE temperature > (setpoint-5)


    HIGH 15 'turns on fan
    GOSUB READ_ds1620: 'reads / converts temp
    GOSUB clearLCD


    GOSUB ChangeSetPt 'allows to change setpoint on the fly
    SEROUT lcdpin, baudlcd, [noparse][[/noparse]"SetPt=",DEC setpoint,2,"F-", "Cool",149, 'shows stats on lcd
    "Temp is ",DEC temperature,2,"F" ]

    PAUSE 150
    IF Auto = 1 THEN 'exit button
    LOW 15 'shuts down fan
    PAUSE 200 'waits 1/4 sec
    GOSUB main_menu: 'returns to main
    ENDIF

    LOOP
    ELSE
    LOW 15 'turns fan off
    ENDIF

    LOOP UNTIL Auto = 1
    GOSUB main_menu

    Post Edited (thikyela) : 6/12/2009 1:31:37 AM GMT
  • thikyelathikyela Posts: 8
    edited 2009-06-23 21:38
    Update, I got a fix for the timing problem, using a simple CMOS 555. Instead of trying to write in complicated code for the timer, I just triggered it when I needed to, and shut off the backlight when it expired.

    So now I'm off to try and find a way to lock down the thermostat, using a keypad maybe? Or a biometric security device, maybe a fingerprint reader, or voice recognition? I know that might be overkill, but I'm just having fun with it. I know when i was young I'd crank that heater up to 82, then go shirtless. Not gonna let that happen....
Sign In or Register to comment.