November 18, 2024, 02:36:50 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.


Newbie needs help getting pir, prop 1 and ap-8 to work

Started by widiver, August 25, 2008, 06:58:33 AM

Previous topic - Next topic

widiver

Hi
This will be my first project using the pir, prop 1 and ap-8. It is going to be a trick or treat greeter. when someone passes in front of the pir I would like the ap-8 to play the audio. Right now I can't get it to work.
I have the audio in the ap-8 and I can hear it play when I press the play button.
This is the code I am using for the prop 1 (it is from garageofevil.com
----------------
' (c) 2007 Garage of Evil
' http://www.garageofevil.com
'
' this program will watch for the PIR sensor to trigger on PIN7, and then
' trigger the AP-8 to play it's audio, and then wait 60 seconds before doing it
' again...
'
' {$STAMP BS1}
' {$PBASIC 1.0}

SYMBOL Audio = 0                   ' AP-8 is on P0
SYMBOL PIRSensor = PIN7            ' input trigger on P7
SYMBOL IsOff = 0
SYMBOL IsOn = 1

Reset:
  DIRS = %00111111                  ' make P7-P6 inputs, P5-P0 outputs
  PINS = %00000000                  ' all outputs off

Main:

TryAgain:
  'DEBUG "..CHECKING.."
  IF PIRSensor = IsOff THEN TryAgain  ' wait until trigger is activated

  'DEBUG "   SENSOR TRIGGERED!   "
  SEROUT Audio, OT2400, ("!AP8", %11, "P", 0)
  PAUSE 60000  ' wait 60 seconds

  GOTO Main   ' repeat forever
END
--------------------------
I hooded up the prop 1 to my computer and loaded the code into the basic stamp editor and then his run. The screen showed that the code was downloaded.
I put the pir on p7 and the ap-8 on p0.
The switch on the prop 1 is set to 1 and the switch is set to lo on the ap-8
Was power is applied nothing happen.

Is there something I am missing or forgetting to do?

thanks for your help
John

JonnyMac

Well, your program "violates" (that's a little stronger than I mean) a couple of our guidelines:

1) We always suggest using P7 for serial output to the AP-8 and similar devices.  The reason is that the ULN2803 interferes with serial comms; by using P7 we can change the ULN2803 to a ULN2003 or clip pin #1 (easier to find) to eliminate the interference.  This thread goes into great detail on the ULN and how to change it our or modify it when using serial:

http://www.efx-tek.com/php/smf/index.php?topic=130.0

2) Our documentation on using the PIR strongly suggests that it be debounced.  PIRs can be twitchy and give false positives unless properly debounced. 

Here's my update of your program.  To make it easy it expects all AP-8 jumpers (Baud, A0, and A1) to be removed.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  timer           = B2


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00111111                              ' make P0-P5 outputs


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

Main:
  timer = 0                                     ' reset timer
  DEBUG "Waiting for PIR...", CR

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * PIR                       ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  DEBUG "Triggered!", CR, CR

  SEROUT Sio, Baud, ("!AP8", %00, "P", 0)
  PAUSE 60000
  GOTO Main


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


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


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


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

widiver

Hi Jon
I loaded the new code, put the pir on pin 6 and the ap-8 on pin 7. I removed the 3 jumpers on the ap-8.
When I run the program I get the debugging screen and I can see that the pir is being triggered appropriately. I am still not getting any audio, is this because I need to change the ULN2803A with the   ULN2003A (Stock #: 500-00004)? If that's the issue I should just need to order the part, pop the old one off, put the new one on and reload the code?

thanks for your help.
John 

JonnyMac

Yes, as I indicated above you must remove the ULN's influence from the serial pin.  There is a link in my earlier response that shows you how to cut the proper pin from the ULN2803 -- will save you the order (you can order more later).  Also, make sure you have the serial cable going into the serial header on the AP-8, not the P (Play) header as customers will do once in a while.
Jon McPhalen
EFX-TEK Hollywood Office

widiver

Hi Jon

Wow, what a fast response, don't you sleep. I did surgery this morning on pin 1 and its all working.

thanks for your help

John

JonnyMac

Between now and Halloween I won't be sleeping much... that's okay, as long as everyone's props are working.  I can sleep in November.
Jon McPhalen
EFX-TEK Hollywood Office