November 23, 2024, 02:03:43 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Noob error or something else? Works while connected to PC but not otherwise

Started by BigRez, October 28, 2008, 09:32:24 PM

Previous topic - Next topic

BigRez

Hi all -

Complete noob here - at least with this stuff.

Got all the goodies yesterday (prop-1 kit, RC4, PIR, solenoid.) Got 'em all hooked up (PIR to p6 and setup DN and low on the PIR, valve to V+ and OUT0, RC4 to PIN7 setup off, replaced UNL2803 with UNL2003.) picked parts of different programs and put together the following program.

When I run it in debug (prop-1 switch set to 1) things appear to work just fine.  When I disconnect the BS1 serial connection, turn it off and then flip the switch to position 2, the PIR doesn't seem to activate.  I commented out some of the delays to make sure it's just not me being impatient, also added the light flash part to see the RC4 led flash while testing.

Anyone got a clue as to what's going on?


' =========================================================================
'   File......  Monster1.bs1
'   Purpose...  Used to control coffin monster
'   Author....  Pieces obtained from EFX-TEK web site.
'   {$STAMP BS1}
'   {$PBASIC 1.0}
' =========================================================================
' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Monster         = PIN0                  ' use OUT0

' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0
SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0
SYMBOL  Baud            = OT2400

' -----[ Variables ]-------------------------------------------------------
SYMBOL  delay           = W1
SYMBOL  pirTimer        = W2
SYMBOL  lottery         = W3

SYMBOL  relays          = B0
SYMBOL   Light          =  BIT0
SYMBOL   K2             =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  id1             = B1                    ' version string

' -----[ Initialization ]--------------------------------------------------
Init:
  SEROUT Sio, Baud, ("!!!RC4", %00, "V")        ' Go get the RC-4 version
  SERIN Sio, Baud, id1
  DEBUG "RC-4 Version ", #@id1, CR
  DEBUG "Sleeping 20 seconds for PIR warmup...", CR
  PAUSE 20000                                   'allow for PIR warm-up

Reset:
  DEBUG "Resetting Monster...", CR
  PINS = %00000000                               ' clear all
  DIRS = %00000011                               ' set outputs
  relays = IsOff
  SEROUT Sio, Baud, ("!!!RC4", %00, "X")         ' clear RC-4 outputs

' -----[ Program Code ]----------------------------------------------------
Main:
  DEBUG "Random pause... 60 - 183 seconds...", CR
  'PAUSE 60000                                    ' minimum sleep = 60 seconds
  'GOSUB Do_Delay                                 ' Create an dditional delay of
  'GOSUB Do_Delay                                 '   3 to 180 seconds
  'GOSUB Do_Delay

  DEBUG "Flashing light", CR
  Light = IsOn                                   'Flash the light (temporary)
  GOSUB Set_RC4
  PAUSE 500
  Light = IsOff
  GOSUB Set_RC4

  pirTimer = 0                                   ' reset timer
  DEBUG "Waiting for PIR Trigger...",CR

Check_Trigger:
  RANDOM lottery                                'Start Random function
  pirTimer = pirTimer + PIR * PIR                ' update timer
  PAUSE 10
  IF pirTimer < 25 THEN Check_Trigger
  DEBUG "PIR detected.",CR
  PAUSE 1000                                     'Pause for 1 second

  DEBUG "Monster going up and turning light on...", CR
  Monster = IsUp                                 'Bring monster up
  Light = IsOn                                   'Turn Light On
  GOSUB Set_RC4

  PAUSE 7000                                     ' wait 7 seconds for sound to complete
  GOTO Reset                                     ' do it all again...


' -----[ Subroutines ]-----------------------------------------------------
' Updates RC-4  -- takes about 29.4 milliseconds
Set_RC4:
  SEROUT Sio, Baud, ("!!!RC4", %00, "S", relays)
  RETURN

Do_Delay:
  delay = lottery // 60 + 1                     'Create Delay up to 60 seconds
  DEBUG "Sleeping for ", #delay," seconds", CR
  delay = delay * 1000                          'Convert to Milliseconds, min 30 secs
  PAUSE delay
  RETURN

' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

JonnyMac

Your program seems to work stand-alone on my desk -- that said, it's a bit over-done; you can simplify.  Let me suggest something like this as simpler is always better.

' =========================================================================
'
'   File...... Monster.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 29 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Monster         = PIN0

' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  IsUp            = 1
SYMBOL  IsDown          = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


' -----[ Variables ]-------------------------------------------------------

SYMBOL  relays          = B0
SYMBOL   Light          =  BIT0
SYMBOL   K2             =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  timer           = B2

SYMBOL  lottery         = W5                    ' random #


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000001                              ' set outputs

  SEROUT Sio, Baud, ("!!!!!RC4", %00, "X")      ' clear RC-4
  relays = %0000

  PAUSE 20000                                   ' warm-up


' -----[ Program Code ]----------------------------------------------------

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' stir random #
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  PAUSE 1000

  Monster = IsUp
  Light = IsOn
  GOSUB Set_RC4
  PAUSE 7000

  Monster = IsDown
  Light = IsOff
  GOSUB Set_RC4

  RANDOM lottery
  timer = lottery // 121 + 60                   ' 60 to 180 (seconds)

Monster_Sleep:
  PAUSE 1000
  timer = timer - 1
  IF timer > 0 THEN Monster_Sleep
    GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

BigRez

Ah yes, looks much better.  Thank you.

By stand-alone, do you mean not connected to the computer and running through the debug window in the stamp editor?  The version you included above does work perfectly when in stand-alone, but mine didn't.  OK - I gotta go figure out why!

Thanks again,

mike

p.s. Two days into using the prop-1/RC-4 and I'm already looking at getting a couple prop-2 or SX controllers and other goodies for next year.  I'll give myself more than a few days to work things out though. :)