November 23, 2024, 02:13:24 PM

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.


MDFLY AU5018 MP3 player

Started by Jeff Haas, November 16, 2019, 09:57:30 PM

Previous topic - Next topic

Jeff Haas

Hi Tim,

Here's the code to control the MDFLY AU5018 MP3 player from the Prop-2.  I ported your code from the Prop-1.  Because the Prop-2 is capable of many more speeds of serial connection, it can communicate via serial with this type of board.  So it makes the whole thing much simpler.  One connection from the Prop-2 to the MP3 board and you can give it all kinds of commands, and leave the rest of the Prop-2's pins free to control relays.

Note that MDFly's website doesn't have the entire manual for the Tenda player.  I found a copy on this link:
http://www.echelleinconnue.net/outils/mobio/composants/TDB380_datasheet_V2_(Tenda_Electronics).pdf

I used the info in the section on Serial Mode.

Instructions on how to set this up are in the top of the code.  I tested this on my Prop-2 with the same MP3 player and a relay.

Jeff

' =========================================================================
'
'   File...... music player.bs2
'   Purpose... control MDFLY AU5018
'   Author.... Timothy Ewing
'   E-mail.... time2dive@hawaii.rr.com
'   Started... 14 NOV 2019
'   Updated... 16 NOV 2019
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================
' Discussion from EFX-Tek board:
' http://www.efx-tek.com/php/smf/index.php?topic=2400.0
'
' Ported from Prop-1 (Basic Stamp 1) to Prop-2 (Basic Stamp 2).
' This version uses serial control for the MDFly/Tenda board.
' Connect a servo cable from R/B/W header on Pin 7 to VCC, GND, and Pin 16 on MP3 board.
' Then use pins 17, 18, and GND on the MP3 board for the headphone jack.

' Name the MP3s like this:
' 001 Firstsound.mp3
' 002 Secondsound.mp3
'
' Name the files like this, make a folder on the SD card named 001,
' then copy the MP3s into the folder the SD card.
'
' Then sort the FAT on the SD card using a utility like DriveSort:
' http://www.anerty.net/software/file/DriveSort/?lang=en
' This makes sure the MP3 player sees "001 Firstsound.mp3" as the actual first sound!

' -----[ Program Description ]---------------------------------------------
'   audio board controller
'   input PIR
'   output to MP3 player via serial
'   output lights

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


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

Sio          PIN      15  ' SETUP = out; no ULN
PIR          PIN      14  ' SETUP = DN
MP3          PIN      7   ' Connect to Tenda MP3 board on Pin7 header.
LIGHT1       PIN      1   ' light 1

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

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

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T38K4       CON     45
  #CASE BS2PX
    T2400       CON     1646
    T38K4       CON     84
#ENDSELECT

Open            CON     $8000
Baud            CON     Open + T38K4            ' B/R jumper installed

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

timer           VAR     Word
PIRWarmup       VAR     Byte
WarmupTime      VAR     Byte

WarmupTime = 30  ' This may need to be as long as 60 for a reliable PIR response.  30 = 30 seconds.

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

Reset:

  OUTH = %00000000 : OUTL = %00000000           ' preset IOs
  DIRH = %00000000 : DIRL = %10000010           ' set outputs (1s)

  SEROUT MP3, 188, [239]                        'STOP MP3 module before doing anything

  FOR PIRWarmup = 1 TO WarmupTime               ' Define loop for PIR calibration time
    PAUSE 500                                   ' Wait 0.5 seconds
    DEBUG "."                                   ' Visual feedback in DEBUG window
    PAUSE 500                                   ' Wait 0.5 seconds
  NEXT

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

Startup:

'  light1 = IsOff                               ' light 1 off

  PAUSE 1000
  SEROUT MP3, 188, [01]                        ' Play SFX 1
  PAUSE 1000                                   ' wait
  SEROUT MP3, 188, [239]                       ' Stop playing

  SEROUT MP3, 188, [06]                        ' Play repeat (assumes repeat is named 006 repeat.mp3)
  PAUSE 1000                                   ' pause
  SEROUT MP3, 188, [239]                       ' Stop playing

  PAUSE 4500                                   ' wait 4.5 seconds

Main:
  timer = 0                                     ' reset PIR debounce timer

  DEBUG CR, "Ready", CR

Check_Trigger:

  DO WHILE (timer < 100)                        ' wait for 0.1 sec input
    PAUSE 5                                     ' loop pad
    timer = (timer + 5) * PIR                   ' update timer
  LOOP

  DEBUG CR, "Triggered", CR

  LIGHT1 = IsOn                                ' turn on light

  SEROUT MP3, 188, [02]                        ' Play SFX 2
  PAUSE 4500                                   ' wait
  SEROUT MP3, 188, [239]                       ' Stop playing

  SEROUT MP3, 188, [03]                        ' Play SFX 3
  PAUSE 4500                                   ' wait
  SEROUT MP3, 188, [239]                       ' Stop playing

  LIGHT1 = IsOff                               ' light 1 off

  SEROUT MP3, 188, [01]                        ' Play SFX 1
  PAUSE 1000                                   ' wait
  SEROUT MP3, 188, [239]                       ' Stop playing

  SEROUT MP3, 188, [06]                        ' Play SFX 6 (repeat sound)
  PAUSE 1000                                   ' wait
  SEROUT MP3, 188, [239]                       ' Stop playing

  GOTO Main

time2dive

I am unable to get my AU5018 to work in serial mode. I looked at the audio board from the PDF that you posted. The audio boards are different. I am assuming that the pin out is different. According to your code PO7 is for serial control, red goes to 5vd.c, black goes to ground white goes to ??? I have a header that has gnd, tx, rx and 5vdc. On my audio board it says that the commands must be in hex. Does the Prop2 send hex as a serial output?
Time to learn more programming

Everything works in non serial mode. I was able to convert the code from the Prop1.
thanks for the help

Jeff Haas

That's too bad. If you have a link to a PDF for the board, we can try converting it to serial. The advantage is that it saves a bunch of pins.  But glad to hear it's working.