Show Posts
Pages: [1] 2
1  Using Arduino / Audio / Play Pause Skip Buttons rmp3 help on: April 27, 2011, 01:29:24 pm
Hello,

It has been a while since I have last been here, and have my project running. I have made an mp3 player that analyzes music for frequency and causes a motor to vibrate depending on the frequency that is player, so you can "feel" the music. The project can be seen here http://jennifercrossley.com

I am now trying to get the project to the next step, and need to to be able to "play/pause" and skip track. The white buttons on the device are supposed to be doing this. I have what I think to be the correct code, and have it in my code where I think it should be, I just don't know if it is correct, and how I should wire the hardware buttons to my arduino?

Code:
#include <RogueMP3.h>
#include <SoftwareSerial.h>
#include <RogueSD.h>

SoftwareSerial rmp3_s(6, 7);

RogueSD filecommands(rmp3_s);
RogueMP3 rmp3(rmp3_s);

int numberOfSongs;
int lastSong;

#define numberOfBands 6
uint16_t bandfreqs[] = { 300, 1000, 9000 };
//uint8_t outputPin[] = { 2, 3, 4 };
uint8_t outputPin[] = { 11, 12, 13 };

uint16_t numfiles = 0;
 
#define MP3PATH "/mp3/"
// you need to put the two double quotes ("") in the middle below,
// because the Arduino IDE looks for unclosed comments.
#define MP3FILTER "/mp3/""*.mp3"

#define THRESHOLD 1

//#define songname "/gold.mp3"


void checkFrequencies(void)
{
  // prepare for up to 23 bands
  uint8_t v[23];

  rmp3.getspectrumanalyzer(v);

  for (uint8_t i=0; i<numberOfBands; i++)
  {
    if (v[i] > THRESHOLD)
      digitalWrite(outputPin[i], HIGH);
    else
      digitalWrite(outputPin[i], LOW);
  }
}

void playNextSong()
{
  uint8_t i;
  char filename[80];
  char path[96];
  int nextSong = 0;

  if (numberOfSongs > 0)
  {
    // Select our next song randomly
    if (numberOfSongs > 2)
    {
      do
        nextSong = random(numberOfSongs);
      while (nextSong == lastSong);
    }
    else if (numberOfSongs == 2)
    {
      // we only have two songs
      if (lastSong == 0)
        nextSong = 1;
      else
        nextSong = 0;
    }

    // now, get our file name from file list

    filecommands.opendir(MP3PATH);

    for (i = 0; i <= nextSong; i++)
    {
      filecommands.readdir(filename, "*.mp3");
    }

    strcpy(path, MP3PATH);
    strcat(path, "/");
    strcat(path, filename);

    rmp3.playfile(path);

    Serial.print("Playing: ");
    Serial.println(path);

    lastSong = nextSong;
  }
  else
  {
    Serial.println("No files to play.");
  }
}


void setup(void)
{
  Serial.begin(9600);
  Serial.println("Started");

  rmp3_s.begin(9600);

  for (uint8_t i = 0; i < numberOfBands; i++)
    pinMode(outputPin[i], OUTPUT);

  Serial.println("Starting sync");
  rmp3.sync();
  Serial.println("Done sync");
    rmp3.stop();
      filecommands.sync();
}



//void playTrack(void)
//{
//  char mp3path[128];
//
//  numfiles = filecommands.filecount(MP3FILTER);
//
//  Serial.print("MP3 count: ");
//  Serial.println(numfiles, DEC);
//
//  // play a file (random)
//  strcpy(mp3path, MP3PATH);
//  filecommands.entrytofilename(mp3path + strlen(mp3path), 127, MP3FILTER, random(0, numfiles));
//
//  Serial.println(mp3path);
//  rmp3.playfile(mp3path);
//
//  rmp3.setspectrumanalyzer(bandfreqs, 10);
//
//  Serial.println("Playing");
//}

int8_t isPlaying(void)
{
  return (rmp3.getplaybackstatus() == 'P' ? 1 : 0);
}


