Introduction: TinyQuiz

This is a small single-player quiz game that's built using the flask framework and runs on the Raspberry Pi. I made this as a final project for one of my college courses, namely "Project I" of "New Media and Communication Technologies"

It features a minimalist and simple esthetic, a self-contained unit and some cooling for the Pie, so it wouldn't throttle your gaming experience.

Step 1: Gather the Required Components

Hardware:

Quiz:

  • Raspberry Pi 3 B (example)
  • Breadboard jumper cables of various types (m2m, m2f, f2f) (example)
  • Ethernet cable (example)

Cooling:

  • ds11b20 temperature sensor (example)
  • small 5V fan that can fit the inside of your Pi enclosure (example)
  • BC517 transistor (example)

Software:

  • PuTTY (get it here)
  • Win32DiskImager (get it here)
  • Filezilla (get it here)

Step 2: Set Up the Pie

Download and install the Raspian Jessie image onto your Pi's SD card using Win32DiskImager. Before booting up, change the cmdline.txt by adding ip=169.254.x.x to it. the last two sections can be chose by you.

This will give your Pi an apipa address so you can access it when connected directly with an ethernet cable.

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline ip=169.254.80.73 rootwait

This is what my cmdline.txt looks like, and 169.254.80.73 is the ip I will continue to use during this tutorial.

Plug the sd card into the Pi, plug the pi into your computer's ethernet port and plug the power into the Pi.

Open PuTTY and create an SSL connection using the aforementioned IP address on port 22. Log into the Pi, the default login being "pi" and the default password is "raspberry".

type sudo raspi-config, and in the interface options enable the 1-wire circuit. You can change the password to your liking in the previous menu.

Do not forget to connect your Pi to WiFi. Either do it through the GUI, or edit the wpa_supplicant.conf file.

Using FileZilla, connect to the Pi using the same data as with PuTTY, and drag the project files someplace on the pi. Mine are in sftp://pi@169.254.80.73/home/pi/Projects/tinyQuiz

Now we will need to install mySQL and create the database required for the program. After you're connected to WiFi, type the following commands: (beware, they may take from 10 to 30 minutes)

sudo apt-get update
sudo apt-get upgrade sudo apt-get install mysql-server sudo apt-get install mysql-client (you'll be asked for a password.)
mysql -uroot -p
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password'; GRAND ALL PRIVELEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;
CREATE DATABASE db_quiz quit
sudo apt-get install python3-mysql.connector
mysql -uroot -p --database=db_quiz <home/pi/Projects/tinyQuiz/static/sql/db_quiz_dump.sql


These commands will update your Pi, install the necessary software and create and populate the database using the dump file.

Step 3: Set Up Your Breadboard

Now you need to complete the circuitry for the cooling system and
connect it to the Pi. Simply follow this simple Fritzing schema and you should be fine.

the DC motor in this case is the fan, and the led is necessary to bleed off excess electricity that can remain in the motor.

Step 4: Enclosure

I've made blueprints, but the material is free for your own choosing. I used cardboard and tape because it was easy to work with and cheap.

Download the blueprints from the static/files folder, and either get some thin ply wood cut with a laser cutter, or slice cardboard using the templates.

Put the Pi and breadboard inside the enclosure.

Step 5: Start the Script

Now we need the script to start automatically with the Pi, as well as being able to start/stop it from the PuTTY console.

Connect to PuTTY again, and type the following command:

sudo nano /etc/init.d/tinyQuiz

In this file, you should put the following code:

sleep 10 #neccesary wait-time for mysql to start.

case "$1" in
start) echo "Starting projectNaam" # applicatie latten runnen # hieronder de mappenstructuur opgeven naar je app python3 /home/pi/Projects/tinyQuiz/tinyQuiz.py
python3 /home/pi/Projects/tinyQuiz/cooling.py ;; stop) echo "Stopping tinyQuiz" # kill applicatie killall tinyQuiz.py
killall cooling.py ;; *) echo "Usage: /etc/init.d/projectNaam {start|stop}" exit 1 ;; esac exit 0

save the file.

Now execute the following commands:

sudo chmod 755 /etc/init.d/tinyQuiz
sudo update-rc.d tinyQuiz defaults

this adds this start-up script into the list of things to run on boot-time. If, for some reason, it doesn't work, you can:

sudo /etc/init.d/tinyQuiz start
sudo /etc/init.d/tinyQuiz stop

to manually start and stop the program from the console.

Step 6: Play the Game

This is it. This is the moment we've all been waiting for. Coming from a long day of work, you want to relax and play your favorite game - tinyQuiz!

Get small box, and plug in the power. Within a few moments, you will be able to surf to the pi's localhost and enjoy these amazing graphics.

Go to ip-of-the-pi:5050 (for example, mine is 192.168.1.111:5050)

If you have access to your router, you can give your Pi a static IP so you always know where the game is.

Comments

author
Swansong made it!(author)2017-06-20

That looks like fun :)

About This Instructable

373views

8favorites

Bio: student of NMCT @ Howest
More by elfensky:TinyQuiz
Add instructable to: