November 23, 2024, 07:25:29 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Prop1 Groundbreaker prop

Started by youngti, May 19, 2009, 03:25:02 PM

Previous topic - Next topic

youngti

Okay, so I'm trying to understand the programing and I have gathered bits of code from this site and put it together into code for a groudbreaker prop.  The prop has two solenoids that are attached to two cylinders, a vmusic player, RC-4 for light control and a PIR trigger.  What I want to happen is when the PIR is triggered, the light comes one, sounds from the vmusic plays and the 2 solenoids fire randomly.  Can you take a look at the code below and tell me if I am close?  Thank you for your help.

       ' =========================================================================
'
'   File...... GroundBreaker_V1.BS1
'   Purpose...
'   Author.... Tim Young
'   E-mail....
'   Started...05-19-09
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'This program will take activation from a PIR AND THEN randomly activate two solenoids

'Non RANDOM activation of Vmusic2, AND light.

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


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

SYMBOL  Trigger         = PIN7                           ' SETUP = Active High
SYMBOL  vMusic2RX       = PIN6                           ' SETUP = Up, No ULN
SYMBOL  vMusic2TX       = PIN5                           ' SETUP = Up, No ULN
SYMBOL  LightRC4        = PIN4                           ' SETUP = Up, No ULN
SYMBOL  Solenoid2       = PIN1
SYMBOL  Solenoid1       = PIN0

SYMBOL Sio              =4

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

SYMBOL  Baud            = OT2400

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

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

SYMBOL  delay           = B2
SYMBOL  timer           = W4
SYMBOL  lottery         = W5
SYMBOL  volume          = B5


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

Reset:
  PINS = %00000000                                      ' start with all off
  DIRS = %01111111                                      ' set output pins

  LightRC4 = IsOff
  SEROUT Sio, Baud, ("!RC4", %00, "X")                  ' clear RC-4 outputs

  PAUSE 2250                                            ' let VMUSIC power up
  GOSUB VM_Stop                                         ' stop if playing
  GOSUB VM_Wait_Prompt

  LOW Solenoid1                                         ' initialize Solenoid
  LOW Solenoid2                                         ' initialize Solenoid

  PAUSE 30000                                           ' PIR warm-up, reset delay


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

Main:
  timer = 0                                             ' reset timer

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

Start_Audio:
  SEROUT vMusic2RX, Baud, ("GroundBreak.mp3", 13)
  GOSUB VM_Wait_Start

LightRC4 = IsOn                                         ' light on
  GOSUB Update_RC4
  Ground_Break:

IF timer > Breaktime THEN Quit                          ' quit if timer expired
    RANDOM lottery                                      ' create new timing
    delay = lottery // 201 + 50                         ' between 50 and 250 ms
    TOGGLE Solenoid1                                    ' Random Solenoid1
    TOGGLE Solenoid2                                    ' Random Solenoid2
    PAUSE delay                                         ' hold
    timer = timer + delay                               ' update timer
    GOTO Ground_Break

Quit:
  LOW Solenoid1                                         ' stop it
  LOW Solenoid2
  PAUSE 15000                                           ' hold 15 secs
  GOTO Main                                             ' start over




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

Update_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", %0001)
  RETURN

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

VM_Wait_Start :
  SERIN vMusic2RX, Baud, ("T $0")
  RETURN

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

VM_Stop:
  SEROUT vMusic2TX, Baud, ("VST", 13)
  RETURN

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

' Pass volume (0 = loudest, 254 = muted) in "volume"

VM_Volume:
  SEROUT vMusic2TX, Baud, ("VSV ", #volume, 13)
  RETURN

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

VM_Wait_Prompt:
  SERIN vMusic2RX, Baud, (">")
  RETURN

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

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


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

livinlowe

Jon taught me a valuable lesson one time: have you tried to compile your program in the Stamp IDE?
Shawn
Scaring someone with a prop you built -- priceless!

youngti

not complie, I did run the syntax check and it came throught fine.

youngti

I'm going to try it tonight with the trainer.

livinlowe

Yeah, Geez!  :o I meant Syntax check!
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

I did a bit of a clean-up.  You can't run this program on the trainer because it uses P6 as the trigger input and the nature of using the VMUSIC (which I'm beginning to loathe) means that you can't use P6 for the trigger -- the VMUSIC pins MUST be pulled up (please trust me on this).

