This is a combination of a couple of my previous Instructables as well as some programming that I did in python. I designed it as a way to run all of my games that I make with one file. It combines all of my games into one for a makeshift gaming console. It is really easy to do if you know Python. It can read any python files you put in it's folder and run it, all from a simple 3 button controller. Please vote for this in the Coded Creations contest if you like it.
Step 1: Materials
You will need...
- Raspberry Pi B+(you can probably use other models too but you'll have to adapt the GPIOs for it)
-small breadboard(or large, it just won't be good for the 'handheld' idea...)
-2 flat, tactile push switches
-1 tall push switch
-some way of connecting your wires to the GPIO pins, I used a ribbon cable but female headers work great as well
-flash drive for moving files
Step 2: Constructing the Controller
The controller we will use is from a previous Instructable that I did. Here's the link:
Again, feel free to change the pins if you want, just remember which pins it is that you're using for when you write the code...
Step 3: Getting the Software
This is the easier way to do this, though you can go to steps 4 and 5 instead.
Go onto your pi and enter this command:
git clone https://github.com/slapshot135/PiBox
This will install my repository on github which will download the pibox software and each file that ive uploaded so far. I will try to add files whenever I can, so keep checking for an update! Also, If you can, try making your own games(see step 5) and, if you're successful, send me a message and I will upload your script to the repository.
Step 4: Making the Folder
The program that I wrote is made to run out of the folder PiBox. It helps to keep a lot of the files together and keep the program from picking up files you don't want.
Navigate to the directory /home/pi and simply right click, select 'new folder', and name it PiBox. Now, any files you make for this program, place here. This includes the PiBox script.
Step 5: Adding the Script
I've attatched the script that I wrote in Python that will run the programs that you want. Simply add this to your flash drive and move it to your new folder.
Note: this will not do anything until..
1. You need to download an image from the web, or make one yourself if you want and place that on your pi(choose a taller one, otherwise it will be squished when it gets re-sized), then edit the script below the comment:
##Edit the Image Name Here##
replace '/home/pi/PiBoxBackground.jpg' with the path to your new background
2. You need games, otherwise it will just display your background and do nothing else. These come in the next step and you can move any py files onto a Flashdrive titled PIDRIVE (you can change that in the PiBox Script, just look in the two directories beneath the first 'try' statement at the top and change the /media/PIDRIVE to /media/flashdrivename). The script will automatically load any .py files from that flashdrive into the PiBox Folder as long as there isn't already a script in the folder with that same name. I recently added this feature so that it will make it easier for people to share scripts.
Step 6: Writing Games
Now that you have your files all set, it's time to write the actual games. I've attached a simple game that I wrote that will run so you can test this project out. You can copy this onto a flash drive and put it in the PiBox folder.
To write your own game, open a new python file.
Here are some basics to get you started, you can look at my example to get some of the concepts better:
-You'll need to import RPi.GPIO as GPIO
-set up the pins like I did in my example
-when you need to check if one is pressed, set a variable to GPIO.input(pin#)
-in my example, left is 17, right is 18, and the fire button is 21
-you can use any modules that you like, but I have found that pygame is fairly easy to use
-Set up your screen:
(screen name)=pygame.display.set_mode((width, height))
-Now you have a window that will pop up with the dimensions of width X height
-the close command is pygame.quit()
-for more basics check out this site for a good introduction:
Step 7: Final Touches
Feel free to edit the scripts however you like.
you can also add some of my other projects to it, like an on/off switch or batteries.
I don't have the right tools or materials to make a good case for my project, which is why this is all just breadboards and open raspberry Pis(Though I did add some hot glue sticks to The sides to make it a little more comfortable to hold), but feel free to design your own, and if you do, please share it in the comments
Remember, if you liked this project, please vote for it in the Coded Creations Contest
Participated in the