void loop(void)
{
  //if (!isPlaying())
    //playTrack();

  checkFrequencies();
  uint8_t i;
  char filename[80];
  char path[96];
  int nextSong = 0;
 
  filecommands.opendir(MP3PATH);
{
      filecommands.readdir(filename, "*.mp3");
    }

  strcpy(path, MP3PATH);
  strcat(path, "/");
  strcat(path, "*.mp3");  // we have to do this because the IDE thinks that "/*" needs to be terminated everywhere

  numberOfSongs = filecommands.filecount(path);

  lastSong = -1;
 
  char c;
 // uint8_t i;
  int16_t newtime;

  playbackinfo playinfo;

  char status = 'S';
  uint8_t playing = 1;
  uint8_t volume = 20;
  uint8_t boostOn = false;

  volume = rmp3.getvolume();  // this only gets the left volume
 
  playNextSong();

  while(1)
  {
    while(!Serial.available())
    {
      // we should do fancy stuff like flash lights on our Xmas tree here!
      // got lots of time!
      delay(200);

      status = rmp3.getplaybackstatus();
      playinfo = rmp3.getplaybackinfo();

      if (status == 'S' && playing)
        playNextSong();
    }
   
    // OOH!! got a character!
    c = Serial.read();

    switch(c)
    {
      case 'p':
        // pause
        if(status == 'D')
        {
          // fade in
          rmp3.playpause();
          rmp3.fade(volume, 400);
        }
        else if(status == 'P')
        {
          // fade out
          rmp3.fade(100, 400);
          rmp3.playpause();
        }
        else
        {
          // start playing
          playNextSong();
          playing = 1;
        }
        break;
      case 's':
        rmp3.stop();
        playing = 0;
        break;
      case 'n':
        playNextSong();
        playing = 1;
        break;

      case 'e':
        if(boostOn)
        {
          rmp3.setboost(0);
          boostOn = false;
        }
        else
        {
          rmp3.setboost(8, 6, 7, 3);
          boostOn = true;
        }
        break;
     
      case 'a':
        // jump back 5 seconds
        newtime = playinfo.position - 5;
        if (newtime < 0) newtime = 0;
        rmp3.jump(newtime);
        break;

      case 'd':
        // jump forward 5 seconds
        rmp3.jump(playinfo.position + 5);
        break;
       
      case 'k':
        if(volume < 254) volume++;
        if(status != 'D') rmp3.setvolume(volume);
        break;

      case 'i':
        if(volume > 0) volume--;
        if(status != 'D') rmp3.setvolume(volume);
        break;

    }
  }
}

I have commented out parts that I dont think are necessary, but I am not sure.

Any guidance on how to go from here would be greatly appreciated.

Thank you

Jennifer
2  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 21, 2011, 09:44:10 am
Hi

edit::

Sorry, I have just looked back and seen that I pasted the wrong code, I just pasted yours, oops.

I was using your code as a base for mine.

I think I have got to a point where it should be analysing the code, but I am not sure as to what each part of your original code actually does. I have tried to edit it with the code to play from the folder /mp3/ and the audio is not playing, but have had a version where it did only play my song gold.mp3.

From what I can tell from your code, mine should now be analysing for 3 different bands, and sending it back to the arduino. My problem is now, I am not sure how to change this from the lcd output, to just have a different arduino output turned "on" when each frequency returned.
Code:
#include <SoftwareSerial.h>
#include <RogueMP3.h>
#include <RogueSD.h>

SoftwareSerial rmp3_s(6, 7);
 
RogueMP3 rmp3(rmp3_s);
RogueSD filecommands(rmp3_s);
 
uint16_t bandfreqs[] = {  120,  2000,  20000 };
 
uint16_t numfiles = 0;
 
#define MP3PATH "/mp3/"
// you need to put the two double quotes ("") in the middle below,
// because the Arduino IDE looks for unclosed comments.
#define MP3FILTER "/mp3/""*.mp3"


void doFREQSpec(void)
{
  // prepare for up to 3 bands
  uint8_t v[3];
 
  rmp3.getspectrumanalyzer(v);
 
}

void setup(void)
{
  Serial.begin(9600);
  Serial.println("Started");
  Serial.println("Starting sync");
  rmp3.sync();
  filecommands.sync();
  Serial.println("Done sync");
  
}


void playTrack(void)
{
  char mp3path[128];
 
// ...
 
  rmp3.playfile(mp3path);
 
  rmp3.setspectrumanalyzer(bandfreqs, 10);
 
  Serial.println("Playing");
}

void loop(void)
{
  
}

Currently my code is stuck on the syncing. I will keep trying to get this working with the folder, but as a failsafe, I have it working with a single track.

Is there a specific part of the documentation that I can read, or a direction you can point me in on how to translate this back to an arduino output?

Thanks

Jenny
3  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 19, 2011, 09:53:08 am
Turns out that was the problem.

Its working now. =D Thank you very much.

Away off to read about using the getspectrumanalyser() to get the rmp3 giving the arduino a value, so that an output can be created depending on the value. That sound about right?

Thanks again
4  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 18, 2011, 09:37:18 pm
Is it just those to pins that need to be soldered down? Or am I ok to have all of them soldered to the same pin on the uno board?

I don't have access to my soldering iron at the moment, will be back with it tomorrow. I will double check 6&7 ?and the rest? of the pins, and will let you know how it works from there.

Thank you for your help

Jenny
5  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 18, 2011, 09:20:34 pm
Returns "no" for all of them 2400-115200
6  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 18, 2011, 08:11:25 pm
Very similar. I couldn't get mine with the pins, so I have used my own. But I think I have got the same set up with them


With the usb from the uno going to my laptop.
7  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 18, 2011, 06:45:06 pm
It just hangs at starting mp3. I am correct in having all the pins from the uno jumped to the rmp3? Doing this wont interfere with the two boards talking?

Thank you
8  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 18, 2011, 06:22:12 pm
I am just using this:
Code:
#include <SoftwareSerial.h>

#include <RogueMP3.h>
 
SoftwareSerial rmp3_serial(6, 7);
RogueMP3 rmp3(rmp3_serial);
 
