Wish MP3-TF-16P

Ilya G.

Active Member
Licensed User
Longtime User
Add please this library: https://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299

-1554049997-1207406741.jpg
 

derez

Expert
Licensed User
Longtime User
I've worked on this in the past, here are the results of inline c code :

B4X:
#If C
#include <DFPlayer_Mini_Mp3.h>

void Mp3_set_serial(B4R::Object* o) {
   SoftwareSerial* soft = (SoftwareSerial*)b4r_main::_softserial->getStream()->wrappedStream;
   mp3_set_serial(*soft);
}

void Mp3_send_cmd2(B4R::Object* o) {
mp3_send_cmd(b4r_main::_cmd, b4r_main::_arg);
}

//void Mp3_send_cmd(B4R::Object* o) {
// mp3_send_cmd(b4r_main::_cmd);
//}

void Mp3_set_volume(B4R::Object* o) {
mp3_set_volume(b4r_main::_volume);
}

void Mp3_next(B4R::Object* o) {
mp3_next();
}

void Mp3_prev(B4R::Object* o) {
mp3_prev();
}


void Mp3_sleep(B4R::Object* o) {
mp3_sleep();
}

void Mp3_reset(B4R::Object* o) {
mp3_reset();
}

void Mp3_pause(B4R::Object* o) {
mp3_pause();
}

void Mp3_random_play(B4R::Object* o) {
mp3_random_play();
}

void Mp3_stop(B4R::Object* o) {
mp3_stop();
}

void Mp3_play(B4R::Object* o) {
mp3_play();
}

//void Mp3_play_num(B4R::Object* o) {
// mp3_play(b4r_main::_num);
//}

void Mp3_single_play(B4R::Object* o) {
mp3_single_play(b4r_main::_num);
}

void Mp3_single_loop(B4R::Object* o) {
mp3_single_loop(b4r_main::_state);
}

void Mp3_get_tf_sum(B4R::Object* o) {
mp3_get_tf_sum();
}

void Mp3_get_tf_current(B4R::Object* o) {
mp3_get_tf_current();
}

void Mp3_get_state(B4R::Object* o) {
mp3_get_state();
}

#End If

This is how it is used, from remote :
B4X:
Sub Astream_NewData (Buffer() As Byte)
    Private st As String
    Log(st)
    If Buffer(0) = 0x76 Then  ' "v"
        Private buf(2) As Byte 
        bc.ArrayCopy2(Buffer,1,buf,0,2)
        st = bc.StringFromBytes(buf)
        Log(st)
        Volume = st
        RunNative("Mp3_set_volume", Null)
               
    Else   
        st = bc.StringFromBytes(Buffer)

        Log(st)
       
        Select st
           
            Case "Cont"
                State = False
                RunNative("Mp3_single_loop", Null)
                continuous = True
                Log("cont = ",continuous)
               
            Case  "Next"
                RunNative("Mp3_next", Null)
                play = True
           
            Case  "Prev"
                RunNative("Mp3_prev", Null)
                play = True

               
            Case  "Vol0"
                Volume = 0
                RunNative("Mp3_set_volume", Null)
           
            Case  "Loop"
                    State = True
                    RunNative("Mp3_single_loop", Null)
                    continuous = False
               
            Case  "Playpause"
                If play Then
                    RunNative("Mp3_pause", Null)
                    play = False
                Else
                    RunNative("Mp3_play", Null)
                    play = True
                End If
               
            Case "Random"
                State = False
                RunNative("Mp3_single_loop", Null)
                Delay(1000)
                RunNative("Mp3_random_play", Null)
                play = True
                continuous = False
               
            Case "Stop"
                RunNative("Mp3_stop", Null)
                play = False
                continuous = False
                Delay(1000)
                State = False
                RunNative("Mp3_single_loop", Null)
               
            Case "watch"
               
            Case Else  ' song number
                Arg = st
                Log("song ",Arg)
                Cmd = 0x03
                RunNative("Mp3_send_cmd2", Null)
                play = True
                Delay(1000)
                State = False
                RunNative("Mp3_single_loop", Null)

        End Select
        watchtmr.Enabled = False
        watchtmr.Enabled = True
    End If
   
End Sub
 
Last edited:

derez

Expert
Licensed User
Longtime User
Attached find B4A and B4R applications. the player is operated by connections to pins 3 - rx and 4 - tx (and of course vcc, gnd and the two spk pins), because it is controlled by phone with BT.

player.jpg
 

Attachments

  • playerUNO_BT.zip
    2.7 KB · Views: 373
  • player_b4A_BT.zip
    293.3 KB · Views: 367
Last edited:

derez

Expert
Licensed User
Longtime User
Here's the problem, I tried to run this code on ESP-12e :(
It can work, just feed the player by 5v and use logic converters on the rx tx pins to 3.3v
Also you have to put the song files in the sd card of the player...
This is for Wifi:

B4X:
Private Sub AppStart

   Serial1.Initialize(115200)
   Log("AppStart")


   If wifi.Connect2("xxxxx","xxxxxxxxx") Then  ' change to your wifi
        server.Initialize(55055, "server_NewConnection")
        server.Listen
        Log("Waiting for connection.")
        Log("My ip: ", wifi.LocalIp)
    Else
        Log("Failed to connect to Wifi.")
    End If
    timer1.Initialize("timer1_Tick", 2000)


    Softserial.Initialize(9600,d1.d3,d1.d4) 'in wemos - pins 8 rx,9 tx or any other pair
    Softserial.Listening = False
 
    pstream.Initialize(Softserial.Stream, "pstream_NewData", "pstream_Error")
 
Last edited:

Similar Threads

Top