A Pi Calculating Pi For Pi Day

What is it about pi that we humans — at least some of us — find so endlessly fascinating? Maybe that’s just it — it’s endless, an eternal march of digits that tempts us with the thought that if we just calculate one more digit, something interesting will happen. Spoiler alert: it never does.

That doesn’t stop people from trying, of course, especially when “Pi Day” rolls around on March 14 every day  — with apologies to the DD/MM set, of course. This year, [Cristiano Monteiro] commemorated the day with this Pi-based eternal pi calculator. The heart of the build is a Raspberry Pi Pico board, which does double duty thanks to its two cores. One core is devoted to running the pi calculation routine, while the other takes care of updating the seven-segment LED display with the last eight calculated digits. Since the calculation takes increasingly more time the farther into pi it gets, [Cristiano] thoughtfully included a 1-Hz heartbeat indicator, to assure users that the display isn’t frozen; the video below shows how slow the display gets even just a few seconds after starting up, so it’s a welcome addition.

This is actually [Cristiano]’s second go at a Pi Day pi calculator; last year’s effort was a decidedly tactical breadboard build, and only supported a four-digit display. We applaud the upgrades, and if anyone wants to replicate the build, [Cristiano] has posted his code.

12 thoughts on “A Pi Calculating Pi For Pi Day

  1. Arggh, we don’t get to see the first 8 decimal digits… very cool, I was obsessed with pi in high school and once had it memorized to about 100 digits. But that was many brain cells ago.

    1. All you need in general is 3.141592653589793238, as this exceeds the precision of a double (though most libraries give it to you as a constant these days, sometimes with the extra guard bits, as well)

      People looking for patterns and secret messages and the like confuse coincidence with meaning, and don’t understand the difference between the representation of a number, and the properties it brings, and the properties of a the number itself.

    1. I just munged the code to work on a bluepill board–just disable all the setup1() and loop1() stuff.

      He also seems to have left out an easy optimization. The HAS_LONG_LONG wasn’t defines, so it was using emulated float for the modular squaring. Maybe that’s not faster on the little M0 core in the pico, but it made a difference in the M3 core of the bluepill.

      I think I’m going to see how fast other boards run this. It would be cute to see a design of this running on an ESP-01 with a minimal display of some sort.

        1. Glad I could help. :) Cute little project. I’m tempted to build it for a friend (math teacher) on a bluepill or similar board. I’ll have to use some other means of controlling the display since I won’t have a dedicated core to do that work. Fortunately, time IRQs are a thing, so I can just use that.

          If you’re willing to implement enhancements, I was thinking that the digit display speed could be easily determined by looking at how long the last batch of digits took to calculate and just display at 1/8 that speed. Each batch takes a little longer, so that 1/8th may take a little tweaking to make it smooth, but it shouldn’t be too hard to tune that right.

          As a visual assist, I was thinking that the blinking DP ‘sign of life’ could move with the group of 8 digits.

          FWIW, many clocks use a (seconds &0x01) to determine the blinking ‘sign of life’ indicator (flashing colon, etc.). It’s pretty easy logic, too.

  2. Que j aime a faire apprendre un nombre utile aux sages
    Immortel Archimede, artiste ingenieur
    Qui de ton jugement peut priser la valeur
    Pour moi ton probleme eut bien d autres avantages
    Guess what s hides behind these french sentences?

  3. Brings back to memory of the Star Trek episode where the Jack The Ripper entity had invaded the Enterprise computer. Spock asks the computer to calculate the value of Pi to the last digit whereupon the entity starts screaming and flees the computer….. Math can be a weapon 😁

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.