上位に戻る ESP32で、MP3-TF-16P 使ってみる 初版2025/4/15

だいぶ以前に、アマゾンで、mp3プレイヤー MP3-TF-16Pを購入しました Arudinoで使うつもりでしたが、届かなかったので
返金してもらったのですが、1ケ月くらい経ってからひょっこり届きました もうArudinoは、音声なしで作ってしまったので
ずっとおねんねしてたものです
いざ、使ってみると、なにかとうまくいかず 悪戦苦闘ス 

  1. ESP32 DFPplay miniのライブラリでうごかん!

    2021年に購入 DFPlay対応と書いてありました

    んんんDFP Player miniのチップMH2024K-24SSと同じなので動くはず 
    制御コマンド載ってるので、制御コマンドで試そうかと思ったのですが、ネットで調べると、互換モデルの場合動かないようで、
    互換モデル用のライブラリがありました IDEのライブラリの管理には出て来ないので、手動で設置します

    GitHub - enjoyneering/DFPlayer: Small and fast Arduino library for DFPlayer Mini MP3 Player


  2. なんか再生したけど、エラーステータスが返ってくる
    再生コマンドで再生しだすけど、ステータスエラーだし、音量制御できない 再生トラックも指定できない なんじゃこれ・・・・。
    MP3-TF-16Pのモデルではなく、他のモデルのものを試したところ、DFPLAYER_HW_247Aに設定したところ、正常になりました


    /***************************************************************************************************/
    /*
       This is an Arduino sketch for DFPlayer Mini MP3 module

       written by : enjoyneering
       source code: https://github.com/enjoyneering/DFPlayer

       DFPlayer Mini features:
       - 3.2v..5.0v, typical 4.2v
       - 15mA without flash drive, typical 24mA
       - 24-bit DAC with 90dB output dynamic range and SNR over 85dB
       - micro SD-card, up to 32GB (FAT16, FAT32)
       - USB-Disk up to 32GB (FAT16, FAT32)
       - supports mp3 sampling rate 8KHz, 11.025KHz, 12KHz, 16KHz, 22.05KHz, 24KHz, 32KHz, 44.1KHz, 48KHz
       - supports up to 100 folders, each folder can be assigned to 001..255 songs
       - built-in 3W mono amplifier, NS8002 AB-Class with standby function
       - UART to communicate, 9600bps (parity:none, data bits:8, stop bits:1, flow control:none)

       NOTE:
       - if you hear a loud noise, add a 1K resistor in series with DFPlayer TX pin
       - move the jumper from right to left to automatically switch the amplifier to standby

       Frameworks & Libraries:
       ESP8266 Core      -  https://github.com/esp8266/Arduino
       EspSoftwareSerial -  https://github.com/plerup/espsoftwareserial


       GNU GPL license, all text above must be included in any redistribution,
       see link for details  - https://www.gnu.org/licenses/licenses.html
    */
    /***************************************************************************************************/

    #include <SoftwareSerial.h>
    #include <DFPlayer.h>


    #define MP3_RX_PIN              14    //GPI14/D2 to DFPlayer Mini TX
    #define MP3_TX_PIN              13    //GPI13/D1 to DFPlayer Mini RX
    #define MP3_SERIAL_SPEED        9600  //DFPlayer Mini suport only 9600-baud
    #define MP3_SERIAL_BUFFER_SIZE  32    //software serial buffer size in bytes, to send 8-bytes you need 11-bytes buffer (start byte+8-data bytes+parity-byte+stop-byte=11-bytes)
    #define MP3_SERIAL_TIMEOUT      350   //average DFPlayer response timeout 200msec..300msec for YX5200/AAxxxx chip & 350msec..500msec for GD3200B/MH2024K chip


    SoftwareSerial mp3Serial;
    DFPlayer       mp3;


    /**************************************************************************/
    /*
        setup()

        Main setup

        NOTE:
        - moduleType:
          - DFPLAYER_MINI:
            - DFPlayer Mini module
            - MP3-TF-16P module
            - FN-M16P module
            - YX5200 chip
            - YX5300 chip
            - JL AAxxxx chip
          - DFPLAYER_FN_X10P:
            - FN-M10P module
            - FN-S10P module
            - FN6100 chip
          - DFPLAYER_HW_247A:
            - HW-247A module
            - GD3200B chip
          - DFPLAYER_NO_CHECKSUM:
            - no checksum calculation (not recomended for MCU without external
              crystal oscillator)
    */
    /**************************************************************************/
    void setup()
    {
      Serial.begin(115200);

      mp3Serial.begin(MP3_SERIAL_SPEED, SWSERIAL_8N1, MP3_RX_PIN, MP3_TX_PIN, false, MP3_SERIAL_BUFFER_SIZE, 0); //false=signal not inverted, 0=ISR/RX buffer size (shared with serial TX buffer)
      mp3.begin(mp3Serial, MP3_SERIAL_TIMEOUT, DFPLAYER_HW_247A, false); //"DFPLAYER_MINI" see NOTE, false=no response from module after the command
      //mp3.stop();                             //if player was runing during ESP8266 reboot
      //mp3.reset();                            //reset all setting to default
      //mp3.setSource(2);                       //1=USB-Disk, 2=TF-Card, 3=Aux, 4=Sleep, 5=NOR Flash
      //mp3.setEQ(0);                           //0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass
      mp3.setVolume(8);                      //0..30, module persists volume on power failure
     // mp3.sleep();                            //inter sleep mode, 24mA
     // mp3.wakeup(2);                          //exit sleep mode & initialize source 1=USB-Disk, 2=TF-Card, 3=Aux, 5=NOR Flash
     // mp3Serial.enableRx(true);               //enable interrupts on RX-pin for better response detection, less overhead than mp3Serial.listen()
      Serial.println(mp3.getStatus());        //0=stop, 1=playing, 2=pause, 3=sleep or standby, 4=communication error, 5=unknown state
      Serial.println(mp3.getVolume());        //0..30
      //Serial.println(mp3.getCommandStatus()); //1=module busy, 2=module sleep, 3=request not fully received, 4=checksum not match
                                              //5=requested folder/track out of range, 6=requested folder/track not found
                                              //7=advert available while track is playing, 8=SD card not found, 9=???, 10=module sleep
                                              //11=OK command accepted, 12=OK playback completed, 13=OK module ready after reboot
     // mp3Serial.enableRx(false);              //disable interrupts on RX-pin, less overhead than mp3Serial.listen()
    }

    int pno=1;

    void loop()
    {
    //mp3.playTrack(pno);     //play track #1, don’t copy 0003.mp3 and then 0001.mp3, because 0003.mp3 will be played firts
    //mp3.playMP3Folder(1); //1=track, folder name must be "mp3" or "MP3" & files in folder must start with 4 decimal digits with leading zeros
    mp3.playFolder(1, pno); //1=folder/2=track, folder name must be 01..99 & files in folder must start with 3 decimal digits with leading zeros

      delay(20000);         //play for 30 seconds
     
      mp3.pause();
    //Serial.println(mp3.getVolume());
      delay(5000);
      pno++;        //pause for 10 seconds
      Serial.println(pno);
    }




  3. 再生ファイルの指定がうまくいかない
    ルートフォルダに入れる場合は、 トラックの順番かと思い、トラック番号を記載してみたが、まったく意味なし 凡例には、0003.mp3は、
    最初に再生されるの注意事項のみ 次が、mp3フォルダを作ってその中に、4デシマル(10進数4桁)だって
    今回、毎正時用の音声データと、アラーム用の音声データがあるので、フォルダで分けて音声ファイルを入れました
    フォルダの名前は、01〜99 その中に3デシマルなので、001.mp3〜999.mp3 てな感じで入れたのだが
    02フォルダの再生が、001.mp3しか再生しない 再生しないファイルを指定すると、01フォルダの003.mp3が再生される
    再生しない002.mp3を001に 001を002に書き換えると、001 002も再生される んんん SDカードが悪いのか
    以降全ファイル名を書き換えてなんとか全て再生するようにはなった・・・・。
    うええ 不安定 あんまり触りたくないねえ

    音源.zip






    以上間違い等ありましたら、以下ご意見箱にお願いします

   

    ご意見箱