November 24, 2024, 05:22:26 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Prop2 SEROUT question

Started by davisgraveyard, July 26, 2024, 05:14:40 PM

Previous topic - Next topic

davisgraveyard

July 26, 2024, 05:14:40 PM Last Edit: July 26, 2024, 05:22:44 PM by davisgraveyard
I am converting an old Prop1 program that uses SEROUT to send commands to a AP8 audio player.  I am switching to a different audio board. 

I have to send a series of hex values to the audio board

"AA","07","02","00","01","B4"

What is the syntax for doing this?   Should I convert these to decimal values?

Something like this?

  SEROUT Sio, Baud, ["AA","07","02","00","01","B4", HEX2] 




Jeff Haas

Hey, good to hear from you!

It would be helpful to tell which audio player you're using.  I've done serial commands with the Prop-2, so if you can point me to the datasheet I can take a look.

I've already got Prop-2 code for the YX-5300/Catalex boards, and the DY Player boards.

davisgraveyard

it is a DY player board.  specifically a DY-HV8F

Here is a link to some specs from the Arduino library Dyplayer

https://github.com/SnijderC/dyplayer/blob/main/README.MD

DY-XXX.pdf

Jeff Haas

Ok, let me dig up my code and test it tomorrow.  All the DY players use the same code, they just have different versions for installing on circuit boards vs. stand-alone.

Jeff Haas

So here's everything you need to know about the DY Players.

The quick answer to your question is to format the command like this on the Prop-2 (Basic Stamp 2):

' -----[ I/O Definitions ]-------------------------------------------------
MP3   PIN     7    'BS2 Pin to DY player.  Connects to W header of EFX Prop-2; use servo cable for RWB connection.

SEROUT MP3,84,[$AA,$07,$02,$00,$01,$B4]' Play file #1

I just tested and commented my code for the Prop-2 (Basic Stamp 2), it's at the bottom of this post.  The main thing that will trip you up is trying to tell the DY module to play a specific file.  The last number in the SEROUT command is a checksum of all the others before it.  So in the line above, I used an online checksum generator to add these up:

AA 07 02 00 01

And it came back with B4, using:
CheckSum8 Modulo 256
(Sum of Bytes % 256)

