loading

A couple of weeks ago, I saw this really cool Raspberry Pi based RFID-enabled cassette player. It ran PiMusicbox and the maker created a module to control PiMusicbox via RFID. This would be perfect for my three year old daughter. Ok, as she's clearly not familiar with cassette players, I needed something simpler. She already had a KNG Andrew MP3-player, that plays MP3's from an SD-card and is controlled via touch buttons. For those who are not familiar with this player, it's simply an SD-card based MP3-player with built-in speakers that looks like a robot.

So, the idea was born, an RFID controlled Raspberry Pi based music robot, or short RFID Music Robot (that's how we refer to it at home). My daughter really loves her music robot, when she wants music, she chooses the tag she wants, holds it near the robot and it will play her favourite music!

Although PiMusicBox is a very easy to install music player for the RaspberryPi with many installation guides, I could not find a guide how to make PiMusicBox respond to RFID's. Therefore, I decided to create something similar to the RFID cassette player. As my Python programming skills are around beginner's level area, building a PiMusicbox module was clearly a bridge too far for me.

That it's not that difficult to connect an RFID-reader to a Raspberry Pi, I learned this from another great instructable: https://www.instructables.com/id/Attendance-system-...

My instructable will show how simple it is to create a Python program that plays music triggered by RFID-tags, so you can make one as well!

Step 1: Materials/tools

For this instructable, you'll need the following:

  • KNG Andrew Home Invader
    • Note that you actually only need an amplified speaker to connect to the headphones output
    • So it should work with any amplified speaker with an input that you can connect to the Raspberry Pi
    • For better sound quality, have look at the cool hifi audio DACs
  • Raspberry Pi A+ incl. Wifi Dongle and a micro SD card (4 GB minimum)
    • Note that I needed the smallest Raspberry Pi, so it would fit in the KNG Andrew
    • Any other Raspberry Pi can be used as well
    • Actually, a 'B' might be easier, as you can connect a keyboard and wifi dongle simultaneously (for an A you could use a powered USB-hub of course)
  • Mifare RC522 Card Read Antenna
    • Around $3 on ebay including blank card and key ring tag
  • Extra tags
    • Choose Mifare 13.56MHz tags/tokens/cards
    • You'll need one tag per function / playlist / audiostream / action
      • So, decide for yourself how many you need
      • Currently, I already have 12 tags in use
      • Initially, I figured 5 would be enough
  • Dupont female-female cables
  • Power supply for the Raspberry Pi
    • I used a Micro USB Host Cable Male to USB Female ( < $1 on eBay)
    • A regular Raspberry Pi power supply is also ok, downside is that you most probably have two power supplies, one for the Raspberry Pi and one for the amplified speakers
  • 3.5mm Auxiliary cord male to male
    • To connect Raspberry Pi to the amplified speakers

Tools used:

  • Soldering station
  • Glue gun
  • Drill
  • Screw driver
  • Tape

Step 2: Electronics

The electronics are actually very simple, as there are only four major components:

  • Raspberry Pi
  • MF RC522 reader
  • Power supply
  • Amplified speakers

In the Fritzing diagram, you can see how to connect the Raspberry Pi to the RC522 reader. I connected the two using regular Dupont wires. After making sure all components work as expected (always test the electronics before you put it into a case), I used tape to combine the single headers. This will make it much more easy to reconnect when you glued the components in place.

Step 3: Assembly

The music robot looks quite large on the outside, however, the speakers take up a lot of space. That's why a Raspberry Pi A+ has been used for this build, as it fits perfectly. In the future, I might decide to use the Raspberry Pi for another project, so all connections are made via the regular connectors. The headphones output is connected to the audio input of the KNG Andrew (or any other amplified speaker set). For this, I used a short 3.5mm male-to-male cable and cut off one of the connectors. The wires in the cable are connected to the audio input connector (black is ground, white left channel, red right channel). Note that the tip is the left channel, the middle the right channel and last one is the ground.

A very short micro-USB to USB cable provides power to the Raspberry Pi. With a sharp knife, I cut open the regular USB connector, so I could connect wires to the power pins. As the KNG Andrew is powered via a regular (mini-) USB connector, it was very simple to find a +5V and GND on the internal KNG Andrew PCB.

There was not enough room in the belly of the music robot to simply connect the audio and power connectors. Therefore, two holes at the top should fix this issue (so the rest of the connector/cable ends up in the head of the robot). Using a permanent marker to indicate the exact spots for the holes, made it easier to drill the holes. As I didn't want to make the hole too large, I started with a small drill bit and used larger drill bits until the hole was large enough.

The RFID reader is glued in place with a glue gun. Note that the header is soldered on to the back of the reader. This makes it possible to put the reader the closest to the outside as possible. Then, connect the taped Dupont wires to the reader and the other ends to the Raspberry Pi. Last steps are gluing the Raspberry Pi in place, connect the audio and power connectors and close up the case!

Step 4: Installing the Raspberry Pi

First of all, you need a recent version of Raspbian installed to the Raspberry Pi.

In the raspi config, activate the audio output via headphones and enable the SPI interface (both can be found in the Advanced options menu).

Make sure the Raspberry Pi is connected to the internet. For setting up a wifi connection, please check the following link.

It's always good to be up-to-date, using:

sudo apt-get update

For installing Python modules, the development packages are required:

sudo apt-get install python2.7-dev

For the MFRC522-python interface, SPI-Py has to be downloaded and installed:

git clone https://github.com/lthiery/SPI-Py

Enter the SPI-Py directory and install it via:

sudo python setup.py install

Next up is the MFRC522-python module:

git clone https://github.com/mxgxw/MFRC522-python

Enter the MFRC522-python directory and install it via:

sudo python setup.py install

Finally, as this solution is made around mplayer, you'll need mplayer of course:

sudo apt-get install mplayer

Please check whether mplayer works fine on the Raspberry Pi when it's connected to the speakers.

Step 5: RFID Enabled Player

In the previous step, MFRC522-python was cloned. This resulted in a new folder named MFRC522-python. Put the rfidmp3player.py file into this folder. Make sure the file is executable:

chmod +x rfidmp3player.py

One of my tags makes the robot tell it's IP-address (or the time, or what ever sentence you like). For this, I use festival, a very simple to use text-to-speech program. You can install it on the Raspberry Pi using:

sudo apt-get install festival

This is a good moment to try whether the rfidmp3player script works. For this, mplayer should be in slave-mode. And to be able to control mplayer, a named pipe is required. What the rfidmp3player program does, is write commands to the named pipe. To test the script, this is what you'll need to do:

sudo mkfifo /tmp/mplayer-control
sudo mplayer -slave -input file=/tmp/mplayer-control -idle
sudo ./rfidmp3player.py

Now, when you hold (a Mifare) RFID-tag to the reader, the Python script will show it's card ID. This ID is an array of 5 integers. In the screenshot, you'll notice that the tag I used for my testrun, triggered an audio stream. What a RFID-tag triggers is defined in the rfidconfig.txt, which will be explained in the next step.

As -in my setup- no screen or keyboard is connected to the Raspberry Pi, it's important that rfidmp3player.py is started from startup. Edit /etc/rc.local (don't forget sudo for this) and add the following before the exit 0 statement:

