Pi Calculator Running on a Raspberry Pi Pico in the Shape of a Pie

by Banana_Monster in Circuits > Raspberry Pi

4161 Views, 7 Favorites, 0 Comments

Pi Calculator Running on a Raspberry Pi Pico in the Shape of a Pie

IMG_9071.jpeg

What is it?

This is a pi calculator shaped as a Pie, because why not? When I saw this contest, I knew that this was the project I wanted to make, because it combines all of the different variants of Pi/pie.

The calculator runs on the Raspberry Pi Pico W and is coded so that when you plug it in, the screen will turn on and start calculating pi in real time. It is meant to be a fun project that you can have sitting on your desk slowly calculating pi, to higher and higher decimal places. I have only tested it for at most about an hour or so, but after a while it starts taking a very long to time to get the next digit. I cannot promise that this will work for all Pico boards, or all similar screens, so if you do make this, you may want to test your boards with the files from step two to make sure that your boards fit. If you would like to test the holders for the board, you can test print them with the files from Step two. My brother wrote step ten and did the coding and wiring for this project, because I am hopeless at stuff like that.

Supplies

IMG_8894.jpeg
IMG_8903.jpeg
IMG_8899.jpeg
IMG_8895.jpeg
IMG_9020.jpeg
IMG_9021.jpeg
IMG_9027.jpeg
image3.jpeg
IMG_9038.jpeg
IMG_9039.jpeg
IMG_8892.jpeg
unnamed (1).png
blender-logo-png_seeklogo-20236.png
orca-slicer-logo.png
Thonny_logo.png
  1. Electronics:
  2. 128x64 pixel white OLED screen
  3. Raspberry Pi Pico W (should be flashed with MicroPython)
  4. A data capable Micro-USB cable
  5. Jumper wires X 4
  6. Other supplies:
  7. 16mm long 3M screws
  8. 3M hex nuts
  9. PLA filament (If you are painting your case, then you can use whatever color you want, but if you do not want to, than you should choose a color you actually want the case to be)
  10. Painters tape
  11. Light brown spray paint
  12. Americana Acrylic Sealer/Finisher
  13. Assorted acrylic paints (This would probably work better if you actually had higher quality paints)
  14. Duct tape
  15. Tools and software:
  16. Assorted Paint Brushes
  17. Digital calipers
  18. Screwdriver
  19. A 3D Printer
  20. A relatively powerful computer
  21. TinkerCAD software
  22. Blender software
  23. A slicer software
  24. Thonny IDE software

Measure and Design Your Parts

Overview:

This step is pretty easy, if you just want to 3D print the model, and not have to worry about designing it from scratch, you can skip this step and go straight to step seven. If you do want to design from scratch, then you will want to do this step. If you just want the files from this step, you can download them right below this step. It is really important to get the holes in the right place, as they will be used to mount the different boards into the model later in this Ible.

Measuring your electronics:

For me, I measured the PCBs and the wires with my calibers, and designed it in TinkerCAD. I would:

  1. Measure the parts with the calipers, for the power cord, you don't need to have exact measurements, but for the Raspberry Pi and the screen, you will want exact placement of holes, and exact size of the PCB.

image

image image

  1. After I had gotten a measurement I would use TinkerCAD to design the part. For example, I would measure the hole placement on one of the PCBs, and then I would place cylinders in the model in the right place. Then I might measure the diameter of the hole, and then change the diameter of the cylinders in TinkerCAD. For the screen, I made sure to also measure where the screen was placed on the PCB in relation to the holes, so I would be able to place it correctly in the final case. I didn't end up modeling the Pi Pico myself, instead I ended up using this website. It is not the exact board that I used, but for header and hole placement it is the same, so it works just fine. It isn't an STL, but if you need it to be an STL, I had success using this converter. After I converted it, the file was a little bit corrupted, so I used an online STL repair tool to fix the mesh.

image image image image image

Design Holders for the Raspberry Pi and the Screen

Overview

