November 23, 2024, 03:20:36 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.


Tricky uMP3 audio code

Started by tomb rogue, October 22, 2009, 05:31:52 PM

Previous topic - Next topic

tomb rogue

Greetings All;

I have a Prop-1 successfully connected & tested with the uMP3 player exactly as described in the
"Using the uMP3 with the Prop-1" thread.

I wondering if anyone has run code for uMP3 audio at all similar to my description below that I could use.

I have added a relay on P2(for fog), the PIR on P6 and the uMP3 utilizing P5 & 4.
I left P3 open in case I need a connection from the "D" pin on the uMP3 to signal the prop 1 at the
end of each track. The 5 tracks I am using are named simply 1.mp3, 2.mp3, 3.mp3, etc. 

Basically at the start of the program:

once the PIR detects motion

Start track one and hit the fog for 3 seconds
at the end of the track wait 10 seconds & check the pir

if motion detected - fog 2 seconds before starting track 2 
if no motion -reset

at the end of track 2 wait 10 seconds & check the pir

if motion detected - fog 2 seconds before starting track 3
if no motion - reset

at the end of track 3 wait 10 seconds & check the pir

if motion detected - fog 2 seconds before starting track 4
if no motion - reset

at the end of track 4 wait 10 seconds & check the pir

if motion detected - fog 2 seconds before starting track 5
at the end of track 5, fog for 4 seconds and suspend everything for 20 seconds and reset

if no motion was detected - reset



It sounds simple in concept but the audio code is above my skill level at this time.

Any help would be greatly appreciated.

Thanks,
Tombrogue

JonnyMac

Not too tricky for "The JonnyMac"!  ;D

Note that I "rewired" your circuit -- it's better to use P6 and P7 for the serial comms with the uMP3 with the SETUP jumpers in the UP position (I won't bore you with the tech details, but it matters).  Use P5 (ULN pin intact) for the PIR input.

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


' -----[ Program Description ]---------------------------------------------
'
' RX/TX   :: Serial connection to uMP3
'            -- P6 & P7 setup jumpers = UP
'            -- clip pins 1 & 2 of ULN2803
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P5.W and P5.R


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


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

SYMBOL  RX              = 7                     ' to UMP3.T; no ULN
SYMBOL  TX              = 6                     ' to UMP3.R; no ULN
SYMBOL  Trigger         = PIN5                  ' keep ULN; is pull-down
SYMBOL  Fogger          = PIN2


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

SYMBOL  Baud            = OT2400

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

SYMBOL  char            = B2
SYMBOL  track           = B3
SYMBOL  idx             = B4

SYMBOL  timer           = W5


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

Warm_Up:
  GOSUB UMP3_Stop                               ' stop if playing
  PAUSE 30000                                   ' let PIR warm up

Prod_uMP3:
  SEROUT TX, Baud, (13)                         ' send CR
  SERIN  RX, Baud, char                         ' get response
  IF char <> ">" THEN Prod_uMP3                 ' wait for ">"

Reset:
  PINS = %00000000                              ' preseti IOs
  DIRS = %00000100                              ' set output pins (1s)

  track = 1


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

Main:
  GOSUB Scan_Sensor
  IF timer < 100 THEN Reset
  GOSUB UMP3_Track

  ' run fogger timing for track

  idx = track - 1
  LOOKUP idx, (3000, 2000, 2000, 2000, 2000), timer
  Fogger = IsOn
  PAUSE timer
  Fogger = IsOff

  GOSUB UMP3_WaitPlay

  ' post-track delay

  idx = track - 1
  LOOKUP idx, (10000, 10000, 10000, 10000, 0), timer
  PAUSE timer

  track = track + 1                             ' next track
  IF track <= 5 THEN Main                       ' more

  Fogger = IsOn                                 ' no, blast once more
  PAUSE 4000
  Fogger = IsOff

  PAUSE 20000                                   ' retrigger delay
  GOTO Reset


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

' Scan /debounce sensor input
' -- will return value 0 to 100 based on signal input
' -- use >70 to indicate valid input
' -- consumes 100ms (0.1s)

Scan_Sensor:
  timer = 0
  FOR idx = 1 TO 20
    PAUSE 5
    timer = timer + 5 * Trigger
  NEXT
  RETURN

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

' Play numbered track, e.g., 1.mp3, 2.mp3, etc.

UMP3_Track:
  SEROUT TX, Baud, ("PC F /", #track, ".MP3", 13)
  RETURN

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

UMP3_Stop:
  SEROUT TX, Baud, ("PC S", 13)
  RETURN

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

UMP3_Status:
  SEROUT TX, Baud, ("PC Z", 13)                 ' request status
  SERIN  RX, Baud, char                         ' will be "S" or "P"
  RETURN

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

' Will hold if uMP3 is playing

UMP3_WaitPlay:
  PAUSE 75
  GOSUB UMP3_Status
  IF char = "P" THEN UMP3_WaitPlay
    RETURN

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

tomb rogue

Hello again everyone:

First of all let me thank you Jon. I appreciate it.

For anyone, I do have a couple questions though...

Just to be sure, I am actually removing p6 and p7 when you say pins 1 and 2 correct? (fortunately I had the first 4 pins just bent out
of the way rather than clipped so I'm good with bending 4 & 5 back in).

The other question I had is this..

I'm confused about what "PC F" "S" "Z" and the "13" are. Are the F,S,P forward stop and play
commands? if so I assume that Z is a status request. This was a total guess. I couldnt see anthing to relate the 13 to.   


Thanks again for any comments.
Tombrogue

JonnyMac

You are going to pull the ULN2803 from the socket, do a little surgery (amputate pins 1 and 2), then put it back.
-- see this thread: http://www.efx-tek.com/php/smf/index.php?topic=130.msg476#msg476

In your case, yes, you can put pins 4 & 5 back (the ULN acts as a pull-down on P5 to prevent false triggers when the PIR is not connected).

Finally, we will write code for you all day long, but we will not hold your hand to teach you another vendor's product.  ;D  Download the uMP3 documentation (from www.roguerobotics.com) and read it.  But now that the hair on my neck is standing up... how could you be making a total guess?  The names of the routines and the comments spell out exactly what's going on!  :P

13 is the value of a carriage return character -- all uMP3 commands are terminated with this (you'll find this in the uMP3 docs).
Jon McPhalen
EFX-TEK Hollywood Office

tomb rogue

Sorry about the questions, still working through the novice stage. Good to go on this one though thanks.

Tombrogue

tomb rogue

Greetings everyone;

Just wondering if anyone has time to look this over. It seems to be in the middle of playing a track & then just jump to the next track. I beliieve it is detecting motion & starting again with the first or next track. I'm wondering if it needs something in the "ump3 wait play" subroutine to kill the motion sensor if any track is playing.

I know everyone is busy but if anyone has time I appreciate it.

Tombrogue

JonnyMac

Did you update the LOOKUP table under the banner called "post-track delay"? -- I just loaded 10 seconds into each not know how long your audio tracks are; this should take care of the problem you're seeing. 
Jon McPhalen
EFX-TEK Hollywood Office

tomb rogue

Thanks Jon; I really appreciate your help. I am going to test and troubleshoot again in the morning. I'm sure I will have some more questions though. I am going to learn this, period!!

Tombrogue