# Create named pipe for mplayer
mkfifo /tmp/mplayer-control

# Start mplayer in slave mode
mplayer -slave -input file=/tmp/mplayer-control -idle &

# Tell host IP
hostname -I | festival --tts # Start Python RFID-reader-mplayer-control script
/home/pi/MFRC522-python/rfidmp3player.py &

The 'hostname -I | festival --tts' statement will read the current IP-address out loud. This helps you in two ways, first, you know the IP-address to connect to and second, you know that the Raspberry Pi is now up-and-running!

Step 6: Rfidconfig.txt

All RFID triggered actions are defined in the rfidconfig.txt file.

Each RFID tag has the following attributes:

[aaa,bbb,ccc,ddd,eee] Unique tag Id
Description:Description, so you know what this tag should trigger
FileUrlFunction:This is either a file (single file or playlist), URL or function (for either mplayer or OS)
ActionType:Either OS, URL, File, Playlist or Function
TagType:This is actually ignored. I simply numbered my tags with a permanent marker and then I entered that number in this attribute.

Example rfidconfig.txt file can be found below.

ActionType: OS
Use OS for triggering an activity on your Raspberry Pi. Please note, that the commands will be run as root, so be careful! Use this action type for letting the robot tell it's IP address, telling the current time or shutting down the Raspberry Pi.