This step is just designing holders for your different electronics, so that you know how you boards will be held, before you start designing the entire case. This just makes sure that everything fits well, and the wiring works. It also allows you to test the holders separately to make sure they fit, before using up filament to print the entire case, and risk it possibly not working. It is really helpful to have the already designed reference models to take measurements from. If you just want the holders for the parts you can download them below this step.

You can design the holders in many different ways, if you want you could use screws, or you could print little pins that will friction fit into the mounting holes on the PCB. You can also make use of flat sections and make your model slot into the case or have a bar securing it in place.

Screen

  1. For designing the screen holder, I first designed pins before placing them in the correct spots, by using the "align" tool in TinkerCAD. Then I added some blocks to add height to the model, and to make sure that everything fit well, and the I connected everything together with a few two millimeter thick plates.

image image

Raspberry Pi

  1. For the Raspberry Pi, I knew that I wanted it to sit on it's side to save space with all of the wires that have to go in it. I first designed bars that would rest on top of the Pico. Then I designed another plate that would slot into the finished case and rest on top of the bars that go in between the pins on either side, securing the Raspberry Pi in place. I added sides to the model, and cut out the hole for the charging cable. I also added a window that allows you to access the Raspberry Pi, and lets the case accommodate more Pico boards.

image image image

Test Print Your Case

Now it is time for me to test my cases/holders. This step is important, to save time and money printing the entire case and finding out that it may not work, and then you have to do it again. Since I want the Raspberry Pi to be on its side to save space with wiring I will want to test it on its side. It will need supports because I didn't try to do anything fancy to remove the necessity of supports, but it is pretty small so it doesn't matter that much.

Print settings

You can just use pretty normal settings for printing this. Here are the settings I used:

  1. 0.2 mm layer height
  2. 0.4 mm nozzle
  3. organic supports
  4. brim
  5. 80-100 mm/s

image


Printing