Compare my version to yours -- it will be a good way to learn.

' =========================================================================
'
'   File...... GroundBreaker_V1.BS1
'   Purpose...
'   Author.... Tim Young (clean-up by Jon Williams)
'   E-mail....
'   Started... 05-19-09
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  RX              = 7                     ' SETUP = UP, no ULN
SYMBOL  TX              = 6                     ' SETUP = UP, no ULN
SYMBOL  Sio             = 5                     ' no ULN
SYMBOL  Trigger         = PIN4
SYMBOL  LightRC4        = PIN3
SYMBOL  Solenoid2       = PIN1
SYMBOL  Solenoid1       = PIN0

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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  BreakTime       = 15000

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

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

SYMBOL  delay           = B2
SYMBOL  volume          = B3

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' start with all off
  DIRS = %00001011                              ' set output pins

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

  PAUSE 2250                                    ' let VMUSIC power up
  GOSUB VM_Stop                                 ' stop if playing
  GOSUB VM_Wait_Prompt

  PAUSE 30000                                   ' PIR warm-up, reset delay


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

Main:
  timer = 0                                     ' reset timer

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

Start_Audio:
  SEROUT TX, Baud, ("VPF ground.mp3", 13)
  GOSUB VM_Wait_Start

  LightRC4 = IsOn                               ' light on
  relays = %0001
  GOSUB Update_RC4

  timer = 0

Ground_Break:
  RANDOM lottery                                ' create new timing
  delay = lottery // 201 + 50                   ' between 50 and 250 ms
  TOGGLE Solenoid1                              ' Random Solenoid1
  TOGGLE Solenoid2                              ' Random Solenoid2
  PAUSE delay                                   ' hold
  timer = timer + delay                         ' update timer
  IF timer < BreakTime THEN Ground_Break

Quit:
  LOW Solenoid1                                 ' stop it
  LOW Solenoid2
  LightRC4 = IsOff
  relays = %0000
  GOSUB Update_RC4
  PAUSE 15000                                   ' hold 15 secs
  GOTO Main                                     ' start over

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

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

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

VM_Wait_Start :
  SERIN RX, Baud, ("T $0")
  RETURN

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

VM_Stop:
  SEROUT TX, Baud, ("VST", 13)
  RETURN

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

' Pass volume (0 = loudest, 254 = muted) in "volume"