ActionType: File / URL
Simply put the location of a media file or stream. Note that you cannot use relative paths, so include the full path for a file.

ActionType: Playlist
Simply put the location of a playlist. Same as with a file, provide an absolute path. Within the playlist, you can use a relative path.

ActionType: Function
Use this for sending a specific command to mplayer. For all commands, please check https://www.mplayerhq.hu/DOCS/tech/slave.txt
Examples are: pause, pt_step 1 (next song in playlist) and pt_step -1 (previous song in playlist)

Step 7: Enjoy!!!

Now it's time to enjoy your RFID-music player! Initially I just wrote a number on each tag, but that's not very helpful for a three year old. So, I pimped the tags with nice stickers, using a label writer.

You could also crack open a tag and put the actual RFID-antenna and IC into an object, for example a CD case! How cool would it be to just simply hold a CD case to the reader and the music of that CD's starts playing?

As the range of the reader is not that good, I put a sticker with an RFID-logo on the outside of the robot. This is also the only change to the KNG Andrew you can see from the outside. All standard functions still work, so I can play MP3's from an SD card and also use the robot as speakers for phone. This may look like a 'clean hack', which is a good thing. However, when I demo it, not everyone is convinced that the RFID functionality has been added by me... :-)

Ok, at night, you can see the red reader LED through the white plastic.

The best thing is that my daughter loves it and I hope you like it too!