Printing these models is pretty simple, you just need to send it over to a 3d printer, and wait for it to finish (if you don't own one, a lot of libraires have 3d printers that are available to the public, or you can find a makerspace near you.) Once mine was finished printing, all I needed to do was take off the brim and test them.

Mine worked pretty well, but even if one didn't work perfectly, it would just be as simple as going back into TinkerCAD and making any necessary changes to the model, before test printing again. After I had printed the models, I decided that the Pi Pico case should attach to the main case through a dovetail, so that you can secure it in place with the bar before you slot it into place.

image image

image image

Design Rough Draft of Your Case Part 1: the Base

Designing

  1. I first took the Raspberry Pi case from the first step, and added a dovetail. I also made a dovetail part that will be cut into the main case.

image image

  1. I then made a simple cylindrical case, by cutting a cylinder into another cylinder, leaving 2mm walls on all sides.

image

  1. I positioned the screen in place, and made a holder, making sure to leave space for the wires.

image image

  1. I sloped the walls of the main case and hollowed it out with a couple of revolve sketches.

image image

  1. I then added a block on the side of the Pi case to make sure that the bar that holds the Pi Pico in will not come out.

image

  1. I also cut a hole in the case for the power cord, making sure that there are a few millimeters of tolerance.

image

  1. I added places for the hex nuts to fit so that the screws can secure the lid to the case.

Design Rough Draft of Your Case Part 2: the Pie Top

Screenshot 2026-04-09 184123.png

Designing

  1. For the top piece of the case I started with a cylinder.

image

  1. I added a dome and flattened it, so it was much thinner.

image image

  1. I drew the lattice top pattern in the sketch tool, and made it bent down so it fit one the pie well. I used the duplicate and repeat tool to complete the lattice, you may need to lower some of the designs to make it fit. There were some gaps in between the lattice, but that is ok, just trust the process.

image

  1. Next I trimmed the edge of the lattice and added a lip to it.

image

  1. I cut out a rectangle for the screen and added a frame to make it look better and cut out the bottom of the lid, so that the screen holder will fit well.

image image

  1. I added a ruffled edge to the pie, it may not look the best right now, but it will look better after it has been sculpted with blender.

image

  1. I added holes for the screws, making sure that the shaft of the screw will fit well with my calipers.

image

Blender Smooth the Top of the Case

Overview

This step isn't strictly necessary, but it should help to make the pie look more rounded, and to remove sharp corners. The file is at the bottom of this step.

  1. The first step to this process was to import my file from the last step into blender.

image

  1. I re-meshed the model, so that it would be able to be smoothed and sculpted.

image

  1. I started smoothing and sculpted the lattice top, making sure to not accidentally smooth the screw holes too much, so that the screw will still fit well.

image

  1. Then I started smoothing and sculpting the crimped edge on the pie. I had to be careful to not actually mess with the bottom of the file, so that it will still be flat, and screw to the bottom case so that to seam is relatively hidden.

image

  1. I had to use the decimate modifier to simplify the mesh, because Instructables limits file size to 25MB, if you are designing everything from scratch, you may not have to worry about file size, though it will take up much more space on your computer and take forever to slice. After using blender, my file was slightly corrupted, so I used this STL repair tool.

image

Slice and Print Your Finished Files

Overview

Now that all of the files have been designed, it is time to print them! All of the files that need to be printed are right below this step, because I didn't want you to have to search through all of the previous steps.

  1. To slice the model, you first need to create a new project, and import all of your files into your slicing software (I used Orca slicer).

image

  1. Once the file are imported, I added two extra beds, and placed the files on the beds. Here are the settings I used:

Settings

  1. 0.2mm layer height for the case Pico case parts and the bottom case, and 0.15mm layer height for the top of the case.
  2. 0.4mm nozzle size
  3. 150mm max print speed
  4. 200mm travel speed
  5. 10% gyroid infill
  6. 220°C print temp
  7. 60°C bed temp
  8. Brim enabled
  9. Paint on support*

image

  1. *For painting supports on the models, I painted on the floating ledge that is on the top case. I also painted a couple of other ledges on the bottom case and the Pi Pico case part A.

image image image

  1. Once the model have been sliced, it is time to send the Gcode to the printer and finally print them! If your printer has problems with bed adhesion, you may want to add glue to the bed to make sure they stick well.

image image image image image image image

Preparing Prints for Spray Painting, and Spray Painting

  1. Before you start spray painting, you will want to cover up any parts of you print that you don't want paint on. On the bottom of the case. I cut out strips of tape, and covered up the dovetail connector, the pins to connect the screen with, and the little hex nut/screw hole things.

image image image

  1. I took the top and bottom case outside. I propped the pieces up on bricks, so that any spray paint that ran down the sides would not make the parts stick to the table.

image image

  1. I started spray painting the top and bottom case pieces. Make sure not to hold the can of spray paint too close, so that the paint doesn't drip

image image

  1. I flipped over the top case piece and gave it a second coat of paint on the other side, I also gave the bottom case a second coat, but I didn't take any photos of it.

image image

Non Spray Paint Painting and Finishing (Optional)

I will not go into a ton of detail on how I painted this, because my process is probably not the easiest or the best way to do this.

  1. I first painted over the pieces with a light brown, I used several layers. After I painted the pieces, I realized that I probably could have skipped the spray paint step if I wanted, but it was too late anyway.

image image

  1. Once the bottom case has been fully painted, it just needs to be sealed.

image

  1. For the top case I put on a coat of a watered down even lighter brown.

image

  1. Once that layer was dry, I added a darker layer, which was also watered down. For the darker paint, I added a bit of red and dark brown to the lighter brown, until I got my desired color. before the darker layer is dry, get a paper towel and dab off the darker paint off of the higher raised up sections, leaving the lower sections dark.

image

  1. Once you are done painting, and are happy with you results, you take take the parts outside and seal all of the paint. Make sure to flip the the top case over and seal the bottom too.

image image


Coding

Screenshot 2026-03-31 172144.png
Screenshot 2026-04-01 192756.png
Screenshot 2026-04-01 192959.png
Screenshot 2026-04-01 194852.png
circuit_image.png

In this step we will write the code and get the pi calculator working.

I used Thonny to write the code because it's simple for beginners, and chose the Nilakantha series for my calculation method because it is simple to write but slow to calculate.

π = 3 + (4 / (2 × 3 × 4)) - (4 / (4 × 5 × 6)) + (4 / (6 × 7 × 8))... (each term = 4 / ((2 + (2x)) × (3 + (2x)) × (4 + (2x))) the signs alternate and x starts at 0)


Download and Precompile Libraries

For libraries, I chose mpy-decimal and ssd1306 and precompiled both.

  1. install mpy-cross:
pip install mpy-cross
  1. run it on your libraries:
mpy-cross PATH_TO_SSD1306.py
mpy-cross PATH_TO_MPY-DECIMAL.py

You should end up with two .mpy files which will start faster than a standard .py file. The compiled versions are attached here.

Writing the code

  1. Setup the Pico in Thonny.
  2. Connect the pico by plugging it into the computer with a data capable usb cable and selecting it in the menu in the lower right corner of Thonny.
  3. image
  4. Make sure that the Interpreter is set to MicroPython in Thonny options(Tools → Options → Interpreter).
  5. image
  6. Upload the libraries to the board.
  7. Make sure you have downloaded the precompiled files or compiled them yourself with the instructions above.
  8. Open the files menu(View → Files) and locate your .mpy files. Right click on them and press "Upload to"
  9. image
  10. Make the code file.
  11. In thonny press the new file button.
  12. Press the save button, choose save to Raspberry Pi Pico, and save it as "main.py" (MicroPython automatically runs main.py"
  13. Write the code.
  14. This is the code that I wrote. It uses the Nilakantha series and shows the calculation live on the oled every ten terms. The code can be downloaded here.
# Pi calculator code using Nilakantha's formula.
# π = 3 + 4 / (2*3*4) - 4 / (4*5*6) + 4 / (6*7*8)...

# Import the machine library for hardware control.
import machine

# Initialize the I2C communication for SDA and SCL on pins 0 and 1 respectively.
i2c = machine.I2C(sda=machine.Pin(0), scl=machine.Pin(1))

# Import the ssd1306 library.
from ssd1306 import SSD1306_I2C

# Initialize the SSD1306_I2C class with width, height, and I2C communication method.
oled = SSD1306_I2C(128, 64, i2c)

# Import the whole mpy_decimal library.
from mpy_decimal import *

# Set the decimal length to 127 digits.
DecimalNumber.set_scale(127)

# Decimal number for the value of pi starting at 3.
pi = DecimalNumber("3")

# Decimal number for each term.
term = DecimalNumber("0")

# Decimal number for the numerator, which stays at 4.
numerator = DecimalNumber("4")

# Decimal number for the denominator.
denominator = DecimalNumber("0")

# Standard integer to count what term it's on
termValue = 0

# The main loop.
while True:

# Calculate the denominator.
denominator = ((2 + (2 * termValue))*(3 + (2 * termValue))*(4 + (2 * termValue)))

# Divide the numerator by the denominator to get the term's value.
term = numerator / denominator

# If the code is on an even term:
if termValue % 2 == 0:

# Add the term to pi.
pi = pi + term

# If the code is on an odd term:
else:

# Subtract the term from pi.
pi = pi - term

# Every ten terms:
if termValue % 10 == 0:

# Turn pi to a string.
pi_str = str(pi)

# Split pi into chunks 16 characters long.
chunks = [pi_str[i:i+16] for i in range(0, len(pi_str), 16)]

# Clear the screen by turning it black.
oled.fill(0)

# For every value in chunks:
for position, line in enumerate(chunks):

# Display that line's text.
oled.text(line, 0, 8 * position, 1)

# Update the screen.
oled.show()

# Add 1 to the term.
termValue = termValue + 1

Code explanation.

Setting up the libraries.

import machine

The machine library is used for I2C communication.

i2c = machine.I2C(sda=machine.Pin(0), scl=machine.Pin(1))

Initialize I2C communication on pins GP0 and GP1.

from ssd1306 import SSD1306_I2C

The ssd1306 library handles communication with the oled module.

oled = SSD1306_I2C(128, 64, i2c)

Setup the ssd1306 library with 128 pixel width and 64 pixel height.

from mpy_decimal import *

The mpy_decimal library is used for storing accurate decimals.

DecimalNumber.set_scale(127)

This sets the decimal library to have 127 decimal places, which is enough to fill the oled.

Add the variables.

pi = DecimalNumber("3")

This makes a decimal variable for pi starting at 3.

term = DecimalNumber("0")

A decimal variable to store each term's value.

numerator = DecimalNumber("4")

A decimal variable that does not change to hold the value of the numerator.

denominator = DecimalNumber("0")

One last decimal variable to hold the value of the denominator.

termValue = 0

An integer used to count what term it is.

The loop.

while True:

This sets up a loop that will run forever.

denominator = ((2 + (2 * termValue))*(3 + (2 * termValue))*(4 + (2 * termValue)))

This calculates the value of the denominator using termValue. ((2 + 2x) × (3 + 2x) × (4 + 2x)

term = numerator / denominator

Calculate the term's value by dividing the numerator by the denominator.

if termValue % 2 == 0:

If the term is an even value (first term = 0).

pi = pi + term

Add the term to pi.

else:

If the term is not an even value.

pi = pi - term

Update the oled.

if termValue % 10 == 0:

This triggers every ten terms.

pi_str = str(pi)

Turn pi into a string so that it can be easily handled for displaying it.

chunks = [pi_str[i:i+16] for i in range(0, len(pi_str), 16)]

This splits the pi string into lines 16 characters long inside of an array called chunks.

led.fill(0)

Clear the oled.

for position, line in enumerate(chunks):

For every line of text inside of chunks.

oled.text(line, 0, 8 * position, 1)

Display the line of text at a position calculated by the array's index.

oled.show()

Update the oled with the new text.

termValue = termValue + 1

Add one to the term.

  1. Upload the code.
  2. Press the green run button and watch pi calculate on your oled!
  3. Save the file.

Wiring

All you need to do for the hardware is to connect the ssd1306 oled module to the Raspberry Pi Pico W.

This is how I connected it:

PICO W-->SSD1306
3V3----->VCC
GND----->GND
GP0----->SDA
GP1----->SCL

Now just upload an example sketch to test that it works.

Assembly

Now you have gotten to the fun part! It is finally time to assemble everything, and make sure it all works.

  1. Push the hex nuts into the holes in the case, you may need to get something like a key to push them all the way in.

image image

  1. Put the Pico into it's case and make sure that the wires are on the correct pins.

image

  1. Push the Pico case rod piece into the main Pico case.
  2. I made a little loop of duct tape to secure the Pico case in, and stuck it to the bottom case.

image image image

  1. Then I slotted the Pico case into the dovetail.

image

  1. The screen can be pushed onto the pins and snap into place. I used more duct to secure the wires in place.

image image

  1. Once all of the electronics are in place you can put the lid on and screw the lid on

image

Final Thoughts

Timelapse-ezgif.com-video-to-gif-converter.gif

I had a really fun time making this project. I hope you enjoyed reading this Instructable as much I did making it. If you have and suggestions, or ideas for this project, please feel free to put them in the comments below.

After I had finished making the calculator, there were a few things that I realized I could of done better, firstly I realized that I could have possible skipped the entire spray painting step if I wanted to, but It did make the other painting steps a lot less time consuming, but if you do make this, you might not need to bother with that step. I also realized the the hex nut slots were a little bit loose, so on a 3d printer with more accuracy than mine, it might rotate too much and not work as well.