Shop OBEX P1 Docs P2 Docs Learn Events
Solenoids and the Debug Menu — Parallax Forums

Solenoids and the Debug Menu

calvin777calvin777 Posts: 2
edited 2008-06-09 14:06 in Learn with BlocklyProp
Hello all. This is my first post here, so bear with me if any of this is incredibly trivial. For a school assignment I have to use the BASIC Stamp with various actuators. As an introduction to all of this, the instructors have us performing basic tasks, like turning on a DC motor for 5 seconds and turning off, then programming it so the motor only turns on when a switch is pressed, etc.

One of these tasks is to activate a solenoid for a set length of time when a switch is pressed, then release it and repeatedly check for the closed switch. I have got this working, but strangely, only when I include the debug line. I can't figure out why this would be necessary, and it's driving me batty. Here is the (short) code from my program.

' {$STAMP BS2p}
' {$PBASIC 2.5}

DO

DEBUG ? IN4
IF IN4=1 THEN       'Check the state of switch in pin 4. If closed, then
HIGH 11               'Activate solenoid on pin 11
PAUSE 2000           'Pause 2 seconds
LOW 11                'deactivate solenoid on pin 11
ENDIF
LOOP                   'repeat loop

END




If I comment out the "DEBUG ? IN4" line, the program ceases to work properly. The solenoid will only activate if the switch is closed at the time I compile the code, and then it doesn't repeatedly check to see if the switch is closed again after 2 seconds.

Any veterans want to help out a rookie here? Thanks.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-08 21:44
    How much current does the solenoid take and how are you powering the Stamp? It may be that the first time the solenoid is activated the battery is drained enough for the Stamp to reset, then the battery recovers enough for the Stamp to start up again.
  • calvin777calvin777 Posts: 2
    edited 2008-06-09 00:31
    I am not sure how much power the solenoid draws, but I am powering it with a DC converter. I played around with the code a little and it seems to get slightly stranger (to my untrained eye, that is).

    With the serial cable plugged in, the DEBUG line is required to get the code to run as desired. However, if the serial cable is removed, then the DEBUG line must also be removed, or else the solenoid will only activate once, no matter how many times the switch is closed.

    Your thoughts?
  • FranklinFranklin Posts: 4,747
    edited 2008-06-09 01:12
    Could you include a schematic in your next post?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-09 14:06
    Often when a DEBUG line is required it indicates that the PC being used is one of the rare units that toggle the DTR line when the COM Port is not in use. This essentially keeps the BASIC Stamp in a state of reset. Adding the DEBUG line forces the BASIC Stamp DEBUG Window to open the port, therefore asserting the DTR line into a known state. I would guess if you remove the DEBUG line you could still get it to work by unplugging your programming able as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.