May 12, 2024, 12:15: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.


Need help with prop1 and vmusic2

Started by tugman, April 09, 2009, 04:59:03 PM

Previous topic - Next topic

tugman

Jon,  I have the vmusic communicating with the pc through hyper-terminal so I know the baud is set correctly.  Still having trouble getting it to work. I looked at your code and see no provision for volume.  I tried to put something in for this myself but I don't know anything coding yet.  I don't know if this might be the problem or not.   
Something else I'm wondering is- when you put your files in the thumb drive do you have to put any addressing  in the names of each song file or is just the 8 or less character name all you need?
  Thanks,  tugman




' =========================================================================
'
'   File...... VMusic_8x.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 09 APR 2009
'
'   {$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


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

SYMBOL  Baud            = OT2400

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  song            = B0                    ' song selection
SYMBOL  bCount          = B1                    ' bit count
SYMBOL  shift           = B2
SYMBOL  eePntr          = B3                    ' EEPROM pointer
SYMBOL  char            = B4                    ' char to TX
SYMBOL  chNum           = B5                    ' characters sent


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

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


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

Main:
  song = PINS & %00011111                       ' get button(s)
  IF song = %00000000 THEN Main                 ' wait for press

Count_Buttons:
  bCount = 0
  bCount = bCount + BIT0
  bCount = bCount + BIT1
  bCount = bCount + BIT2
  bCount = bCount + BIT3
  IF bCount > 1 THEN Main                       ' no "chords" allowed

  LOOKDOWN song, (%1, %10, %100, %1000), song   ' convert bit to #
  shift = BIT4 * 4                              ' shift = 0 or 4
  song = song + shift                           ' add "shift" input
  eePntr = song * 8                             ' create EE pointer

Play_Song:
  SEROUT TX, Baud, ("VPF ")                     ' send play command
  chNum = 0                                     ' clear character count

Send_Name:                                      ' send file title
  READ eePntr, char                             ' get a character
  IF char = 0 THEN Finish_Cmd                   ' if zero, we're done
  SEROUT TX, Baud, (char)                       ' else send the character
  chNum = chNum + 1                             ' update character count
  IF chNum = 8 THEN Finish_Cmd                  ' abort on max length
  eePntr = eePntr + 1                           ' point to next character
  GOTO Send_Name

Finish_Cmd:
  SEROUT TX, Baud, (".MP3", 13)                 ' send extention + CR

  GOSUB VM_Wait_Start                           ' let song start
  GOTO Main


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

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

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

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

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

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


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

' Use file name only -- must be eight or fewer characters and followed
' by zero.  Do not change EEPROM address setting for any line.

Song_List:
  EEPROM $00, ("1OFDAYS", 0)
  EEPROM $08, ("BLOWMEDN", 0)
  EEPROM $10, ("FOGHORN", 0)
  EEPROM $18, ("LNGSONG", 0)
  EEPROM $20, ("OPENSEZ", 0)
  EEPROM $28, ("POPLAUGH", 0)
  EEPROM $30, ("POPTOOT", 0)
  EEPROM $38, ("SHRTSONG", 0)

JonnyMac

May 27, 2009, 08:14:51 AM #31 Last Edit: May 27, 2009, 08:18:50 AM by JonnyMac
When you power up the VMUSIC the volume is set to max.  I've changed my routine to this:

VM_Mute:
  mute = mute MAX $FE                       ' limit per spec
  SEROUT TX, Baud, ($88, $20, volume, 13)
  RETURN


The reason is that the default level of 0 is the loudest, so any number higher than this is muting the audio.

