Ok, so this is the start of the how-to on using a Raspberry Pi computer to add all sorts of functionality to your table hockey, or, in this case, adding a goal horn to my 83′ Chexx.
The raspberry pi is an inexpensive open-source computer that is the size of a credit card. You can order one for about $30. It’s very similar to the Audurino in that it has a GPIO port or General Purpose In/Out port with room for several sensors. Using a simple breadboard I was able to build a small circuit that when closed, sounds a horn (mp3). I’ll keep revising this, here’s what I’ve got so far…
The parts list..
- Raspberry Pi Computer – $30
- Breadboard – $8 http://www.adafruit.com/products/914
- Reed Switches – $4 https://www.sparkfun.com/products/10601
- 10K and 1K resistors – $2 Radio Shack
- Cheap Speakers – $8
- 4GB SD Card – $10
You’ll need to start with a Raspberry Pi. There are 2 versions, the first one is $29 and the newer one with more ram is $39. Either one will do. You’ll need a mini-USB 5V power supply typically found with cell phones. The Raspberry Pi doesn’t come with the power supply or an SD card (which is the boot drive). There are many resources out there to get your Pi up and running. Here’s a great resource for the Pi, http://www.raspberrypi.org/quick-start-guide. I went low end for mine, a 4GB SD card and a cell phone power cord I had laying around. Hopefully you can follow directions and have a bit of a technical background because you have to do some command line linux. Don’t worry, I know zero linux and was able to step thru the tutorials to get mine up and running.
Once the Pi was up and running I wanted to make it a headless, mouseless, keyboardless unit by setting up SSH access. I figured it was going to run in this configuration when installed in the Chexx unit so I went the SSH route so I could just connect from my Mac and do what I needed to do. It’s mostly configured out of the box for SSH, just use Mac Terminal or WinSCP to connect. This also makes editing the Python scripts much easier.
Now that you’ve got your Pi running, find an mp3 of the sound you want to play, in my case, I grabbed several different horns from various Hockey arenas from here… http://www.theawl.com/2011/04/the-nhls-goal-horns-in-order/5. Save the files to your local drive and then use something like WinSCP to copy them over to the Pi. There is a home directory under Root/Home/Pi where I copied my stuff and ran the script from there. The last piece that isn’t included in any of the links is to download an mp3 player for the script to use when it plays the sounds. Type ” sudo apt-get install mpg321 ” and “sudo modprobe snd_bcm2835″ and “sudo amixer cset numid=3 1″ This installs the player and sets the speaker to use the 3.5mm sound output. If you’re using HDMI for sound you’ll have to dig into the amixer settings, I think it’s 3.
The code for the script is very simple. In essence what you’re doing is running a Python script from the command line that simply looks for the reed switch to close by detecting whether GPIO pin #23 is High or Low. Take the following code and put it into a text file and save it as a somename.py file in the same folder where you copied the mp3s, preferably root/home/pi. Simply go File/New/File, name it, paste the code below in and save. Go to the command line and run it as root using sudo python horn.py
|#!/usr/bin/env pythonfrom time import sleep
import RPi.GPIO as GPIOGPIO.setmode(GPIO.BCM)
The last part is building the circuit using the reed switch and the breadboard. The circuit looks like this.
Here’s a picture so you can follow along. Don’t worry about the wire colors, they don’t mean anything as I didn’t follow any conventions. It doesn’t have to look like this but the path does have to flow correctly. The breadboard has rails that run up and down the sides on each side, you can use the positive and negative on one side, both sides, it doesn’t matter just as long as the 3.3V is connected to a positive rail and the GRND is connected to another. The Numbered rows run across the board but are separated down the middle of the board and separated from the rails. You can run them across, up, down, just as long as you follow a path and dont interrupt the circuit between the rows and rails.
Raspberry Pi Circuit
Here is how I took the reed switch from the picture above, strapped 3′ of wire to it and ran it up into the cabinet and attached it to the bottom of the goal housing. It’s attached with hot glue. Eventually the Raspberry Pi will be down in the base sitting by itself.
So, The Pi is running, when you type sudo python horn.py (or whatever you named the piece of code above) the Pi will sit and wait for pin #23 to drop to 0V indicating that the puck has passed close to the reed switch. When it does, the blues.mp3 sound is played. The 12 second delay is for the length of the mp3.
There are a million things you can do with this, eventually I plan to run a new scoreboard with a timer, shots on goal (reading the oh sensors) and random noises and sounds played the entire match. I’ll set the Pi up as a web server and when goals are recorded I’ll send a little php/mysql update to a database. Then I’ll make a webpage that is the scoreboard and use a small 7″ LCD to display the webpage, instant live updating scoreboard. Have fun, ask questions, I’ve worked thru all of this with very little knowledge in the beginning about electronics etc.
The original tutorial I used for sound from a button push is here…