Guess That Song Game
Turn your living room into a real life game show and have fun playing with your family and friends! Prepare some mp3 files to play and try to score the most amount of points with an automatic game app on the raspberry Pi. See who has the most musical knowledge between songs of today and yesteryear.
Note, Printed copy in this month's catalogue has incorrectly mentioned SD cards and LCD screens which were present on version 0.1 of this project. This project now requires a TV or monitor connected to the raspberry Pi and assumes that you have audio output present.
Bill of Materials
|1||XC9002||Case for rPi|
|8||PS0132||Stereo Sockets (4 on base, 1 per controller)|
|4||HB6015||Jiffy boxes for controllers|
|4*||SP0662||Red Arcade button ( Use multiple colours if desired, you need 1 per controller)|
|4||WA7009||3.5mm Stereo male-male lead, 3m different lengths if required.|
|1||ZT2110||PNP transistor BC327|
|1||RR0596||10k Resistor pack|
|1||RR0582||2.7k Resistor pack|
This is the main circuit understanding for the project, you can see that there are two signals on the left hand side which are Input/Output (per controller) followed by a resistor/transistor network, then to the connector which is copied over onto the controller side. Pin 3 of the 3.5mm connector is the signal in, that will get connected to ground when the button is pressed. Pin 2 of the connector is the transistor network that feeds the LED of the controller the 5v from the supply.
The GPIO of the raspberry Pi can only give out 3v3 signals, with not a lot of current. This is unfortunate as the LEDs in the arcade button are designed to be used with 12V (but 5V seems to work fine) and lighting up all 4 controllers at once will most likely ask for too much power from the raspberry Pi, so we have used a PNP transistor and a voltage divider circuit here to act as a switch, so that the power comes from the 5V rail ( USB power supply) rather than the internal logic chips in the rPi.
We won't go too far into transistors here, as they're a subject in and of themselves, with plenty of better material out there. but for the time being we can suffice with some basic information:
With our set up, we use a voltage divider between the 5V rail and the 3v3 GPIO output. When the GPIO gives a
HIGH reading, (3.3v) the voltage over the resistors in the divider is 1.7v, which splits according to the voltage divider:
When the GPIO is
LOW, the voltage divider has 5V on one side and 0V on the other, so the full 5V is being divided:
This project has two main parts, the main unit and the controllers (four of them)
The Controller is a relatively simple set up, you are connecting the arcade button's switch and LED to the socket connector for the cable to connect to.
Pin 1 is the ground connection, with pin 2 being the +5V coming in, and pin 3 is the switch connection back to the main unit.
If you want, you can solder the connections and make sure that the unit works before assembling it into a case.
COM- for "Common")
NOpin of the switch (middle pin of the 3, should be marked "NO") to Pin 3 of the socket connector, and connect
COMto Pin 1.
You should now have something that looks like this:
With the case as chosen, I wasn't able to fit the thread screw onto it while it is still in the case, so I went without the screw and used some super-glue instead.
Drill out the hole and place the switch housing in. you'd probably want to use super glue up around where the green is in the picture. There is a little bit of overhang but it's not a big concern
One controller finished, 3 more to go
Main unit assembly
Here is where the tricky part is. you're going to make 4x of the same part for each of the controllers, and there's not a lot of room in the case, but it is doable.
If you want to provide your own case, feel free to do so and use the schematic above. These instructions below are to get it fitting into the tiny XC9002 case, but if you have more room to play you won't have to be so tight.
Scroll down further for the finished look if you want to start with the end in mind.
Notice that there is a resistor between the collector and the base pin. This can be confusing below, but look at the diagrams and pinouts to ensure that you have the connections right, especially if you have never played around with transistors before.
Note, in my prototype, I used 1k and 4k7 valued resistors. you will find that the values are fairly similar for voltage dividing purposes.
Clip the offshoots of the twist and keep them aside for later.
Recall the pinout of the transistors:
Note, this isn't the same for every transistor, but most of them should be similar
Looking at the face of the transistor, left to right, you have the collector, base, and then emitter.
The red in this diagram highlights how the emitter pin was bent before clipping off the excess
That is now 1 single unit. Do 3 more times.
Fitting to housing
It is a tight fit, but entirely possible to fit the 4 socket connectors as well as the circuitry into the tiny XC9002 case.
First step is to drill out the spaces from the front-grill. Here we've marked the places to drill (in red):
Make sure you're looking at the correct side of the front grill. you'll notice there is a little notch where they give space so you can pull out the SD card of the assembled unit.
With the rightmost hole, I have marked (in orange) an alternative position, which would make for closing the case easier, however the circuitry will be closer to the HDMI socket and so you will have to isolate and make sure that the circuits do not touch by using electrical tape or similar.
Drill out the holes, then attach the 4 socket units:
Here, we have also attached a small hook to each of the pin 1 of the socket connectors as I attached them, so that we can bridge these connections later. these were from the small resistor leads that we clipped back when we attached the two resistors together.
Finally, connect all the Pin 1 leads together, and all the collector leads together, so you get something that looks like the following:
You now have finished your front grill assembly.Cut up some female jumper leads or similar so that you can connect to the rPi GPIO header connector.
The end of each resistor lead is the output to the LED for the controllers, and the unconnected Pin 3 of each socket adapter is the input from the switch. Using some heat shrink at this point is also a good idea as it keeps things mechanically secure and electrically isolated.
Our final unit looks something like this, with heat-shrink attached:
This is our pin-out, you can deviate from this if you want, but you'll have to change the code in
#set these to the GPIO pins, in order of player 1,2,3,4:
button_pins = [21,9,10,11] #Input button pins
led_pins = [26,19,13,6] #Output LED pins
the idea would be, if the led and buttons are in the form of
the zip function will bring it to:
players = list(zip([LED(l) for l in led_pins],
[Button(b) for b in button_pins]))
Making it fit in the case
The only final issue now is getting the whole thing in the case. Unfortunately, with having 4 controller ports, the final port is blocking one of the support beams holding down the case. Use a pair of side-cutters and trim down the beam so that it's almost as flush as the case.
At this point you will be able to try and fit the case together, first by putting the rPi in the base, and sitting the front-grill in on top. Connect the header pins to where you want them, and sit the roof of the case on top. you should be able to screw in the 3 remaining supports and depending on how neat everything is, you should have a pretty neat little unit.
The code is entirely on github with a setup script.
You can easily download and install it by using:
git clone http://github.com/duinotech/Guess-That-Song-Game
The code should have a number of comments for you to look at and try to understand, we are using 4 main libraries here:
pygame- to provide us with audio output
appJar- easy GUI interface
gpiozero- interface to the rPi GPIO
eyeD3- MP3 file tag reading.
the setup script will install these for you and make an icon on the desktop.
MCof the night will have to have a keyboard to press enter or space at certain points of the game
To use the app, run the icon on the desktop, you will then be presented with a startup screen.
Here you can set the folder of where your music files are, which it will then play from.
Each black screen will guide you and ask you what's playing, one of the players must use the controller to pause the music (their controller will light up) and they have their moment to speak, otherwise they can give up (long press on controller) or the
MC can hit
enter to show the song on the screen, which the player will get a point or not if they get it correct or not.
Finally, after all songs have played through or the
escape - the score screen will show with a log history of who got what correct.
PILlibrary to display images on
appJarguis, maybe an idea would be to show the album art aswel.
MCwhich operates on a different controller layout.