At the end of the day you must not be connecting it to the Prop-1 correctly, otherwise it would work.  Let me suggest that you disconnect and try again (trust me, I take this route all the time with stuff -- I'm old enough not to assume I connected anything correctly).  Here's a drawing of how I connect the VMUSIC to the Prop-1; use this to check your connections.



Keep in mind that the pin labeled TX on the Prop-1 must connect to the RX pin on the VMUSIC, and vice-versa.  Thing of TX as a mouth and RX as an ear -- you need to have the mouth connected to the ear for communications.

The file names just need to follow the 8.3 format -- in your case they will be:

1OFDAYS.MP3
BLOWMEDN.MP3
FOGHORN.MP3
LNGSONG.MP3
OPENSEZ.MP3
POPLAUGH.MP3
POPTOOT.MP3
SHRTSONG.MP3
Jon McPhalen
EFX-TEK Hollywood Office

tugman

Jon, do I need to add this to get this to work and if so where do I put it in the program and do I need to call it up as a subroutine, if so how do I do that.

VM_Mute:
  mute = mute MAX $FE                       ' limit per spec
  SEROUT TX, Baud, ($88, $20, volume, 13)
  RETURN

I have check everthing per your instructions everthing seems to be correct but still no sound.
Now here is something that I have done.  I installed Scary Terry's demo program. the debug screen comes up and says playing firefly but I get no sound through the headphone jack.
With your program when it powers up and I press one of the buttons I see the jump drive led flash very briefly but still no sound.  I am pretty sure, because of this that the prop 1 is communicating with the VMUSIC  but no sound.  I think I am very close to getting this thing to work. Any ideas?

JonnyMac

You do not need to deal with muting -- one power-up the VMUSIC sets itself to maximum volume (0 mute level).

I feel for you but I don't know what else to say.  We don't make the VMUSIC, the only thing we can do is show you have we've made it work -- and I have done that.  There is a danger going back and forth between my code and Terry's as we do things differently.   With respect to my friend Scary Terry, my code is more robust.

Q: Do you have a file called "firefly.mp3" on your memory stick?  If not, of course it won't play -- you're telling the VMUSIC to play a file that's not there.
Jon McPhalen
EFX-TEK Hollywood Office

tugman

Yes I did put a file on it called firelfly.

tugman

All I have to do is put any mp3 file on the jump drive and call it, for example, firefly.mp3.  Is there anything more needed for the file name that that?  I keep thinking I'm doing some silly thing wrong that I am overlooking.

JonnyMac

Yes, all you have to do is have a file -- in the root -- that corresponds to what you're calling.  You may want to try my VMUSIC demo program first just to get that side worked out;  once the VMUSIC is working then you can add the buttons in.
Jon McPhalen
EFX-TEK Hollywood Office

tugman

Jon, you said that I should get the vmusic working with the vm2 demo. I did that and low and behold I actually got the thing to play,  how or why it worked this time, I don't have a clue!  I'm going to go back to your code now and see what I can do with that.  I see that you have added some new code today I think I'll try that. You mention in the text that if you use different song name you must change the names at the end of the program.  That makes sense to me but do you also have to also change song names called out in the upper part of the code where it says playing firefly etc.?  I'm just trying to learn.

JonnyMac

Excellent news -- and guess what?  Sometimes that just happens!  Just yesterday I was helping a friend with a Propeller (new chip from Parallax) to SX (what we use in the Prop-SX) communications problem; I managed to finally get it working but am not sure why it didn't work in the first place!

On your question: You must change the file names in the DATA/EEPROM statements for the code to work; you should change the DEBUG statements to prevent confusion.  Let me suggest that you make a copy of the code that is now working and add you new elements into it; it's better to start with a working platform and build up.
Jon McPhalen
EFX-TEK Hollywood Office

tugman

Jon, I went back to your code with the 8 sw's and nothing.  When I power up and push and of the buttons 1-4  I see a very short flash of the led on the jump drive but no sound. This only works for one press of any one of these buttons, if I push any of them a second time I get nothing no flash. Power up again and the same thing happens.

The pulse that goes to p7 when the buttons 1-4 are pressed is only about 80 micro seconds long.  I don't know what it's supposed to be.  I didn't think to check that when it was working with the vm2 demo code.  This is just for your information thought maybe  it might jog your memory about something

This only works with  the first 4 buttons.  If I try this with buttons 5-8 nothing at all happens, no pulse and no flash.  This part may have to do with the steering diodes?  Have you used this steering diode setup before? I don't understand how,( sw's 5-8 all tied to the same input p4.w in this case), you can identify which of these buttons buttons has been pressed in order to chose the correct song to play?  I'm not being critical  I'm just trying to understand.

Thanks, tugman


JonnyMac

With the VMUSIC running we can move to the next step -- this is how development works.

Two things:

1) I'm human (shocking, I know...) and I could have erred
2) I didn't build the switch circuit but with 30+ years of experience I'm confident in it.

What do do?  Isolate the switch circuit in code and use the DEBUG facilities of the BASIC Stamp to show you what you're getting. 

Use this program to test your switch inputs.  It will show the state of the inputs (1 when pressed) and how many buttons are pressed.  If you built the circuit correctly then pressing PB5 through PB8 will show 2 inputs active (PIN4 + one other)

' =========================================================================
'
'   File...... VMusic_8x.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 09 APR 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  song            = B0                    ' song selection
SYMBOL  bCount          = B1                    ' bit count


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

Reset:
  DEBUG CLS


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

Main:
  song = PINS & %00011111                       ' get button(s)
  'IF song = %00000000 THEN Main                 ' wait for press

Count_Buttons:
  bCount = 0
  bCount = bCount + BIT0
  bCount = bCount + BIT1
  bCount = bCount + BIT2
  bCount = bCount + BIT3

  DEBUG "Buttons = ", #%song, "  ( ", #bCount, ")", CR
  PAUSE 100
  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

tugman

Jon, I did the debug as directed.  I worked pretty much as you said. 
The only difference and this may be important, switches 1 through 4 work just as you said, but sw's 5-8 you get 5+ another sw instead of 4+ another sw

switch 1 =   1
switch 2 =   2
switch 3 =   3
switch 4 =   4

switch 5 =   1 & 5
switch 6 =   2 & 5
switch 7 =   3 & 5
switch 8 =   4 & 5


