0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Arduinoでmp3再生[DFR0534]

0
Last updated at Posted at 2026-02-09

DFR0534というモジュールを使用すると、Arduinoで簡単にmp3を鳴らすことができます。
[113708]MP3ボイスモジュール
DFR0534

DFR0534をPCに接続するとドライブとして認識されるので、
ドライブ>ZHフォルダ内にmp3を格納します。
この際、ファイル名の先頭に01-99までの数字を付ける必要があります。
番号は書きこんだ順で決まるようです。

image.png
Arduinoからはファイル名ではなく、この数字でmp3を呼び出します。

次に、ArduinoのVcc,GndとDFR0534のVcc,Gndをつなぎます。
さらに、ArduinoのSoftwareSerialのTX,RXとDFR0534のTX,RXをつなぎます。

繋いだら下記のライブラリを使用してmp3を制御します。

DFR0534_UART_MP3.hpp
#ifndef DFR0534_UART_MP3_HPP
#define DFR0534_UART_MP3_HPP
#include <SoftwareSerial.h>
// https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/890/DFR0534_Web.pdf
class DFR0534_UART_MP3
{
public:
    DFR0534_UART_MP3(uint8_t rx, uint8_t tx){
        m_pSs = new SoftwareSerial(rx, tx);
    }
    void begin(unsigned long baudrate = 9600)
    {
        m_pSs->begin(baudrate);
    }
    void play(unsigned char Track)
    {
        unsigned char play[6] = {0xAA,0x07,0x02,0x00,Track,Track+0xB3};
        m_pSs->write(play,6);
    }
    
    // 再生状態をチェック
    void CheckPlaybackStatus()
    {
        unsigned char cmd[4] = {0xAA,0x01,0x00,0xAB};
        m_pSs->write(cmd,4);
    }
    
    // 一時停止
    void Pause()
    {
        unsigned char cmd[4] = {0xAA,0x03,0x00,0xAD};
        m_pSs->write(cmd,4);
    }
    
    // 再生再開(一時停止から復帰)
    void Resume()
    {
        unsigned char cmd[4] = {0xAA,0x02,0x00,0xAC};
        m_pSs->write(cmd,4);
    }
    
    // 再生停止
    void Playstop()
    {
        unsigned char cmd[4] = {0xAA,0x04,0x00,0xAE};
        m_pSs->write(cmd,4);
    }
    
    // 前の曲
    void PrevAudio()
    {
        unsigned char cmd[4] = {0xAA,0x05,0x00,0xAF};
        m_pSs->write(cmd,4);
    }
    
    // 次の曲
    void NextAudio()
    {
        unsigned char cmd[4] = {0xAA,0x06,0x00,0xB0};
        m_pSs->write(cmd,4);
    }
    
    // 音量設定 (0-30)
    void VolumeSettings(uint8_t vol)
    {
        if(vol > 30) vol = 30; // 音量の上限を30に制限
        unsigned char cmd[5] = {0xAA,0x13,0x01,vol,0xBE + vol};
        m_pSs->write(cmd,5);
    }
    
private:
    SoftwareSerial* m_pSs;
};
#endif // DFR0534_UART_MP3_HPP
#include <Arduino.h>
#include <SoftwareSerial.h>
#include "DFR0534_UART_MP3.hpp"

DFR0534_UART_MP3 mp3(8, 7); // RX, TX

void setup() {
  delay(1000);
  mp3.begin(9600);
  mp3.VolumeSettings(10); // Set volume to 20
  mp3.play(9); // Play track 9
  delay(3000); // Wait for 3 seconds
  mp3.Pause(); // Pause playback
  delay(2000); // Wait for 2 seconds
  mp3.Resume(); // Play track 9
  delay(2000); // Wait for 2 seconds
  mp3.VolumeSettings(20); // Set volume to max
  mp3.play(9); // Play track 9
  delay(2000); // Wait for 2 seconds
  mp3.PrevAudio(); // Play previous track
  delay(500); // Wait for 2 seconds
  mp3.PrevAudio(); // Play previous track
  delay(500); // Wait for 2 seconds
  mp3.PrevAudio(); // Play previous track
  delay(300); // Wait for 2 seconds
  mp3.NextAudio(); // Play next track
  delay(300); // Wait for 2 seconds
  mp3.NextAudio(); // Play next track
  delay(300); // Wait for 2 seconds
  mp3.NextAudio(); // Play next track
  
}

void loop() {
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?