User Tools

Site Tools


courses:intro.prototyping.spring.2012.may15

Rogue rMP3 audio shield for Arduino

As you may remember we have previously used audio in prototyping by using a glitchy external mp3-player called Vmusic2. The limitations and frustrating unreliability have sent me and Camille to look for an alternative and the best one on the market right now is the rMp3 audio-shield that Camille found and summarized here.

For handy accessibility the most common commands are listed here.

rMP3-library

Button example
#include <RogueMP3.h>
#include <SoftwareSerial.h>
 // make sure this file exists in the root folder on the SD card
#define sound1 "/hhm.wav"
 
//Extra serial port for commands
SoftwareSerial rmp3_serial(6, 7);
//Instance of shield object for control
RogueMP3 rmp3(rmp3_serial);
 
//Variable to keep track of button
int button1State = 0;
 
void setup()
{
  pinMode(2, INPUT);
 
  Serial.begin(9600);
  rmp3_serial.begin(9600);
  rmp3.sync();
 
  Serial.println(rmp3.version());
 
}
 
void loop()
{
  button1State = digitalRead(2);
 
  if(button1State == HIGH)
  {
    delay(200);
    rmp3.playfile(sound1);
    Serial.println(button1State);
    button1State = LOW;
   } 
}
Analog example
#include <RogueMP3.h>
#include <SoftwareSerial.h>
// make sure this file exists in the root folder on the SD card
#define sound1 "/YODA.wav"
 
//Extra serial port for commands
SoftwareSerial rmp3_serial(6, 7);
//Instance of shield object for control
RogueMP3 rmp3(rmp3_serial);
 
//Variables for sensor value and player status
int sensorVal;
char playing;
 
void setup()
{
  Serial.begin(9600);
  rmp3_serial.begin(9600);
 
  rmp3.sync();
 
  Serial.println(rmp3.version()); 
}
 
void loop()
{
  //Reading sensor
  sensorVal = analogRead(A0);
  if(sensorVal > 300)
  {
    //Getting player status
    playing = rmp3.getplaybackstatus();   
    if(playing != 'P')
    {
      //Play file
      rmp3.playfile(sound1);
      Serial.println("Playing");
    }
  }
}
courses/intro.prototyping.spring.2012.may15.txt · Last modified: 2012/05/16 19:51 by camille