User Tools

Site Tools


arduino:rmp3_audio_shield

Rogue rMP3 Audio Shield for Arduino

What is it?

An Arduino Shield for playing music very easily. It supports many audio formats and encoding settings including stereo sound, MP3 encoded with CBR (Constant Bit Rate), or VBR (Variable Bit Rate) up to 48 KHz at 320 Kbps. It also offers a good support for SD cards (FAT16 and FAT32 compatible - 8MB to 32GB and beyond). It does pitch control and tones. The shield can be used via serial interface or with a logic parallel inputs (direct buttons control).

Product page: http://www.roguerobotics.com/products/electronics/rmp3

Documentation: http://www.roguerobotics.com/wikidocs/rmp3/start

Related libraries: (at the moment the support page lists pre Arduino 1.0 library packages). I updated them to works with Arduino 1.0 in the meantime.

RogueMP3 roguemp3_for_1.0_camille.zip
RogueSD roguesd_for_1.0_camille.zip (only needed for fancy/advanced file manipulation on the memory card)

Usage notes

Browse the RogueMP3 methods.

sync() is needed to initialize the module and communication.

Format the the SD card using FAT16 or FAT32, and just to be on the same, name your files without weird characters, whitespace or funky punctuation: audio_001.mp3 is less problematic across OSes than annette's rip of Glósóli.mp3

The default interface is a 9600 bps serial port on pins 6 and 7 of a standard Arduino. The pin selection can be easily changed, as with the serial communication speed. It makes this module very easy to work with any microcontroller that has hardware (or software) serial support, including all Arduinos and event ATtinys. It only needs 2 pins and power supply (Vcc and Ground), so it possible to use with many other shields and/or modules.

If you are using MP3 files, make sure you clean/remove as much metadata in your files. All this information is saved in the header of the mp3 files and can add a significant delay (1-5 seconds) when loading/playing a file. With no metadata, playback starts almost instantaneously. The are numerous free and non-free utilities to edit metadata. I found MP3Tag to be working well on PC, and it's free!

For volume control, note that a value of 0 is maximum volume and 255 is silent (weird I know!) setvolume(byte newvolume) - sets the volume (both left and right to same value)

It is possible to control volume (including fading) independently on the left/right channels, with a bit of code, you can almost have two-channel mixing abilities (background audio, plus another sound coming in/out based on sensor for example).

Simple example

// simple rMP3 playback, starts the song in setup
 
#include <RogueMP3.h>
#include <SoftwareSerial.h>
 
// make sure this file exists in the root folder on the SD card
#define SONG "/song.mp3"
 
SoftwareSerial rmp3_serial(6, 7);
RogueMP3 rmp3(rmp3_serial);
 
void setup()
{
  Serial.begin(9600);
  rmp3_serial.begin(9600);
 
  rmp3.sync();
  Serial.println(rmp3.version());
 
  rmp3.playfile(SONG);
 
 
 
 
}
 
void loop()
{
 
}

Serial Commander example

// sketch expecting various ascii commands over serial to control various audio playback actions
// see code below for actual valid commands/keypreses
// requires serial terminal at 9600 bps
 
#include <RogueMP3.h>
#include <SoftwareSerial.h>
 
SoftwareSerial rmp3_serial(6, 7);
RogueMP3 rmp3(rmp3_serial);
 
void setup()
{
  Serial.begin(9600);
  rmp3_serial.begin(9600);
 
  rmp3.sync();  
  Serial.println(rmp3.version()); // output version of the rMP3 module
 
  rmp3.playfile("/song.mp3"); // load the file
  rmp3.playpause();  // play it
  rmp3.setvolume(25); // set initial volume to 90%
}
 
void loop()
{
 
  if (Serial.available()){
    playbackinfo playinfo;
    playinfo = rmp3.getplaybackinfo();
 
    char c = Serial.read(); // no cleaning done, could be improved
    Serial.write(c); // echo back the character received
 
    if(c == 'p'){
      rmp3.playpause();
    }
 
    if(c == '0'){
      rmp3.stop();
      rmp3.playfile("/song.wav");
    }
 
    if(c == '3'){
      rmp3.stop();
      rmp3.playfile("/song.mp3");
    }
 
    if(c == '1'){
      rmp3.stop();
      rmp3.playfile("/t.english.wav");
    }
 
    if(c == '2'){
      rmp3.stop();
      rmp3.playfile("/u.english.wav");
    }
 
    if(c == 'i'){
      rmp3.fade(0, 1000);
    }
 
    if(c == 'o'){
      rmp3.fade(255, 1000);
    }
 
    if(c == 'l'){
       rmp3.setloop(255); 
    }
 
    if(c == 'j'){
       rmp3.jump(random(0, 200)); 
    }
 
    if(c == 't'){
      Serial.println(playinfo.position);
    }
 
    if(c == 'T'){
      Serial.println(rmp3.gettracklength("/song.mp3"));
    }
  }
}

Camille Moussette 2012/04/18 02:24

arduino/rmp3_audio_shield.txt · Last modified: 2014/11/24 05:27 by rickard