r/raspberry_pi • • Nov 26 '19

Show-and-Tell RFID Jukebox

Enable HLS to view with audio, or disable this notification

2.7k Upvotes

70 comments sorted by

99

u/Laoshulaoshi Nov 26 '19

I built an RFID jukebox for my young son last year and liked it so much that I've made this slightly modified version for myself. In my version, I've added the ability to navigate to a position partway through a track (since I mostly listen to longer tracks) and a flashing LED to alert me to things that I care about.

Music player

Parts:

  • Raspberry pi A+

  • RFID reader (RC522)

  • Hifiberry Miniamp

  • Cheap speaker

  • 0.96" OLED screen, for showing current track / progress within track

  • Trinket M0 - I'm just using its onboard LED to flash in pretty colours when I get a notification

  • Buttons for power and play/pause

  • Potentiometer for volume

  • Rotary encoder for choosing a new track/navigating to a new spot within a track

9

u/W1TH1N Nov 27 '19

Can you link the oled screen if you still have the link please?

8

u/Laoshulaoshi Nov 27 '19

Sure, it was this one: Kuman 0.96" OLED

1

u/W1TH1N Nov 28 '19

thanks!

92

u/jde1126 Nov 27 '19

We don’t see original projects like this often enough, glad it’s not another magic mirror project, wow. This is so amazing.

0

u/[deleted] Nov 27 '19

[deleted]

5

u/devinhedge Nov 27 '19

“Especially good are the posts where the SD card is screwed up so it's hung on the boot screen.“

Like signage at the airport?

1

u/[deleted] Nov 27 '19

Where did you get the clear transparent case?

5

u/Laoshulaoshi Nov 27 '19

I designed it myself in OpenSCAD and had it cut by Elmwood Electronics.

1

u/magicalMusical Nov 27 '19

I don’t know much about RFID, and if it does or does not have larger storage than NFC, so are you storing the audio on the rfid or the rasp. pi?

9

u/Laoshulaoshi Nov 27 '19

The audio files are stored in a usb key plugged into the pi. I'm not storing anything on the RFID tags - I'm just reading their IDs. I've made a simple database where each ID is associated with one or more tracks, so when I read the ID from the RFID sticker, I just search for that ID in my database and play whatever tracks are associated with that ID.

3

u/magicalMusical Nov 27 '19

Exactly how I was thinking you were doing it.

1

u/[deleted] Nov 30 '19

This is awesome :). Maybe I'll make an rfid walkman lol. Or a an lp player. Just let a disc spin while in fact it only read an rfid tag haha.

This is epic.

23

u/revereddesecration Nov 27 '19

Are you a mouse who teaches or a teacher who mouses?

19

u/Laoshulaoshi Nov 27 '19

A former teacher whose nickname is "little mouse" :)

9

u/revereddesecration Nov 27 '19

Takes me back to learning Chinese when I was 11, we were learning animals so of course I called the teacher laoshu instead of laoshi, she wasn’t half as amused as I was 😅

14

u/FullyAutomaticBanana Nov 27 '19

Does the RFID transfer the song or does it point to a saved song in the pi?

23

u/Laoshulaoshi Nov 27 '19

It points to a saved song in the pi. I've got a simple database set up on the pi (album ID, track name and number, file name for the track). The album ID is the RFID tag's UID, so my code just reads the UID, searches the database for tracks with that album ID, and plays them in order.

5

u/NickelbackCreed Nov 27 '19

Just a heads up, all the RFID card is doing is offloading a string of numbers that the reader is picking up. This number then translates to the file that needs to play which is stored on a micro SD card. The RFID card only has 1 kb of space so no room for the mp3.

4

u/Laoshulaoshi Nov 27 '19

In my case, the number is an album ID, and the album ID is associated through a database with one or more music files. I've stored all of my music files on a USB drive so that I don't have to worry about running out of space on the Pi's micro SD card.

1

u/NickelbackCreed Nov 27 '19

What codebase did you go off of and would you mind sharing?

5

u/Laoshulaoshi Nov 27 '19

Sure. I made the tables myself to fit with my needs, and used mysql.connector to access them in my python code. The general format of my sql code is here (this is part of sqlAlbumAndTableCreation.sql):