So to tell it to play file #2, the command is:
[$AA,$07,$02,$00,$02,$B5]
The next-to-last number is 02 (play file #2), and the checksum is B5.

There was a thread on the Parallax forums a couple of years ago when these first popped up.  Erco  (Eric Ostendorf, a friend of mine) did a write up and review:

https://forums.parallax.com/discussion/174387/my-new-favorite-mp3-module

Here's the code.


' {$STAMP BS2}
' {$PBASIC 2.5}

' From erco on Parallax forum:
' https://forums.parallax.com/discussion/174387/my-new-favorite-mp3-module#latest

' DY-SV17F MP3 player
' BS2 PIN TO MP3 BUSY PIN WITH 10K PULLUP TO +5V
' (ON DY Players with dip switches, no need for a resistors, they are built into the board.)
' BS2 PIN OUT TO MP3 RX PIN

' -----[ I/O Definitions ]-------------------------------------------------
MP3   PIN     7    'BS2 Pin to DY player.  Connects to W header of EFX Prop-2; use servo cable for RWB connection.

' -----[ Init ]----------------------------------------------------

PAUSE 500 ' Give module a moment to initialize

SEROUT MP3,84,[$AA,$13,$01,$14,$DC]   ' Set volume - dec 20=14 D2   max dec 30=1E DC
PAUSE 100

'************ UNCOMMENT ONE GOTO FOR TESTING ******   

GOTO ONEFILE
'GOTO PLAY
'GOTO SHUFFLE

'************* PLAY SPECIFIC FILE *************
ONEFILE:
DO
  DEBUG "Play file #1",CR
  SEROUT MP3,84,[$AA,$07,$02,$00,$01,$B4]' Play file #1

  DEBUG "Pause 3 seconds",CR
  PAUSE 3000     ' PAUSE TO PLAY 3 SECONDS OF FILE
LOOP


'************ SEQUENTIAL PLAY *****************
PLAY:
DEBUG "Sequential Play",CR
DO
  SEROUT MP3,84,[$AA,$02,$00,$AC]' PLAY WHATEVER FILE
  PAUSE 3000     ' PAUSE TO PLAY 3 SECONDS OF FILE

  SEROUT MP3,84,[$AA,$06,$00,$B0]' NEXT FILE
  PAUSE 100
LOOP


'************ RANDOM PLAY *********************
SHUFFLE:      ' Nonstop play, module plays autonomously

DEBUG "Random Play",CR

SEROUT MP3,84,[$AA,$18,$01,$03,$C6]'SELECT 03= RANDOM
PAUSE 100
SEROUT MP3,84,[$AA,$02,$00,$AC]' PLAY CURRENT
STOP

'************ TEST BUSY PIN *******************
TESTBUSY:  ' requires 10K resistor between module pins 12 & 13, busy/high pin 13 connected to BS2 pin 11
DO
  B1=B1+1
  SEROUT MP3,84,[$AA,$02,$00,$AC]' PLAY WHATEVER FILE
  DEBUG "SPEAKING ",DEC B1, CR

  PAUSE 5000' WAIT HALF SECOND INTO PLAYING

  SEROUT MP3,84,[$AA,$06,$00,$B0]'NEXT

PP:
  B0=IN11
  IF B0=1 THEN PP' LOOP BACK ON BUSY HIGH

  DEBUG "PAUSE 2 SECONDS",CR
  PAUSE 2000
LOOP

davisgraveyard

Fantastic!  Exactly what I needed. Thanks.   I'll let you know how it turns out.

davisgraveyard

I have the need to test to see if a sound file is done playing. 

The DY-XXXX boards have a command to return which file is playing

  SEROUT TX,T9600,[$AA,$0D,$00,$B7]' Get Playing Sound file index 0 = none > 0 file is playing

it returns  AA 0D 02 XX where XX =  16bit int 0 means no file and > 0 is the file number playing

I need to get the string and parse out the value and just determine if the file is still playing?

using something like this?

  SERIN  RX, T9600, [status]

so I can check it like this

DO
....
LOOP UNTIL (status < 1)





Jeff Haas

Are you just trying to find out when the sound file is done playing?  Or actually get the filename of what's playing?

If you're just trying to find out when the file is done, use the Busy pin.  Look at the thread on the Parallax forum for a picture that shows how to add a resistor.  Here's Erco's BS2 example, for the TEST BUSY PIN section.

The key line below is B0=IN11 - look at INPUT in the Basic Stamp Help file. This sees if pin 11 is active by putting the state into B0.  Then the IF statement checks the value of B0 and loops until it's done.

' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM15}

' DY-SV17F MP3 player
' BS2 PIN 11 TO MP3 BUSY PIN 12 WITH 10K PULLUP TP +5V
' BS2 PIN 15 OUT TO MP3 RX PIN 2
PAUSE 500

SEROUT 15,84,[$AA,$13,$01,$14,$DC]' set volume             dec 20=14 D2   max dec 30=1E DC
PAUSE 100

TESTBUSY:  ' requires 10K resistor between module pins 12 & 13, busy/high pin 13 connected to BS2 pin 11
DO
B1=B1+1
SEROUT 15,84,[$AA,$02,$00,$AC] ' PLAY WHATEVER FILE
DEBUG "SPEAKING ", DEC B1, CR
PAUSE 500 ' WAIT HALF SECOND INTO PLAYING
SEROUT 15,84,[$AA,$06,$00,$B0] 'NEXT
PP:
B0=IN11
IF B0=1 THEN PP ' LOOP BACK ON BUSY HIGH
DEBUG "PAUSE 2 SECONDS",CR
PAUSE 2000
LOOP