แสดงบทความที่มีป้ายกำกับ การใช้งาน แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ การใช้งาน แสดงบทความทั้งหมด

วันศุกร์ที่ 3 กรกฎาคม พ.ศ. 2558

บอร์ดเล่นเพลง mp3 ที่ใช้ชิป VS1053 นี้ค่อยข้างใช้งานได้ง่าย เนื่องจากมีผู้พัฒนา library ให้เรียบร้อยแล้ว การใช้งานนี้ไม่สอนหลักการอะไรมากนะครับ แค่ใช้งานมันได้ก็พอแล้วครับ
หลัก ๆ คำสั่งที่ใช้งานก็จะ เช่น
MP3player.isPlaying()        //  ดูว่าเพลงกำลังเล่นอยู่ไหม
MP3player.setMonoMode(1);    //  1=EnableMono, 0=DisableMono
MP3player.stopTrack();       //  หยุดเล่น
MP3player.pauseMusic();      //  หยุด
MP3player.resumeMusic();     //  เล่นต่อ
MP3player.resumeMusic(2000); //
MP3player.playTrack(ลำดับเพลง);//เล่นเพลง
มีอีกเยอะนะครับ ศึกษาเพิ่มเติมได้ที่
http://mpflaga.github.io/Sparkfun-MP3-Player-Shield-Arduino-Library/class_s_f_e_m_p3_shield.html


ตัวบอร์ดรองรับ 

Features

  • Can play a variety of music formats, support for OGG encoding real-time recording
  • SPI interface, the control signal lines are led out
  • A headphone and stereo output
  • A microphone for recording
  • A line_in input interface
  • Power indicator
  • 3.3V and 2.8V of LDO chip AMS-1117 on board, provides up to 800mA current
  • A single power supply: +5 VDC
  • 12.288 Mhz crystal
  • TF card slot

Decodes formats

  • Ogg Vorbis
  • MP3 = MPEG 1 & 2 audio layer III (CBR+VBR+ABR)
  • MP1 & MP2 = MPEG 1 & 2 audio layers I & II optional
  • MPEG4 / 2 AAC-LC(+PNS), HE-AAC v2 (Level 3) (SBR + PS)
  • WMA4.0/4.1/7/8/9 all profiles (5-384 kbps)
  • FLAC lossless audio with software plugin (upto 24 bits, 48 kHz)
  • WAV (PCM + IMA ADPCM)
  • General MIDI 1 / SP-MIDI format 0

Encodes formats from mic/line

  • Ogg Vorbis with software plugin
  • IMA ADPCM
  • 16-bit PCM

Document


VS1053-sch.jpg
Wring ของบอร์ด กับ arduino uno
ผมลองล่ะ Micro Sd card 4gb ใช้งานได้ 16gb ก็น่าจะได้ไม่ลอง ลองดูนะครับ อิอิอิ
สำหรับตัว library สามารถโหลดได้จากเว็ปนี้เลยนะครับ
http://www.geeetech.com/wiki/index.php/File:MP3-TF.zip

ซึ่งใช้กับ arduino รุ่น 1.0.5 R2 ได้ปกติ คือรุ่น1.0.X ใช้งานได้ครับ
พวกรุ่น 1.5.x มันจะมี error: variable 'bitrate_table' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 PROGMEM uint16_t bitrate_table[15][6] = {
                                     ^
Error compiling.

เหมือน avr-gcc ไม่รองรับอะไรซะอย่างนี่แหละ อย่างรู้เพิ่มเติมลองหาให้อากูดูครับ แหะๆ 

สำหรับโค้ด ก็ตามนี่ครับ 
/**************************************
*
*  Example for Sparkfun MP3 Shield Library
*      By: Bill Porter
*      www.billporter.info
*
*   Function:
*      This sketch listens for commands from a serial terminal (like the Serial Monitor in 
*      the Arduino IDE). If it sees 1-9 it will try to play an MP3 file named track00x.mp3
*      where x is a number from 1 to 9. For eaxmple, pressing 2 will play 'track002.mp3'.
*      A lowe case 's' will stop playing the mp3.
*      'f' will play an MP3 by calling it by it's filename as opposed to a track number. 
*
*      Sketch assumes you have MP3 files with filenames like 
*      "track001.mp3", "track002.mp3", etc on an SD card loaded into the shield. 
*
***************************************/

#include

//Add the SdFat Libraries
#include
#include  

//and the MP3 Shield Library
#include

//create and name the library object
SFEMP3Shield MP3player;
SdFat sd;
SdFile file;

byte temp;
byte result;

char title[30];
char artist[30];
char album[30];


void setup() {

  Serial.begin(115200);
  
   result = sd.begin(SD_SEL, SPI_HALF_SPEED);
  
  //boot up the MP3 Player Shield
  result = MP3player.begin();
  //check result, see readme for error codes.
  if(result != 0) {
    Serial.print("Error code: ");
    Serial.print(result);
    Serial.println(" when trying to start MP3 player");
    }

  Serial.println("Hello");
  Serial.println("Send a number 1-9 to play a track or s to stop playing");
  
}

void loop() {
  
  if(Serial.available()){
    temp = Serial.read();
    
    Serial.print("Received command: ");
    Serial.write(temp);
    Serial.println(" ");
    
    //if s, stop the current track
    if (temp == 's') {
      MP3player.stopTrack();
    }
      
    else if (temp >= '1' && temp <= '9'){
      //convert ascii numbers to real numbers
      temp = temp - 48;
      
      //tell the MP3 Shield to play a track
      result = MP3player.playTrack(temp);
      
      //check result, see readme for error codes.
      if(result != 0) {
        Serial.print("Error code: ");
        Serial.print(result);
        Serial.println(" when trying to play track");
        }
      
      Serial.println("Playing:");
      
      //we can get track info by using the following functions and arguments
      //the functions will extract the requested information, and put it in the array we pass in  
      MP3player.trackTitle((char*)&title);
      MP3player.trackArtist((char*)&artist);
      MP3player.trackAlbum((char*)&album);
      
      //print out the arrays of track information
      Serial.write((byte*)&title, 30);
      Serial.println();
      Serial.print("by:  ");
      Serial.write((byte*)&artist, 30);
      Serial.println();
      Serial.print("Album:  ");
      Serial.write((byte*)&album, 30);
      Serial.println();
      
      }
    
    /* Alterativly, you could call a track by it's file name by using playMP3(filename); 
       But you must stick to 8.1 filenames, only 8 characters long, and 3 for the extension */
    
    else if (temp == 'f') {
      //create a string with the filename
      char trackName[] = "track001.mp3";
//      char trackName[] = "1.mp3";
      
      //tell the MP3 Shield to play that file
      result = MP3player.playMP3(trackName);
      
      //check result, see readme for error codes.
      if(result != 0) {
        Serial.print("Error code: ");
        Serial.print(result);
        Serial.println(" when trying to play track");
        }
      }
      
  }
  
  delay(100);
  
}

ลองเอาไปเล่นดูนะครับ มีติดปัญหาอะไรถามมาได้เลยนะครับ เพื่อช่วยท่านได้หรือป่าว 
ขอบคุณที่อ่านนะครับ บทความเขียนงงนิดหน่อยนะ ดึกๆแล้ว