Category Archives: geeking

Arduino based RFID mp3 player- part 2

So i started on my project of mp3 player a few weeks back.

Libraries

All the libraries i could find were designed for Arduino 1.0.1 and the current is 1.5.

I spent some time trying to make it compile and at some point i had it working, once…

As my setup was using the default settings, arduino was installed in program files, and windows was making it difficult to edit files in there.

I gave up, and went back to Arduino 1.0. I used 1.0.4 instead of 1.0.1 as it should be close enough. With Arduino 1.0, one has to install the USB driver manually as there is no installer, just a zip file.

There are basically two options as far as the library is concerned, listed at http://www.elecfreaks.com/wiki/index.php?title=Freaduino_MP3_Music_Shield.

As the shield is based around the VS1053b, there are probably other libraries that will be compatible like http://www.seeedstudio.com/wiki/Music_Shield or http://learn.adafruit.com/adafruit-vs1053-mp3-aac-ogg-midi-wav-play-and-record-codec-tutorial/simple-audio-player-wiring

One set allows to play all tracks and have control over next, previous track, the other allows to play track by name or randomly.

I tried both and with the 1.0.4 sdk it works reasonably well out of the box.

Hardware

Now i wanted to use the RFID reader at the same time. the mp3 shield is not using the pin 3 on the arduino, however there is no header left to connect to.  I ended up soldering directly on the back of the mp3 shield. I only need 3 wires: ground, +5 V and rx from the rfid reader.

Another option would be to replace the headers on the shield with male/female headers like this: http://www.adafruit.com/products/706 or to use a stackable protoshield like this: http://www.adafruit.com/products/51

 

DSC_4940

Software

For the software side, it’s not yet clear to me how i will handle folders.
For now , i just won’t. the card is formatted in FAT16 format, so i can have 512 entries in the root (using 8.3 format)

I will encode each audio file with nnnnxmm.mp3 with nnnn being the album number and mm the track number, for example 0001×01.mp3
For now i will hard code everything, but the plan is to have a table of content toc.txt which will match the cards id with the album number; for example

2B00B53A0FAB 0001 12 (there are twelve tracks on album 0001 whose id is 2B00B53A0FAB.

first script

//  File MusicPlayWithName.ino
//  Demo code for playing any existing music file on Micro SD card by file name
//  For more details about the product please check http://www.seeedstudio.com/depot/

//  Copyright (c) 2010 seeed technology inc.
//  Author: Icing Chang
//  Version: 1.0
//  Time: Oct 21, 2010
//  Changing records:
//    
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

/**************************Note*******************************************
 To make this demo code run sucessfully, you need to download the fat16lib 
 into your Arduino library at the following address:
http://code.google.com/p/fat16lib/downloads/detail?name=fat16lib20101009.zip&can=2&q=
**************************************************************************/

#include <Arduino.h>
#include <avr/io.h>
#include "config.h"
#include "player.h"
#include "vs10xx.h"

#include <Fat16.h>
#include <Fat16Util.h>
#include "newSDLib.h"

#include <SoftwareSerial.h>

SoftwareSerial RFID = SoftwareSerial(2,3);
char character;
String Card_id;

void setup()
{
  Serial.begin(9600);
  RFID.begin(9600);

  InitSPI();

  InitIOForVs10xx();

  InitIOForKeys();

  InitIOForLEDs();

  Mp3Reset();
  if (!initialSDCard())
    return;

  RED_LED_ON();//light red LED

//  Serial.println("opening toc.txt");

//  if (file.open("toc.txt", O_READ)) {
//  Serial.println("toc opened");

//   int16_t c;
//   String id="";
//   while ((c = file.read()) != ' '){
//    id+=(char)c;
//   }
//   String foldername="";
//   while ((c = file.read()) != '\n'){
//    foldername+=(char)c;
//  }

//  Serial.println(foldername);
//  file.close();
  }

}

void loop()
{ 
  Serial.println("loop!");

  Serial.println("begin play!");
  while(RFID.available() >0){
        character = RFID.read();
        Card_id+=character;
  }
  if (Card_id.length()>10){
    Card_id = Card_id.substring(1,13);
  }
  Serial.println(Card_id);
  if (Card_id.length()>0){
    if (Card_id.equals("2B00B53A0FAB")){
       playFile("0001x01.mp3");
    }else{
       playFile("0002x01.mp3");
    }
    Card_id= "";
  }
 delay(200);
}

It works!

 

Left to do:

-1- figure out how to get it to run outside of usb with serial monitor with a 9 V power supply.
-2-buttons for control volume up and down work, but next/previous track do not when playing by name. however this works when using play all example. i need to see how it’s done so i allow navigation inside an album.
-3- case. i think i will use a 50 blank CD spool case. buttons for volume up/down, track next/previous play/pause and reset will be moved outside the box as well as popwer connector and audio jack.
-4-using folders to store files.

 

Arduino based RFID mp3 player

This is clearly not about baking but a project i am currently working on.

My wife likes CDs. She will not touch an mp3 player, she needs the tactile feel of something.

So i am thinking at making an mp3 player that is activated by something physical. I am thinking at using RFID cards. Either put the rfid cards in the CD case or print the cd cover on the card and keep the cards in a box, instead of the CDs. This could also bo nice for little kids, so they stop scratching my CDs!

So i have settled on an Arduino board. A Arduino uno (rev 4) as i have one already.

I found a box of 100 125 kHz RFID cards (EM4100) on Ebay for $20.

There was also on ebay a reader for about $10 (RDM630) that is super easy to connect to Arduino, basically ground, 5V  and TX. with a small library, i was able to read the RFID number is about 10 minutes. (10 minutes to set up library and run sample program, a read is under a second i think)

Now for the mp3 player, i found a shield based on the VS1053 chip for about $20.

It does mp3 encoding and decoding to a 3.5 mm jack and micro SD reader. It came with no instructions. The shield reads Elecfreaks.com on the back so i went there and found some example but they are based on old SD libraries that don’t seem to support folders and only 8.3 file names. I found an example that could be convinced to work (was designed for the older libraries for the serial port, there was about 10 one-line changes to get it to work.) And i could play mp3 stored on the root of my 4 GB microSD card. I think it was formatted in FAT16. another card that was FAT32 would not be recognized. also the file system is rather crude, addresses file by number and not by name.

So my plan is to keep trying to get the mp3 shield to work with folders, and to be able to play by name.

Maybe i will use folder whose names are the card number to keep the script simple.

On reading the card, i will just need to cd to the folder of the card name and find all mp3s in there and play there.

Future enhancements would be to decode playlists.

On the hardware front, i will need to work on the case, and also find a way to plug both the mp3 shield and the rfid card reader. there are a few ports on the mp3 shield that are not used,  i should be able to use one for the RFID reader. I will need either a proto shield, or solder on the uno or the mp3 shield for the +5v line and ground and TX.