VM_Volume:
  SEROUT TX, Baud, ("VSV ", #volume, 13)
  RETURN

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

VM_Wait_Prompt:
  SERIN RX, Baud, (">")
  RETURN


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

youngti

Okay, so I'm going to comment on what I think this all means.  Please let me know if I am worng or right on this.

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

SYMBOL  RX              = 7                     ' SETUP = UP, no ULNvMusic recieve-Bent ULN pin up out of the way
SYMBOL  TX              = 6                     ' SETUP = UP, no ULNVmusic transmit-Bent ULN pin up out of the way
SYMBOL  Sio             = 5                     ' no ULNNot sure on this one
SYMBOL  Trigger         = PIN4               This is where the PIR gets attached, should the pin on the ULN be bent up?
SYMBOL  LightRC4        = PIN3             RC-4 connection, okay got it.
SYMBOL  Solenoid2       = PIN1
SYMBOL  Solenoid1       = PIN0

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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  BreakTime       = 15000

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

SYMBOL  relays          = B0     
SYMBOL   K1             =  BIT0     Not sure I understand these next lines.
SYMBOL   K2             =  BIT1
SYMBOL   K3             =  BIT2
SYMBOL   K4             =  BIT3

SYMBOL  delay           = B2
SYMBOL  volume          = B3

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' start with all off
  DIRS = %00001011                              ' set output pins

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

  PAUSE 2250                                    ' let VMUSIC power up
  GOSUB VM_Stop                                 ' stop if playing
  GOSUB VM_Wait_Prompt

  PAUSE 30000                                   ' PIR warm-up, reset delay  This should be 30 seconds, right?


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

Main:
  timer = 0                                     ' reset timer

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

Start_Audio:
  SEROUT TX, Baud, ("VPF ground.mp3", 13)  Yeah, I kinda thought the MP3 name was a little long.
  GOSUB VM_Wait_Start

  LightRC4 = IsOn                               ' light on
  relays = %0001
  GOSUB Update_RC4

  timer = 0

Ground_Break:
  RANDOM lottery                                ' create new timing
  delay = lottery // 201 + 50                   ' between 50 and 250 ms
  TOGGLE Solenoid1                              ' Random Solenoid1
  TOGGLE Solenoid2                              ' Random Solenoid2
  PAUSE delay                                   ' hold
  timer = timer + delay                         ' update timer
  IF timer < BreakTime THEN Ground_Break

Quit:
  LOW Solenoid1                                 ' stop it
  LOW Solenoid2
  LightRC4 = IsOff
  relays = %0000
  GOSUB Update_RC4
  PAUSE 15000                                   ' hold 15 secs
  GOTO Main                                     ' start over

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

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

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

VM_Wait_Start :
  SERIN RX, Baud, ("T $0")
  RETURN

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

VM_Stop:
  SEROUT TX, Baud, ("VST", 13)
  RETURN

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

' Pass volume (0 = loudest, 254 = muted) in "volume"

VM_Volume:
  SEROUT TX, Baud, ("VSV ", #volume, 13)
  RETURN

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

VM_Wait_Prompt:
  SERIN RX, Baud, (">")
  RETURN


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

youngti

Well, I'm not getting it to work.  This is how I have the set-up.

Pin7=vMusic RX ULN pin bent up, Jumper on Prop1 set to UP
Pin6=vMusic TX ULN pin bent up, Jumper on Prop1 set to UP
Pin5 =Empty (not sure what should go here) ULN pin bent up
Pin4=PIR
Pin3=RC-4 with the serial cable connected to the first serial connection on the RC-4, Baud jumper off, A1 jumper off and A0 jumber off
I have the Solenoids connected Red wires to the V+ and one black wire connected to Out0 the other connected to OUT1

I have a mp3 named ground in the vmusic player and I have verified hat this vmusic works on a test prop1

I have all four relays on the RC-4, but I don't have the light connected yet.  But I should still see the LED light on the K1 position.

So no action o the RC-4, no clicking on the solenoids and no sound.

I knew that i may have bitten off a bit much and I hoping you guys can help me

BigRez

Seems to me that the RC4 should be connected to PIN5 (Sio = Serial I/O).  Thus, you wouldn't need LightRC4 throughout the program because the RC4 items are handled by the setting of the "relays" variable.   (Symbols K1 - K4 are four bits belonging to relays (B0) and each represents one of the four relays on the RC4.)

You have a 32.35 second pause prior to getting into main: - seems like you're aware of that.

I wonder if you're getting past the GOSUB VM_Wait_Start command.  Perhaps add a debug line before and after it to be able to "see" what the program is doing. If the play command is making it to the VM2, maybe the SERIN isn't seeing the T status coming back.  The debug before and after will tell you if you're getting past that.

JonnyMac

Focus on one thing at a time, Tim -- start with the VMUSIC player because it's the biggest nightmare.  Keep in mind that the TX (P6) pin on the Prop-1 connects to RX (orange) on the VMUSIC player, and the RX (P7) pin of the Prop-1 connects to TX (yellow) of the VMUSIC. 

Here's how I cable it:



After you get the VMUSIC then you can connect the RC-4 and run the RC-4 demo code with the appropriate Sio pin # change.  Once those items are working you can build your working code.
Jon McPhalen
EFX-TEK Hollywood Office

youngti

Thank you Jonny.  I will check that out tonight and make sure.  So it sound like the RC-4 needs to be on pin 5 and I can do away with the pin3 connection.

JonnyMac

I don't know what you're trying to do with the RC-4.  If you just want to turn on on lamp using an SSR you don't need serial code to the RC-4; just connect the output pin (use 5) to X1 on the RC-4 and plug your Crydom SSR into the K1 slot.  Presto-bingo, done!   Now, if you want to control more than one relay then go serial so that you can still use just one IO pin.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

It looks like your trying to control lights on your RC-4 two different ways. In Jon's program:


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

and

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

control the RC-4 with a Serial data connection. To make a relay turn on you would just say

K1= IsOn
Update_RC4

But in your code

SYMBOL  LightRC4        = PIN3

LightRC4 = IsOn                               ' light on
       


would be used like Jon just said, you would have a wire from Pin 3 to X1 on the RC-4 and that would turn on K1. Did you want to control Serially or Individually?
Shawn
Scaring someone with a prop you built -- priceless!

youngti

That is correct, I just wanted to turn the light on while the prop is activated, then turn it off.

livinlowe

So you can remove Jon's serial code from your program like this:



'   {$STAMP BS1}
'   {$PBASIC 1.0}
' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  RX              = 7                     ' SETUP = UP, no ULNvMusic recieve-Bent ULN pin up out of the way
SYMBOL  TX              = 6                     ' SETUP = UP, no ULNVmusic transmit-Bent ULN pin up out of the way

SYMBOL  Trigger         = PIN4               
SYMBOL  LightRC4        = PIN3              ' RC-4 connection wire from Pin 3 TTL to X1 TTL
SYMBOL  Solenoid2       = PIN1
SYMBOL  Solenoid1       = PIN0

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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  BreakTime       = 15000

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



SYMBOL  delay           = B2
SYMBOL  volume          = B3

SYMBOL  timer           = W4
SYMBOL  lottery         = W5




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

Reset:
  PINS = %00000000                              ' start with all off
  DIRS = %00001011                              ' set output pins



  PAUSE 2250                                    ' let VMUSIC power up
  GOSUB VM_Stop                                 ' stop if playing
  GOSUB VM_Wait_Prompt

  PAUSE 30000                                   ' PIR warm-up, reset delay 30 seconds

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

Main:
  timer = 0                                     ' reset timer

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

Start_Audio:
  SEROUT TX, Baud, ("VPF ground.mp3", 13) 
  GOSUB VM_Wait_Start

  LightRC4 = IsOn                               ' light on
 
  timer = 0

Ground_Break:
  RANDOM lottery                                ' create new timing
  delay = lottery // 201 + 50                   ' between 50 and 250 ms
  TOGGLE Solenoid1                              ' Random Solenoid1
  TOGGLE Solenoid2                              ' Random Solenoid2
  PAUSE delay                                   ' hold
  timer = timer + delay                         ' update timer
  IF timer < BreakTime THEN Ground_Break

Quit:
  LOW Solenoid1                                 ' stop it
  LOW Solenoid2
  LightRC4 = IsOff
 
  PAUSE 15000                                   ' hold 15 secs
  GOTO Main                                     ' start over

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

VM_Wait_Start :
  SERIN RX, Baud, ("T $0")
  RETURN

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

VM_Stop:
  SEROUT TX, Baud, ("VST", 13)
  RETURN

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

' Pass volume (0 = loudest, 254 = muted) in "volume"

VM_Volume:
  SEROUT TX, Baud, ("VSV ", #volume, 13)
  RETURN

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

VM_Wait_Prompt:
  SERIN RX, Baud, (">")
  RETURN


' -----[ User Data ]-------------------------------------------------------
Shawn
Scaring someone with a prop you built -- priceless!