About: Hello, the author of the project is an Application Engineer of Seeed Studio. It's great to share this project with the Hackster maker community. I hope you like Seeed Studio, a hardware enabler for IoT applications, which provides services that enable IoT developers to quickly prototype... More information about Seeed Studio »
Game 【2048】is a single-player sliding block puzzle game by Italian web developer Gabriele Cirulli. 2048 was originally written in JavaScript and CSS during a weekend, and released on March 9, 2014, as free and open-source software subject to the MIT license.
The game's objective is to slide numbered tiles on a grid to combine them to create a tile with the number 2048.
In this project, I rewritten the game 【2048】in Python on Raspberry Pi, and made a little change with it. The numbers in the grid are swapped with a series of words that explain the the process of 【how does an idea become a real product in the market】:
- 2 => Idea
- 4 => Design
- 8 => Make
- 16 => Prototype
- 32 => Seeed
- 64 => Improve
- 128 => Sample
- 256 => Product
- 512 => Promote
- 1024 => Market
- 2048 => Success
There is a camera mounted in front of the game machine, when you win the game, it will take a photo of you and list it on the ranklist.
Besides, to add more fun, I connected the game machine to a Canon SELPHY CP1200 photo printer so it can print out the photo of the winner as a reward.
When you finished this tutorial, you can acquire the following knowledge:
- Be familiar with Raspberry Pi
- Understand python programming using pyside
- The skills of dealing with pictures using Pi Camera
Add TipAsk QuestionCommentDownload
Step 1: What Do We NeedHardware:
- Raspberry Pi 3 Model B
- 10.1 Inch LCD Display - 1366x768
- GrovePi+
- Raspberry Pi Camera Module
- Grove - Thumb Joystick
- Micro SD Card(larger than 4GB)
Structure:
- 3mm wood
- 5mm wood
- 3mm Bamboo plate
- 3mm Studs
- 3mm Nuts
- 3mm Screws
- 2mm Studs
- 2mm Screw
- Screwdriver
Add TipAsk QuestionCommentDownload
Step 2: WiringThe Grove – Thumb Joystick has X and Y axes, each of them are ~10K potentiometers and can control 2D movement by generating analog signals. So we connect this module to an analog port – A0.
Then connect the Pi Camera to the Raspberry Pi just as below picture shows.
Add TipAsk QuestionCommentDownload
Step 3: Setup the GrovePi+The software work occupies the most part of this project. At first we should build the software development environment.
GrovePi is an open source platform for connecting Grove Sensors to the Raspberry Pi. In this project we use GrovePi+ to deal with some real time work, such as the joystick.
You can clickhere to learn how to get started the GrovePi+.
Add TipAsk QuestionCommentDownload
Step 4: Setup the Pi CameraIf you are using the Raspbian distro, it is best for you to install picamera using the system’s package manager: apt. This will ensure that the picamera will always be up-to-date and also easy to remove if you want in the future. It will also make picamera available for all users on the system. To install picamera using apt simply:
$ sudo apt-get update
$ sudo apt-get install python-picamera python3-picamera
Make sure the camera module is not in touch with on any conductive object like the Pi’s USB ports or its GPIO pins. Now, apply power to your Pi. Once booted, start the Raspberry Pi Configuration utility and enable the camera module:
More informationabout Pi Camera you can click here.
Add TipAsk QuestionCommentDownload
Step 5: Setup the Photo Printer3 More Images
In this project, we select a Canon-SELPHY-CP1200-Wireless-Compact-Photo printer, even though the printer supports wireless connect, to ensure the stability of system we use mini USB cable to connect Photo Printer with Raspberry Pi.
Now we should install the printer driver CUPS :
sudo apt-get install cups
More info. about how to install and use cups please clickhere.
Then configure the printer as below picture shows.
- Add printer and select canon SELPHY CP1200.
- Click “Continue”.
- Then, we should set the photo size, in this project we set the media size “Card 54×86mm”.
At last we should install some libraries for pycups.
sudo apt-get install python-dev
sudo apt-get install libcups2-dev
Download the pycups code and install
git clone git://git.fedorahosted.org/git/pycups.git
sudo python setup.py install
Now, we can print a photo to have a test.
Add TipAsk QuestionCommentDownload
Step 6: Install Pyside and Download the Project CodeWe use pyside to develop the game UI.
sudo apt-get install python-pyside
And then download the code from github.
cd ~
git clone <a href="https://github.com/Lee-Kevin/RPI_Photo_booth"> https://github.com/Lee-Kevin/RPI_Photo_booth</a>
Now you can run the seeed.py to see whether the game start normally. And if you’re luckily enough you can see the picture as below shows.
Add TipAsk QuestionCommentDownload
Step 7: Setup the Startup ScriptAt last, we want the game to be lanuched automatically when we boot our Raspberry pi.
The alternative method is to create a configuration file that is unique to the currently logged in user. First you need to edit this text file :
sudo nano ~/.config/lxsession/LXDE/autostart
This file represents a list of commands to be executed when the GUI loads. It is usually blank when you first edit it so just add the applications you need to auto-load:
For this project You can auto-launch th Python scripts by adding the line :
@/usr/bin/python /home/pi/RPI_Photo_booth/seeed.py
This works best in this example the Python script is stored in the home directory of the default Pi user. If another user is logged in they wouldn’t have access to this directory so LXDE may not be able to autoload it.
To save and exit the nano editor press CTRL-X, Y and then ENTER.
Add TipAsk QuestionCommentDownload
Step 8: Laser Cut the PlateDownload the file and laser cut it.
Here we use 3mm wood, 5mm wood and 3mm Bamboo plate.
Attachments📷2048 正式.CDR
Add TipAsk QuestionCommentDownload
Step 9: Install the Screen SectionInstallation screen part, simple structure, fixed with screws
Add TipAsk QuestionCommentDownload
Step 10: Install the HardwareHere, use screws and nuts fix the hardware into wood.
In order to balance the forces behind, you can install several support columns.
Add TipAsk QuestionCommentDownload
Step 11: Install the HousingInstallation of the shell is a bit more difficult, please be patient. You can firstly make sure every screws are fixed without tighten them, so you can adjust the board position and make sure the mount holes are aligned, and then tighten the screws when you find out everthing is OK.
BTW, do not forget to install the back cover and buttons, also, do not forget to lead the camera‘s cable!
Add TipAsk QuestionCommentDownload
Step 12: Install the Camera and Top PanelThe assembly of the camera part is relatively simple, After assembly, insert it into the corresponding hole, fix it. Then secure the top cover with double-sided tape
Add TipAsk QuestionCommentDownload
Step 13: The ResultNow you can use the Grove – Thumb Joystick to play this game. When you get Market(1024), the camera will start and take a photo of yours then print it out, at the same time your photo will be shown on the Ranklist. Enjoy!
Comments