Pi Game
After my previous two Instructables, I felt like I was ready to dive deeper into the world of Arduino with a much more advanced project, so I decided to build this! Pi Game is exactly what it sounds like: a game that helps you learn the digits of Pi! You learn them one by one, and your highscore is saved. The rotary encoder is used to select digits, while the screen displays helpful info. For more info on how to play, you can check out Step 9!
Supplies
For some of these items, any model/brand will do the job. But for many, it's important that you buy the linked item, like for the parts that go on the PCB. If you need to buy a specific model/brand of item, there will be an asterisk (*) before that link.
Materials:
-Arduino Nano Every with headers
This is the brain of your project. It controls everything - from the screen to the encoder.
-10x *Cree LED C513A-WSN-CW0Z0151
These are some pretty standard 3.2V LEDs. They'll indicate which number is selected.
-*Alps Alpine EC11E15244G1 (Rotary encoder)
This rotary encoder is pretty cool because it also features a push-button! You'll use it to select numbers.
-10x 100Ω Resistor
These resistors provide a small step down from the Arduino's 3.3V output to the LED's 3.2V input.
This will hold the 4 AA batteries necessary for powering your project.
-*LCD text display (Must have backpack module)
This screen will diplay your progress and other helpful information. The backpack module reduces the required Arduino pins from 16 to 4, making it perfect for the Arduino Nano.
Pretty self-explanatory. Melt this with your soldering iron to connect your components to your PCB.
This cable is used to connect your Arduino to your PC to upload code.
Used to secure various parts of the project in place.
Used to power your project
You'll also need some custom PCBs (details in Step 1) and some 3D printed parts (details in Step 2).
Tools:
Used to melt solder wire and fuse components to your PCB!
-Helping Hands for soldering
These hold your parts in place, making soldering more manageable.
Used to drive the M2 bolts.
-Wire strippers/precision blade
Used to strip the ends of your battery and LCD wires.
These are used to bend the pins on the LCD screen.
-3D printer (ideally multicolor)
Used to print out the housing for the project.
As for code, you can copy it from my GitHub page. There are more details in Step 3.
Custom PCBs
I knew that hand-wiring all of the components in this project would be too cumbersome to make sense, so I opted for custom PCBs! I used PCBWay, and they were great! For me, 5 PCBs was ~$8 with shipping after I applied my $5 welcome coupon. They came in about 2 weeks (I'm in the Midwestern U.S.). Fabrication details are included down at the bottom of this step.
I decided to make the PCB a circle, because, well, Pi! I used EasyEDA for my PCB design. I'd recommend it for beginners - it's easy to learn and there's a web-based version too! Both the web and desktop versions are free to use.
Unfortunately, I can't upload a Gerber (PCB fabrication) file to Instructables, so I'll include a Google Drive link instead. Here it is: Link to Gerber File
PCB fabrication details:
- Layers: 2
- Thickness: 1.6mm
- Silkscreen: White
- Surface finish: HASL with lead
- Material: FR-4 TG150
- Solder mask: Black
- Finished copper: 1oz Cu
3D Printed Parts
Wow! This was for sure my most advanced 3D modeling project yet. I decided to use Onshape, as I knew I would be wanting to add filleted edges to the design. I decided to use M2 and M3 bolts to secure all the removable plates as well as the screen and PCB in place. You don't need threaded inserts for this, you can just screw the bolts into the print. It's printed in 5 parts (main body, battery box cover, screen cover, number circle, dial).
My print settings (Creality Hi Combo, 0.4mm nozzle):
- PLA, 210°C
- 20% Gyroid infill
- Tree supports, Slim, 2mm Z distance
- 0.2mm layer height
- 2 wall loops
- 5 top shell layers
- 3 bottom shell layers
Once the print is done, all you need to do is remove the supports from the battery compartment. They should all come out in one nice piece, provided you used the settings from above.
This model is quite complex, so I won't be providing a full tutorial. However, I wanted to provide brief instructions on the ribbed knob at the top, as knowing how to make one could be helpful in 3D models you want to make in the future.
- Sketch a circle of your desired diameter.
- Figure out how many ribs you want, and divide 360 by that number. Remember this number!
- Press Q and then L to create a construction line. Draw it from the center of the circle to anywhere on the edge. Repeat this step in a different spot.
- Press D for the Dimension tool. Click on one of the lines, and then the other. A measure will show up.
- Double-click on the measure. Enter in the number from Step 2 and press Enter.
- Draw another construction line, in between the two existing ones. It should end outside the circle.
- Press D again, and then click on the new line, and then one of the other lines.
- Replace the measure that pops up with your number from Step 2, divided by 2. Press Enter.
- Press D, click on the new line, and adjust the length until it extends a desirable amount out of the circle.
- Press A to activate the 3-Point Arc tool. Click on the endpoints of the two old lines, followed by the endpoint of the new line.
- In the top toolbar, click on Search and look for Circular Pattern. Click on it, and then click on the arc.
- Adjust the number that pops up to whatever your desired number of ribs is. It defaults to 3.
- Click anywhere outside the circle. You should now have a series of ribs around the shape.
- Exit the sketch, select it, and press Shift+E for Extrude. Adjudt the height to your desired amount, and click on the checkmark.
If you want, add filleted edges by pressing Shift+F and clicking on the top face of the shape. With that, your ribbed knob is complete! Hopefully you can find a use for one in a future design.
Here are all the 3D models you need:
Code
Now that your parts are printed, you need to get the program onto your Arduino. You'll need to download Arduino IDE. After it's installed, download the code from my GitHub page, and import the .ino file into Arduino IDE. Next, plug your Arduino into your PC. Since the Nano Every is a megaAVR board, you don't need to install any extra libraries for the LCD. Once the code is uploaded, select your Arduino Nano from the dropdown menu on the top left, and click Upload!
You could, of course, change the number in the code to anything you like! If you'd rather memorize another irrational number like, for example, the square root of 2, you can just paste in however many digits you want after "const char PI_DIGITS[] PROGMEM".
Battery Box Installation
Installing the battery box is quite simple! Put the batteries in and turn off the switch, then feed the wires through the hole in the bottom, and make sure you orient it so the switch is exposed. Slot the top cover into place so the switch is accesssible through the hole in the cover. Secure the cover with an M2x4 screw.
Screen Installation
To install the screen, first strip the ends of 4 of the Dupont wires that came with the screen. In order for the screen to fit into the enclosure, you need to bend its four headers up 90° and out at about a 45° angle away from the screen. This isn't super hard as long as you're careful about it. After that, plug the non-stripped ends of the Dupont wires from earlier into the four pins on the screen, and feed them through the hole behind where the screen mounts. Pull them through all the way, and slot the screen into place. Once it's in, secure it with three M2x6 screws.
To cover up the screen, slot in the rectangle piece, making sure the slightly thicker side is on top, and secure it with an M2x4 screw on each side. With that, the screen is installed!
Soldering
I would say that soldering is the hardest part of building any circuit project. But don't be worried! It takes some time to get the hang of it. I would recommend soldering the Arduino Nano first, then the rotary encoder, and then the LEDs and the resistors. When soldering the Arduino Nano, try to solder it as high off the PCB as possible. This will make it easy to upload new code via the USB port if you ever want to. A pair of Helping Hands is totally worth it for a project like this, so I would recommend getting some.
If you're using leaded solder, ventilation is important! You could use a fume extractor, but I just have a box fan and a door open to outside.
The key to soldering is patience. If you try to go too fast, you'll likely end up with low-quality joints, so pace yourself as you work. In order to make sure the LEDs/resistors don't fall out while you're soldering, you can bend their legs to make sure they stay in place. Once they're all soldered in, clip off the excess from their legs.
Once all the components are connected, you need to solder on the battery pack and the screen. The pin on the Arduino with the white square is ground, so the black wire should go to the hole adjacent to that pin. The red wire should go to the hole next to it. For the screen, solder each wire into the hole labeled with that wire's corresponding pin on the screen.
Now that your components, screen, and battery pack are soldered on, you're ready to install the PCB!
PCB Installation
Installing the PCB is quite simple. You need to line it up with the four screw holes, and slide it in. There might be a little resistance, but this is OK. After it's in place, secure it with 4 M2x6 screws. Once it's screwed in, try to manage the wires a little to avoid obstructing the LEDs. This will ensure that you'll always be able to clearly see which digit is selected.
Final Assembly
Once the PCB is installed, you're ready to finish assembling! First, take the thin circular piece and line it up so the 5 and 6 are at the top, and the 0 and 1 are at the bottom. Then, secure it in place with 3 M2x4 screws. Once the circular cover is in place, press on the knob. It should be a little difficult to press on, but not insanely hard. You can try turning it to make sure there's not too much friction with the thin piece. Once you've made sure that it's on properly, your Pi Game is officialy done and ready to play!
How to Play
To turn on the device, flip the switch on the bottom. The Arduino will boot up, and prompt you to press 0. Rotate the knob until 0 is lit up, and press it. Once the game starts, it'll tell you the first digit (3). Rotate the knob until 3 is lit, and press to select it. It'll then tell you the second digit (1). This will continue, with the device giving you one digit at a time, and you entering all the previous digits. If you select the wrong digit, the highscore will be updated and the game will restart. The highscore saves even when the device is turned off, so you don't need to worry about it being erased.
Notes/Final Thoughts
Overall, building this was a blast! It was by far my most advanced project yet, and I'm super happy with how everything turned out. I knew from the start that I wanted the selection method to be a clickable dial, but I never knew that some rotary encoders can have a momentary button built-in! This project was my first ever custom PCB, and it was so cool to see the design go from a computer screen to a physical board at my doorstep. I also learned a lot about 3D modeling while designing the parts for this, as getting all the tolerances, thicknesses, and spacings correctly was a serious task with all of the separate components.
After playtesting this for some time, I'm pleased by how fun it is! At first, I was worried the LEDs wouldn't shine through the 3D printed numbers, but luckily, that didn't end up being an issue. It's super satisfying to see the light move around the numbers as you turn the dial. Having the project be battery-powered is also nice, as it makes it super easy to use on the go or outside. At first, I was thinking about making it USB-powered, but the battery pack was totally worth it.
Anyways, hopefully you thought this Instructable was pretty cool, and I hope you consider building your own Pi Game! If you do, post a Make so I can see how it turned out.
Thanks, and happy making! -Severandom :)