void setup()
{
  Serial.begin(9600);
  rmp3_serial.begin(9600);
 
  rmp3.sync();
 
  rmp3.playfile("/gold.mp3");
}
 
void loop()
{
}

Which seems to be on the rmp3 now, just nothing coming out of the headphones. I still have it plugged into my laptop for power just now.

The serial leds on the uno don't seem to be flashing either. I assume that with that code, the mp3 should just play on loop?

I have the mp3 called gold.mp3 on the root and in a subfoler called /mp3/gold.mp3 on the card. I renamed the file to gold.mp3, so i guess it is called gold.mp3.mp3, and tried it without the extra extension, and still no joy?
9  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 18, 2011, 06:09:59 pm
Hooray,

I finally have got it compiled using version 11 of the new software serial. I exported it to my arduino, but cant hear anything. Not sure why, I have the name of the song correct, and its location on the SD card. I think It may be a connection issue between the uno board and the rmp3
10  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 18, 2011, 05:20:47 pm
I think I was using the NewSoftSerial library. I downloaded it, and pasted it into the /library/ folder at my arduino location. Is that all I had to do?

I have also since tried it without the stream versions, and still the same error.

I have been told that I may have to check the instantiation? I'm not sure what this is, as I only saw it online in relation to the ump3 device.

When attaching my uno to the rmp3, am I correct in just lining up all the pins and attaching? The activity light flashes for a brief moment on the rmp3, then just goes off, and Windows makes the "hardware plugged in" sound, then the removed sound, while the uno is just loop playing the blink programme that I loaded onto it.
11  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 17, 2011, 05:53:25 pm
Just been trying to get it even playing an mp3, and it never compiles. Just gets the same error every time.
Code:
In file included from sketch_jan17a.cpp:1:
C:\Users\Jennifer\Desktop\arduino-0022\libraries\NewSoftSerial/NewSoftSerial.h:32:24: error: SerialBase.h: No such file or directory
In file included from sketch_jan17a.cpp:1:
C:\Users\Jennifer\Desktop\arduino-0022\libraries\NewSoftSerial/NewSoftSerial.h:45: error: expected class-name before '{' token
sketch_jan17a:4: error: no matching function for call to 'RogueMP3::RogueMP3(NewSoftSerial&)'
C:\Users\Jennifer\Desktop\arduino-0022\libraries\RogueMP3/RogueMP3.h:110: note: candidates are: RogueMP3::RogueMP3(Stream&)
C:\Users\Jennifer\Desktop\arduino-0022\libraries\RogueMP3/RogueMP3.h:103: note:                 RogueMP3::RogueMP3(const RogueMP3&)

And I have no idea why it is not working. I have downloaded, and installed the serials library change, and selected the [stream] uno module.

Any ideas what the issue might be?
12  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 17, 2011, 04:28:33 pm
Have just been playing with it a bit, and have got a better grasp of how these things talk to eachother. Will go away and read about the getspectrumanalyser() and see where to go from there.

What I was meaning is that if it is a low frequency, the rmp3 will return a value to the arduino that will activate one output, and if it is a mid range frequency, the rmp3 will return another value to the arduino to trigger a different output.

With the aim of having a different output for a different frequency range.

Thanks
13  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 17, 2011, 02:10:22 pm
I think I am starting to see more how this is going to work now.

On the arduino module, I set it to "tell" the rmp3 to getspectrumanalyser(), which will then return a frequency value to my arduino module, and if it is above a certain frequency will trigger and output to a motor.

Can this be used to trigger an action for groups of different ranges of frequencies, a low frequencies group, medium and high? Rather than just if the frequency goes above a set value?
14  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 16, 2011, 05:32:35 pm
@mowcius Thanks, I already have some code that uses an arduino to analyse an mp3, over usb, when it is all run from an arduino sketch on my laptop. I was going to use the rmp3 to listen to the music on the go, and though I will need to use an arduino module to send the commands over serial then.

The communication between the two should be ok then?

I was going to use the FrequencyEnergy library that comes with the arduino programme, export it to my nano, and where the output display is changing the size of the words, just set the output to set my arduino to set an output to HIGH, to activate a motor.

This should be ok to do, with having the arduino to control the playing of the music on the rmp3, and analysing the mp3 off the sdcard at the same time?

@bhagman As said above, I was going to use the FrequencyEnergy library example that is in the arduino programme. Would using the getspectrumanalyser() method be more useful for my project? Or would doing what I described above be a better method of achieving this?

Thank you very much for your help
Jenny
15  Forum 2005-2010 (read only) / News / Re: * MP3 Shield * - Rogue Robotics rMP3 on: January 16, 2011, 04:12:29 pm
Hey,

Thanks for the reply. From that it seems that I have to use an arduino board. I thought this may be the case.
Will I be able to use any arduino module, and seeing the output bitrates for the music from the rmp3, will I have to use mp3's encoded at a low bitrate so the music can be analysed over the serial port?

Hopefully I can go and start soldering my rmp3 to the nano board, and get my project up and running.

Thanks
Pages: [1] 2