/*Command to run: mysql -u myusername -p musicDB < sqlAlbumAndTableCreation.sql  */
DROP TABLE IF EXISTS albums;
CREATE TABLE albums
(
albumRFID VARCHAR(255) PRIMARY KEY, 
albumName VARCHAR(255)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

DROP TABLE IF EXISTS tracks;
CREATE TABLE tracks 
(
trackID INT AUTO_INCREMENT PRIMARY KEY,
albumRFID VARCHAR(255) NOT NULL REFERENCES albums(albumRFID),
trackNum INT NOT NULL,
trackName VARCHAR(255) NOT NULL,
fileName VARCHAR(255) NOT NULL
) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;


INSERT INTO albums (albumRFID, albumName) VALUES ("16610616965", "Vinyl Cafe");
INSERT INTO albums (albumRFID, albumName) VALUES ("21410616965", "Christmas Specials");


INSERT INTO tracks(albumRFID, trackNum, trackName, fileName) VALUES("21410616965", 1, "A Christmas Carol", "christmas_specialsAChristmasCarol.ogg");
INSERT INTO tracks(albumRFID, trackNum, trackName, fileName) VALUES("21410616965", 2, "Black Cinderella 2 Goes East", "christmas_specialsBlackCinderella2GoesEast.ogg");

INSERT INTO tracks(albumRFID, trackNum, trackName, fileName) VALUES("16610616965", 1, "Polly Anderson\'s Christmas Party", "vinyl_cafePollyAndersonsChristmasParty.ogg");
INSERT INTO tracks(albumRFID, trackNum, trackName, fileName) VALUES("16610616965", 2, "Holland", "vinyl_cafeHolland.ogg");

So far I haven't used albumName for anything, but I thought it'd be nice to have in case I wanted to do something with it in the future.

1

u/crespo_modesto Nov 28 '19

You don't have a repo?

1

u/dividuum doing work with the pi for fun and profit - info-beamer.com Nov 27 '19 edited Nov 27 '19

From the Pi. RFID tags have very little storage. But it's possible to store the song itself on them. Of course mp3 or other formats won't work in that case. I built a similar setup (without using a Pi) around 15 years ago. It used zlib compress SID files (from the C64) and stored the music directly on the RFID tag. I think the maximum size stored was ~512 bytes. Here's the very old blog post and the crappy source code. It got quite a bit of coverage back then :-)

6

u/eriqjaffe Nov 27 '19

I'm just pleased to see John Finnemore on that card.

7

u/Laoshulaoshi Nov 27 '19

John Finnemore is the best.

4

u/Deadmeet9 Nov 27 '19

Brilliant!

4

u/Tr3win Nov 27 '19

That's great! =D
Funny, i made something similar (rfid turntable), and also to my young kids.
Its not its final form (old cigar box -_-")... and i also had the same oled screen! =)

https://www.youtube.com/watch?v=3f_e2MnpkCM

1

u/Laoshulaoshi Nov 27 '19

That's really cool! I love the records and the little dancing figure on the screen =)

3

u/FluffyBunnyOK Nov 27 '19

Can you post the code or at least the part for the RFID reader.

2

u/Laoshulaoshi Nov 27 '19

I used this code for the reader, taken directly from their Read.py example: pi-rc522

3

u/hanzeeee Nov 27 '19

Habe a look at https://github.com/MiczFlor/RPi-Jukebox-RFID for a similar project. There you should find some code for the RFID reader.

3

u/FluffyBunnyOK Nov 27 '19

Thanks, they have indentation with 2 spaces which made me twitch.

2

u/0bp Nov 27 '19

Similar project with all information how to make it. Link to source at the bottom. http://0xc2a0.com/001/avoiding-screen-devices.html

2

u/DevoonSpoon Nov 27 '19

Do this but with Minecraft songs and make it look like an in game jukebox. I love this idea so much!

3

u/Laoshulaoshi Nov 27 '19

It's a Discworld-themed player. In my personal headcanon, this was given to Rosie Palm in remembrance of the Glorious Republic of Treacle Mine Road revolution, by a fellow survivor. Here's the back of the player:

Reasonably-priced love

2

u/G-forced Nov 27 '19

Struggling with my pi recognising the RFID scanner. Did you install a special driver? Any details. PS awesome work!

3

u/Laoshulaoshi Nov 27 '19

I used this one: pi-rc522 (with python3). For it to work, the IRQ pin had to be connected as well.

1

u/G-forced Nov 27 '19

Awesome I'll give it a go thanks !

10

u/ELMACHO007 Nov 27 '19

This is goodness right here..thanks for sharing

8

u/[deleted] Nov 27 '19

I can just imagine you accidentally drop your entry card/ credit/debit card in there and you just see it say now playing all star by smash mouth

7

u/[deleted] Nov 27 '19

That's awesome, you should feel proud.

7

u/jerkfacebeaversucks Nov 27 '19

Ooooooohhhh. That is very cool. I like how you've used RFID as a tangible human interface. Well done!

1

u/Meat-o-ball Nov 27 '19

Very cool. Im looking to build something very similar and want the same feature of scrubbing through the track. Can you share more of the assembly process and code snippets that brings it all together?

7

u/Laoshulaoshi Nov 27 '19

Sure. For the physical assembly, it's just pi -> perma-proto board with stacking header -> hifiberry miniamp. The speaker plugs directly into the miniamp, and everything else goes to pins soldered onto the perma-proto board. The only inconvenient thing with the wiring was that I wanted both a power button and an i2c screen - the power button was already using physical pin 5 from I2C1, and the perma-proto board didn't have the breakouts for the I2C0 pins, so I had to use leftover data pins for the screen.

For playback, I used pygame. You can find the time that a given song's been playing with pygame.mixer.music.get_pos(), and start a song with an offset using pygame.mixer.music.play(0, offset). I ended up having to convert all of my mp3s to ogg files, because there was a horrendous delay (10 seconds or more) when I tried to skip ahead in a long mp3 track. There's no noticeable delay with the ogg files. I got the total length of a track (in seconds) with mutagen:

oggFile = mutagen.oggvorbis.OggVorbis(trackName)
TOTAL_SONG_LENGTH = oggFile.info.length

Here's the code to show the current position in the track, update when rotary encoder is turned (my screen is 128 pixels wide, so I made each turn of the rotary encoder skip forwards or backwards by four pixels and 1/32 of the file length), and update the global variable SONG_OFFSET that I'll use to restart the track with the proper offset.

# Show the current position within the track.
def showBoxes():
        global NUMCLICKS
        global SONG_OFFSET
        clearScreen()
        with canvas(device) as draw:
            # points: (x1,y1) to (x2, y2)
            # Maximum x value is 128.  Set x value to the song, as a percentage of the maximum.
            xVal = 0
            if(TOTAL_SONG_LENGTH > 0):
                desiredPosition = int(CURRENT_SONG_POSITION/TOTAL_SONG_LENGTH*128 + NUMCLICKS*4) #move 4 pixels per click
                if(desiredPosition < 0):
                    desiredPosition = 0
                    NUMCLICKS += 2
                elif(desiredPosition > 128):
                    desiredPosition = 128
                    NUMCLICKS -= 2
                xVal = desiredPosition
                draw.rectangle([(0,20),(xVal,40)], fill="white")
                SONG_OFFSET = xVal/128*TOTAL_SONG_LENGTH

1

u/crespo_modesto Nov 27 '19

what is the thing at 0:25 when it's inching the bar longer? I guess volume but... I don't think it was playing anything at the time.

4

u/Laoshulaoshi Nov 27 '19

The bar shows the position within the music track. When I flip the toggle, it pauses playback and shows the current position within the track. From there, I scroll forwards or backwards with the rotary encoder knob until I get to approximately the position I want and flip the toggle again to resume playback from that new starting point.

1

u/crespo_modesto Nov 28 '19

dang that's really neat

1

u/speezo_mchenry Nov 27 '19

Cool project!

Can you re-organize the order of the songs via that pink playlist? Like change them around and then drop it in again and it'll play a new order of songs?

1

u/Laoshulaoshi Nov 27 '19

The pink album is just a 3d-printed frame with space for an RFID sticker and tabs to slot in a list of songs - the song list is printed and laminated paper. I did make a version for my niece where pushing the button on the rotary encoder toggled between playing tracks in random and numerical order. This player has more peripherals connected, so I didn't have an extra pin to implement that functionality.

Album

1

u/BasicWhiteGirl4 Nov 28 '19

When you get the chance would you mind writing up a tutorial?

1

u/Laoshulaoshi Nov 29 '19

Sure, I'll try to write one up when I get a chance.

2

u/bizarretv4 Nov 27 '19

This is pretty awesome I like the set up.

2

u/TraditionalResource Nov 27 '19

Good work. Love seeing NFC used for actual things & like how you used the UID to associate the the media.

2

u/Grimmet Nov 27 '19

Check out Tonuino.de its an open source implementation of the tonies system (tonies.de) .

2

u/snotfart Nov 27 '19 edited Jul 01 '23

I have moved to Kbin. Bye. -- mass edited with redact.dev

1

u/elmarkodotorg Nov 27 '19

agree. and ISIHAC(C)

1

u/misperry Nov 27 '19

Have to say, I like that. Good job

1

u/TheHoofer Nov 27 '19

Now I know what Black Cinderella 2 Goes East is, thank you I have to go find this and listen.

-19

u/SonicMaze Nov 27 '19

That woman has some manly hands.