I wanted to make a fun game that could be used to see how many digits of Pi can be memorized. This is the game I came up with using a Raspberry Pi Zero W, 16x2 LCD with an i2c backpack and a 4x3 keypad.
The enclosureTo hold all the parts together nicely I designed an enclosure in Autodesk Fusion 360. I then milled it out on my Shapeoko. You could 3D print it also or just use a cardboard box.
Wiring it upThe keypad has 7 wires that will wire up to the GPIO pins.
Keypad to Raspberry Pi
- 1 to GPIO 14 (pin 08)
- 2 to GPIO 15 (pin 10)
- 3 to GPIO 23 (pin 16)
- 4 to GPIO 24 (pin 18)
- 5 to GPIO 8 (pin 24)
- 6 to GPIO 27 (pin 13)
- 7 to GPIO 22 (pin 15)
To connect the LCD Display with i2c Backpack we need to use a logic level converter since its 5v and the Pi prefers 3.3V, I followed this guide here.
I used a Pi Zero W so I could easily ssh in to it and modify the code. But if you have a non-wireless Pi zero that will work also.
I loaded a clean image on an sd card, enabled SSH, enable i2c and configured my wireless information.
For interfacing with the keypad we will use pad4pi which can be installed by running this command:
sudo pip install pad4pi
We will then create a directory for our program:
mkdir countpi
Then put the pi.py, pivalue.ini, and I2C_LCD_driver.py files in that folder.
We also then want to set it up to run the program at boot up automatically. The Pi foundation has some info on how to do it here but I had issues with there guide and did it a tad different.
To edit the rc.local file type:
sudo nano /etc/rc.local
Then scroll down to the bottom and put this in before exit 0:
cd /home/pi/countpi/
python pi.py &
cd ..
Then press ctrl+x and say yes to saving. Now reboot the Pi and you should see it start automatically.
How to playTo power it I used a USB cable powered from my computer. When the Pi boots up the screen should say "let's count to Pi". You can then start entering the digits of Pi, we skip the decimal though.
Once the first row is filled it will go to the 2nd row.
If at any time you enter the wrong number, it will say "game over" and tell you your score.
If you do get a game over you can start a new game by starting to enter Pi again, it will clear the screen and start again. If you make it all the way to the end of the 2nd row you will win the game and see this message.
You can then start a new game same as you would if you lost.
FinalHere's a video of it in action. As you can see, I have quite a few numbers to still memorize.
Thanks for looking over my project. If I didn't explain a part well, just leave me a comment and I will try to help out.
I am quite happy with how this project came out and have a few other ideas using these components in this form. I also think a buzzer would go well with this project.
Comments