May 03, 2024, 10:04:26 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.


Programming or hardware help

Started by time2dive, November 15, 2019, 02:48:09 AM

Previous topic - Next topic

time2dive

I am trying to control a MDFLY AU5018 it wants a low to control what plays it runs on TTL voltage inputs. As of now I am using the Prop 1 to control 5v relays P0-P5 to control "Play", "Repeat" and "Tracks. I am using a push button trigger which does appear to work
The problem that I am having is that only the relay hooked up to P0 is doing anything. It is triggering when the other I/O (P1-P5)should be triggering. The other relays have power.

here is my code

' =========================================================================
'
'   File...... music player.bs1
'   Purpose... control MDFLY AU5018
'   Author.... Timothy Ewing
'   E-mail.... time2dive@hawaii.rr.com
'   Started... 14 NOV 2019
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'   audio board controller
'   input PIR
'   output relay controls
'   output lights

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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  trigger         = PIN6                  ' SETUP = DN
SYMBOL  play            = PIN0                  ' play
SYMBOL  track1          = PIN1                  ' track 1
SYMBOL  track2          = PIN2                  ' track 2
SYMBOL  track3          = PIN3                  ' track 3
SYMBOL  repeat          = PIN4                  ' repeat
SYMBOL  light1          = 5                     ' light 1



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

SYMBOL  IsOn            = 1                     ' for ative-high input
SYMBOL  IsOff           = 0


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


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

Reset:


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

  PAUSE 1000
  HIGH play                                    ' play mp3
  PAUSE 250                                    ' wait 250 msec
  LOW play                                     ' play off
  HIGH repeat                                  ' repeat on
  PAUSE 250                                    ' pause 250 msec
  LOW repeat                                   ' repeat off
  PAUSE 4500                                   ' play track 1 for 45 seconds
  Main:
  IF Trigger = IsOff THEN Main                 ' wait for trigger
  HIGH light1                                  ' turn on light
  HIGH track2                                  ' track 2 on
  PAUSE 250                                    ' pause 250 msecf
  LOW track2                                   ' low track 2
  PAUSE 4500                                   ' play track 2 for 45 seconds
  HIGH track3                                  ' track 3 on
  PAUSE 250                                    ' wait 250 msec
  LOW track3
  PAUSE 4500                                   ' play track 3 for 45 seconds
  LOW light1                                   ' light 1 off
  HIGH track1                                  ' track 1 on
  PAUSE 250                                    ' wait 250 msec
  LOW track1
  HIGH repeat                                  ' repeat on
  PAUSE 250                                    ' wait 250 msec
  LOW repeat
  GOTO Main

Jeff Haas

Hi Tim,

I made a few updates:

- Added pin definitions in the Initialization section.  You forgot these, they're important on the BS1.
- Added "PIN" to PIN5 - you needed this.
- Changed all HIGH and LOW lines to JM's "IsOn" and "IsOff", which is easier to read.  You already had that set up in the top of the code.
- Your pauses were all very short, I made them longer so you can see them.  Remember that PAUSE = 1000 is only one second long, so 250 is really short and may not be what you wanted.
- Added JM's debounce routine for the button input.  This will also work for a PIR.  Doing it this way makes things more reliable, especially with a PIR.
- Some simple reformatting, including labelling your first section "Startup" because you're doing something different there than when you trigger the prop.

I tested this on a Prop-1 Trainer.  Try it out, and I think you'll want to experiment with the pauses, they're still pretty short.

Jeff


                                   ' =========================================================================
'
'   File...... music player.bs1
'   Purpose... control MDFLY AU5018
'   Author.... Timothy Ewing
'   E-mail.... time2dive@hawaii.rr.com
'   Started... 14 NOV 2019
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'   audio board controller
'   input PIR
'   output relay controls
'   output lights

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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  trigger         = PIN6                  ' SETUP = DN
SYMBOL  play            = PIN0                  ' play
SYMBOL  track1          = PIN1                  ' track 1
SYMBOL  track2          = PIN2                  ' track 2
SYMBOL  track3          = PIN3                  ' track 3
SYMBOL  repeat          = PIN4                  ' repeat
SYMBOL  light1          = PIN5                  ' light 1



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

SYMBOL  IsOn            = 1                     ' for active-high input
SYMBOL  IsOff           = 0


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

SYMBOL  timer           = B2

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

Reset:

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

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

Startup:

  PAUSE 1000
  play = IsOn                                  ' play mp3
  PAUSE 1000                                   ' wait
  play = IsOff                                 ' play off
  repeat = IsOn                                ' repeat on
  PAUSE 1000                                   ' pause
  repeat = IsOff                               ' repeat off
  PAUSE 4500                                   ' play track 1 for 45 seconds

Main:

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

  light1 = IsOn                                ' turn on light
  track2 = IsOn                                ' track 2 on
  PAUSE 1000                                   ' pause
  track2 = IsOff                               ' track 2 off
  PAUSE 4500                                   ' wait while track 2 plays
  track3 = IsOn                                ' track 3 on
  PAUSE 1000                                   ' wait
  track3 = IsOff                               ' track 3 off
  PAUSE 4500                                   ' play track 3 for 45 seconds
  light1 = IsOff                               ' light 1 off
  track1 = IsOn                                ' track 1 on
  PAUSE 1000                                   ' wait
  track1 = IsOff                               ' track 1 off
  repeat = IsOn                                ' repeat on
  PAUSE 1000                                   ' wait
  repeat = IsOff                               ' repeat off

  GOTO Main

time2dive

Pin0-Pin4 are using P0-P4 using servo connectors,  the light is using Out5. Should that be labeled Out5 or just 5. The reason for the 250 msec pauses is to simulate pressing a button on the audio board.
I will make changes and try it.

Jeff Haas

If you're  using relays for all the outputs then I thnik the program will work the way it is.  Using the screw terminal for the light is usually a way to have the Prop-1 provide the power, but triggering the output is the same.

Let us know how it works out!

time2dive

Everything works! Thanks for the help. So the main changes were to replace  "High Play" with "play IsOn" and all of the other similar commands and add the trigger function....so I was sort of close.  I will tweak the pause and play times to fit the actual track time and see if the Prop1 will control the MDFLY board without the relays.
Will this same code work for a Prop2? I will need more outputs for the final prop. This was a test of concept.
Again...thanks for the help.

Jeff Haas

A really important change was the two lines in the initialization section, which configure the pins.

This will need to be adapted for the Prop-2, some of the Basic commands are different.

Jeff Haas

Tim,

One thing I forgot - the MDFly board you're using can be controlled by a serial connection with a Prop-2.  The Prop-1 doesn't have the right serial speed to work with that board, but the Prop-2 can work fine with it.  So it will make things easier to control the sound effects - you have one connection from the Prop-2 to the MDFly board.  I've got a few of these modules and have used them very successfully with the Prop-2.  I will put up a thread in the Prop-2 section and post code there for you.

Jeff