<p>i make the robot like yours, but i can't open playlists. <br>in the &quot;rfidconfig.txt&quot; i put </p><p>[84,21,116,211,122] </p><p>Description: Frozen Soundtrack</p><p>FileUrlFunction: /home/pi/music/playlists/1_2_3_Wir_singen_mit.pls</p><p>ActionType: Playlist</p><p>TagType: Tag_3</p><p>and the raspberry says: </p><p><br>Playing /home/pi/.....mp3. </p><p>File not found: '/home/pi/.....mp3' </p><p>Failed to open /home/pi/.....mp3.</p><p>Can someone help me please</p>
<p>So in Step 4 it says Enter the SPI-Py Dir and install it via Sudo python setup.py.</p><p>But there isn't a file in the dir...</p><p>Any suggestions?</p>
<p>Didn't the git clone command create a folder containing a number of files?</p><p>You can visit the url with a regular browser and download the files manually: https://github.com/lthiery/SPI-Py</p>
<p>Sorrry, my bad it is the git clone https://github.com/mxgxw/MFRC522-python that doesn`t contain a setup.py file.</p>
<p>Thank you for this great post! I guess I should use this table for the RasPi3 GPIO, right? Thanks</p><p>https://github.com/mxgxw/MFRC522-python#pins</p>
<p>Hey there, thanks for a great instructable... just setting up a system including elements of yours... struggling with mplayer though...when setting up the slave mode, it complains about not being able to open two files: .mplayer/input.conf in my home directory and /etc/mplayer/input.conf. Any ideas? </p><p>I am running Jessie (Raspbian 8.0) on my Pi so when I installed mplayer it automatically installed mplayer2 - should not make a difference I hope but just in case. </p><p>Thank you and best regards,</p><p>Tim</p>
<p>me again... I discovered that mplayer has been discontinued. Hence I am now using VLC for my purposes... have fun building everyone! </p>
Hi, I actually have the same problem with the mplayer. Could you help me getting the vlc player to work? What did you change in your software setup? Thanks so far
Hi there. I finally solved the mplayer problem by compiling an old version - the 1.1 mplayer. The codec and program dependencies where horrible and the compilation time on the RaspberryPi is almost endless (approximately 5 hours per run). But now everything works! If anyone needs help just send me a pm and I can give advice. Regards, Markus
<p>Hi there, I am planning to publish my setup as an instructable as well... but not sure when I will get around to it. So a bit of help here to get you started: you have to get the python VLC Library and stick the files vlc.py and vlc.pyc into the same directory as your program (https://pypi.python.org/pypi/python-vlc/1.1.2). Then you need to call VLC instead of sending commands to mplayer. Important commands are: </p><blockquote>import vlc # import the library<br>player.stop() # use this to stop a file being played (player needs to <br> # be initialised once first with the next command)<br>player=vlc.MediaPlayer(&quot;file:///home/pi/example.mp3&quot;) <br> # tell the player which file... you need to call this once <br> # before calling player.xxx() to initialise the variable<br>player.play() # play the song you assigned to the player earlier. <br></blockquote><p>Please send me a personal message with your email address if you would like me to send you my python program. </p><p>I hope this helps. Good luck!</p>
<p>Just simple and cool idea.</p>
<p>Hi, nice tutorial! The KNG Andrew Home Invader is sweet, do you think a Raspberry Pi B would also fit in that case? I would like to use 2 USB ports.</p><p>Thanks for the tutorial! :-)</p>
<p>That's is a good question! I opened my robot and tried it for you. I'll make a picture of it, but I think it could work! You'll need to remove some plastic, but that should not be a problem.</p>
<p>I quickly made this account to send you to this link which does about what you want:</p><p>http://jasperproject.github.io/</p>
<p>It looks like it'll fit perfectly! You'll need to remove some plastic near the GPIO-pins, as I tried to show in a close-up photo. Please share your project, as I'm curious what you'll be doing with the second USB-port!</p>
<p>Hi, thanks for trying and for the fast answer! :-) I'm dreaming of a voice-controlled multi-room-system, so I can say &quot;Hey Jarvis, please play some radio&quot; or &quot;... some rock music&quot;. :-)) Therefore I would need one USB port for WiFi dongle and one port for a microphone. I think I will do it, but it will take some time. And I will use your suggested case and the Raspberry Pi B, that's perfect. :-)</p>
<p>Cool! All 3-year-olds must be jealous of your daughter ;-)<br><br>It is a very nice project - it looks like you just bought it like this. Nicely done! Looking forward to your other project(s).</p>
<p>Thank you! My other projects, well, working on it. :-)</p>
Well Done! Nobody will believe this! <br>Congrats on your first ible
<p>Thank you! It was fun making it and it is even more fun sharing it!</p>
<p>This one is one of the greatest giy projects out there!! </p>
<p>Thanks! You should make one yourself and have fun with it!</p>
<p>Cool project</p>
<p>Thanks!</p>
Amazing!
<p>This is so cool. Very nicely done!</p><p>Regarding this being a "clean hack," I think the biggest compliment you can get is that people don't believe you did it! Congrats on a great first instructable too, I hope you'll share many more of your projects here!</p>
Tnx! I have another instructable coming up, that is almost finished (ok, the project is, not the instructable). Apparently, having kids really triggers cool ideas for new stuff to play and interact with!

About This Instructable

18,259views

199favorites

License:

More by roaldh:Raspberry Pi based RFID Music Robot 
Add instructable to: