November 21, 2024, 06:00:40 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Lair of the Spider - Code Assistance

Started by Pantseatflyer, October 27, 2008, 08:01:51 AM

Previous topic - Next topic

Pantseatflyer

Hi Jon,

I would really like some assistance with the following.

Scenario:  TOT'er walks to front door.  He hears a sound from 4 feet above and to his left, he looks to see a giant spider and struggling cocoon and hears the scream of "HELP ME" (ala "The Fly")......

Here are the specs:
Prop 2, PIR Sensor, AP-8 and RC-4 with 4 Cyrdom SSR's

Spider's Lair:

Trigger PIR
Wait 5 sec.
Play Sound 1 - (Hissing) (3 seconds) AP8
Trigger 3 sec burst of fog (hacked trigger of fog machine for burst)
Spotlight On (5 LED Spot powered by 9 volt battery)
Play Sound 2 - (10 seconds) AP8
Trigger Cocoon (6 volt - skinned dancing kids toy with sound disabled, looks good as struggling 'cocoon victim')
Play Sound 3 - (3 seconds) AP8
Spotlight Off
Cocoon Off
Wait 30 seconds reset PIR

Thanks for your assistance!

gb

JonnyMac

October 27, 2008, 09:28:12 AM #1 Last Edit: October 27, 2008, 09:29:57 AM by JonnyMac
I think this matches your description.

' =========================================================================
'
'   File...... Spider_Lair.BS2
'   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... 27 OCT 2008
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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

' Prop-2 --> RC-4 (%00) --> AP-8 (%00)
'
' On RC-4 and AP-8 the A0 and A1 jumpers are out, the B/R (baud) jumper in.


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


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

Sio             PIN     15                      ' SETUP = out; no ULN
Trigger         PIN     14                      ' SETUP = DN

Cocoon          PIN     1
SpotLight       PIN     0


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

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

Yes             CON     1
No              CON     0

T2400           CON     396
T9600           CON     84
T19K2           CON     32
T38K4           CON     6

Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T38K4            ' B/R jumper installed


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

timer           VAR     Byte                    ' debounce/timer

relays          VAR     Byte                    ' RC-4 relay control
Fogger         VAR     relays.Bit0
K2             VAR     relays.bit1
K3             VAR     relays.BIT2
K4             VAR     relays.bit3

sfx             VAR     Byte                    ' sound segment
status          VAR     Byte                    ' AP-8 status
playing        VAR     status.bit7


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000011           ' set outputs

  SEROUT Sio, Baud, ["!!!!!RC4", %00, "X", "!AP8", %00, "X"]
  relays = %0000

  PAUSE 30000                                   ' warm-up/delay


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

Main:
  timer = 0                                     ' reset timer
  DO WHILE (timer < 100)                        ' wait for 0.10 sec input
    PAUSE 5                                     ' loop pad
    timer = (timer + 5) * Trigger               ' update timer
  LOOP

  PAUSE 5000

  Fogger = IsOn
  GOSUB Set_RC4
  sfx = 0
  GOSUB Play_AP8
  GOSUB Hold_AP8                                ' let sound finish
  Fogger = IsOff
  GOSUB Set_RC4

  SpotLight = IsOn
  sfx = 1
  GOSUB Play_AP8
  Cocoon = IsOn
  GOSUB Hold_AP8

  sfx = 3
  GOSUB Play_AP8
  GOSUB Hold_AP8

  GOTO Reset                                    ' everything off


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

Set_RC4:
  SEROUT Sio, Baud, ["!RC4", %00, "S", relays]
  RETURN

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

Play_AP8:
  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]
  RETURN

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

Hold_AP8:
  PAUSE 50
  SEROUT Sio, Baud, ["!AP8", %00, "G"]
  SERIN  Sio, Baud, [status]
  IF (playing = Yes) THEN Hold_AP8
    RETURN

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


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

JonnyMac

Just a note: Your second sound is 10 seconds long which means it will occupy two AP-8 slots (1 and 2); make sure you put your third sound into slot 3.
Jon McPhalen
EFX-TEK Hollywood Office

Pantseatflyer

Thanks Jon!

Is it my understanding that the Spot and Cocoon are triggered by the Prop-2 and the Fogger is powered by a relay on the RC-4?

What is the voltage limitation on the Prop-2?  I realize that relays should be used for AC (110-120v) applications, but was curious on the Prop-2.


JonnyMac

If you use a 12-volt supply you'll get 12 volts form the V+/OUTx terminals -- this means you may need to use relays to interface to your low-voltage devices. 

Fogger remotes simply switch 120 VAC which is what the RC-4 is designed to do, hence the connection.  If you've never hacked a fogger remote you should get help -- 120 VAC can bite you very hard.
Jon McPhalen
EFX-TEK Hollywood Office

Pantseatflyer

The spot light will be powered by a 9 volt battery and the Cocoon will be powered by (3) 1.5 volt AAA.

I'm respectful of electricity.  10 years of restoring pinball machines has taught me quite a bit.  :o

I will opt for the relays to play it safe. 

Thanks Jon!

Pantseatflyer

Jon,

Can you add to my code to include my low voltage devices utilizing the RC-4?

The Fogger currently is on K1.  The spotlight can be on K2 and the Cocoon motor on K3.

Thank you sir!

JonnyMac

Okay, you should have been able to make these updates...  ;)

' =========================================================================
'
'   File...... Spider_Lair.BS2
'   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 BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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

' Prop-2 --> RC-4 (%00) --> AP-8 (%00)
'
' On RC-4 and AP-8 the A0 and A1 jumpers are out, the B/R (baud) jumper in.


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


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

Sio             PIN     15                      ' SETUP = out; no ULN
Trigger         PIN     14                      ' SETUP = DN


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

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

Yes             CON     1
No              CON     0

T2400           CON     396
T9600           CON     84
T19K2           CON     32
T38K4           CON     6

Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T38K4            ' B/R jumper installed


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

timer           VAR     Byte                    ' debounce/timer

relays          VAR     Byte                    ' RC-4 relay control
Fogger         VAR     relays.BIT0
Spotlight      VAR     relays.BIT1
Cocoon         VAR     relays.BIT2
K4             VAR     relays.BIT3

sfx             VAR     Byte                    ' sound segment
status          VAR     Byte                    ' AP-8 status
playing        VAR     status.BIT7


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs

  SEROUT Sio, Baud, ["!!!!!RC4", %00, "X", "!AP8", %00, "X"]
  relays = %0000

  PAUSE 30000                                   ' warm-up/delay


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

Main:
  timer = 0                                     ' reset timer
  DO WHILE (timer < 100)                        ' wait for 0.10 sec input
    PAUSE 5                                     ' loop pad
    timer = (timer + 5) * Trigger               ' update timer
  LOOP

  PAUSE 5000

  Fogger = IsOn
  GOSUB Set_RC4
  sfx = 0
  GOSUB Play_AP8
  GOSUB Hold_AP8                                ' let sound finish

  SpotLight = IsOn
  Cocoon = IsOn
  GOSUB Set_RC4
  sfx = 1
  GOSUB Play_AP8
  GOSUB Hold_AP8

  sfx = 2
  GOSUB Play_AP8
  GOSUB Hold_AP8

  GOTO Reset                                    ' everything off


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

Set_RC4:
  SEROUT Sio, Baud, ["!RC4", %00, "S", relays]
  RETURN

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

Play_AP8:
  SEROUT Sio, Baud, ["!AP8", %00, "P", sfx]
  RETURN

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

Hold_AP8:
  PAUSE 50
  SEROUT Sio, Baud, ["!AP8", %00, "G"]
  SERIN  Sio, Baud, [status]
  IF (playing = Yes) THEN Hold_AP8
    RETURN

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


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

Pantseatflyer

Hey Jon,

I hooked up the works today to test the code.  I get SQUAT! Where am I going wrong??

Code downloaded to Prop-2

P14 is DN.  P14 connected to PIR

P15 is OUT.  P15 connected to RC-4 SER connector.

RC-4 Baud is ON, A1 and A0 are OUT

SER Connector attached to AP-8 to Serial

AP-8 Baud is ON, A1 and A0 are OUT.

Prop-2 is set to 1 to turn on.  AP-8 is on set at 1

I am getting no sound and the RC-4 will periodically flash K1-K3 briefly and then go off.

AP-8 is programmed with sound and double checked and will play through speaker when Play button is pressed.

Thanks for your help!!


Pantseatflyer

Swapped out the ULN2803 with the ULN2003...

EUREKA!

I had thought that the ULN2003 was to be used with the Prop-1 trainer only.... my bad..

JonnyMac

Yep, your bad!  ;D  We actually have this annoying note of every serial product page:

Technical Note
The ULN2803A output driver can interfere with serial communications between a prop controller (Prop-1, Prop-2, or Prop-SX) and the {product}. EFX-TEK recommends that P7 (Prop-1) or P15 (Prop-2 and Prop-SX) is used for serial communications, and that the ULN2803A is replaced with a (7-channel) ULN2003A to prevent interference.

We also took the trouble to write up this thread:
-- http://www.efx-tek.com/php/smf/index.php?topic=130.0

Glad it's working -- Halloween is close!
Jon McPhalen
EFX-TEK Hollywood Office

Pantseatflyer

Hey Jon,

I have a small snag.  The "Cocoon" motor that I am using will not turn off.  I did discover that there are some components on its board that causes this. 

The motor runs by making the switch connection, but upon removing the connection the motor will still run until you make the connection once more thereby stopping the motor. 

My thoughts were adding a Cocoon = IsOff (motor still running) and then a second Cocoon = IsOn line which would essentially 'stop' the motor.

Your thoughts?

JonnyMac

Are you trying to run a DC device from an AC relay in the RC-4?  This is a no-no.  SSRs -- like the ones we use in the RC-4 -- are designed to switch AC only.  The actual switching component inside is called a triac, and once it's on it will stay on until the power is removed.  In an AC cycle this happens 120 times each second at the zero-cross point.  If a DC circuit the power does not go away until you remove it externally.

Short version: You cannot use the SSRs we supply for the RC-4 to switch DC circuits.  Crydom does make DC relays, but they are very expensive.
Jon McPhalen
EFX-TEK Hollywood Office

Pantseatflyer

Yep... Both "Cocoon" and "Spotlight" are DC.  The Cocoon is powered by two (AA) batteries (3vdc) and the Spotlight is a 5 LED configuration run on a 9-volt battery.

I did not realize that the relays were AC only. 

I am concerned about going through the Prop-2 as it pushing out 12 volts. Oh well.

This is what happens when you procrastinate this close to halloween.

Worse comes to worse, I still have my fog machine and AP-8.  ???

BigRez

Isn't your cocoon and Spotlight hooked up to the pin1 and pin0 and NOT the RC-4?  Seems to me that you're just "flipping" a switch since they have their own power, right?

I've got a similar set up (although with a prop-1) where I want to activate a device from pin1.  The device (sound and lights) has it's own power and currently activates via motion sensor.  There is a power switch connected to the three AA batteries that I'd like the prop-1 to control (so that I can stop the lights/sound when I want.)  How does this conenct to the pins?