JonnyMac

May 29, 2009, 07:59:20 AM #42 Last Edit: May 29, 2009, 12:13:09 PM by JonnyMac
I'm going to assume that you mean:

switch 1 = %00000001
switch 2 = %00000010
switch 3 = %00000100
switch 4 = %00001000
switch 5 = %00010001
switch 6 = %00010010
switch 7 = %00010100
switch 8 = %00011000

If that's the case then it works as intended.  Looking at the original code again I found a error on my part (told you I was human) that was causing the could cause the LOOKUP table to fail in some cases.  Try this version of the code -- this folds the update switch input to the updated VMUSIC code.

Note: This code has been tested and refined -- it works as intended and will not be developed any further.

' =========================================================================
'
'   File...... VMusic_8x.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 29 MAY 2009
'
'   {$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


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  VolMax          = 0
SYMBOL  VolMin          = $FE

SYMBOL  Baud            = OT2400


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

SYMBOL  song            = B0                    ' song selection
SYMBOL  bCount          = B1                    ' bit count
SYMBOL  theMP3          = B2                    ' MP3 file pointer
SYMBOL  eePntr          = B3                    ' EEPROM memory pointer
SYMBOL  char            = B4                    ' character value
SYMBOL  mute            = B5                    ' mute level (0 = loudest)
SYMBOL  idx             = B6                    ' loop controller


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

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


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

Main:
  song = PINS & %00001111                       ' get button(s)
  IF song = %00000000 THEN Main                 ' wait for press

Count_Buttons:
  bCount = BIT0 + BIT1 + BIT2 + BIT3
  IF bCount > 1 THEN Main                       ' no "chords"

  LOOKDOWN song, (%1, %10, %100, %1000), song   ' convert bit to #
  theMP3 = PIN4 * 4 + song                      ' add shift button

  GOSUB VM_Play
  GOSUB VM_Wait_Start

Force_Release:
  PAUSE 100
  song = PINS & %00001111                       ' rescan
  IF song <> %00000000 THEN Force_Release
    PAUSE 1000

  GOTO Main


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

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

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

' Pass file # (index in EEPROM table) to play in "theMP3"

VM_Play:
  SEROUT TX, Baud, ("VPF ")
  GOTO Play_MP3

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

' Pass file # (index in EEPROM table) to play in "theMP3"

VM_Repeat:
SEROUT TX, Baud, ("VRF ")

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

Play_MP3:
  eePntr = theMP3 * 8                           ' calc address of name

Send_Name:                                      ' send file title
  FOR idx = 1 TO 8                              ' max is 8 characters
    READ eePntr, char                           ' get a character
    IF char = 0 THEN Finish_Cmd                 ' if 0, we're at end
    SEROUT TX, Baud, (char)
    eePntr = eePntr + 1
  NEXT

Finish_Cmd:
  SEROUT TX, Baud, (".MP3", 13)                 ' send extention + CR
  RETURN

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

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

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

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

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

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

VM_Mute:
  mute = mute MAX VolMin                        ' limit per spec
  SEROUT TX, Baud, ("VSV ", #mute, 13)
  RETURN


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

' File names are stored on 8-byte boundaries -- this is very important for
' correct program operation.  This strategy uses a little more EE space but
' is easier to update and maintain

Song_List:
  EEPROM $00, ("firefly")                       ' theMP3 = 0
  EEPROM $08, ("serenity")                      ' theMP3 = 1
  EEPROM $10, ("spalding")
  EEPROM $18, ("angel")
  EEPROM $20, ("fruity")
  EEPROM $28, ("thunder1")
  EEPROM $30, ("thunder2")
  EEPROM $38, ("glass")
Jon McPhalen
EFX-TEK Hollywood Office

tugman

Yes Jon, that is what I meant by the switches.

When a button is pressed it start out at the bottom  of the table with the appropriate 1's and works it's way up to the top.  I guess this is correct?

Now I tried your new code and changed the file name at the bottom to match what is on my jump drive, still no sound- but now I do get a real short flash on the jump-drive for all of the buttons and they will work again and again without restarting the prop1!  So, I think whatever you did was a step in the right direction.
Were so close, I just know it.

JonnyMac

Yes, that is correct.  Now (stern mode on)... in the length of time we've been working on this you should have learned about binary numbers and bit positions in binary values; it's really important for embedded control.  Time to crack open the Help file and start reading beyond the immediate project at hand (stern mode off).

Before we assume the program is bad, download it again and then cycle power on the Prop-1 (and VMUSIC which should be powered from the Prop-1); I found I had to do this when changing things yesterday.

If that doesn't work let's re-test the integration -- add these lines of code at the end of the Reset section

  theMP3 = 0
  GOSUB VM_Play
  GOSUB VM_Wait_Start
  END


After downloading, cycle the power on the Prop-1 -- this should play your first song; if not we need to figure out why.

Jon McPhalen
EFX-TEK Hollywood Office