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”
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.
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.
I built his project last year, but as I don’t have a Pico at hand (still waiting for my Udoo Key…) I’ll give it a pass this year.
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.
You’re right, I forgot to un-comment the long long optimization.
Fixed on Github already and did a benchmark here.
Pi digit 313 (time to calculate):
No long long: 5782 ms
With long long: 1116 ms
Much better now! Thank you for pointing that out!
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.
I hit walls with 8/16/32/64 bit computers and my basic BASIC programming skills.
I could not think of a way to circumvent this as results would crap out at the maximum CPU address limit.
PI is what makes the world go round!
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?
Hint: count the number of letters in each word…
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 😁
Then of course there was MIB with “trust the pie”
Please be kind and respectful to help make the comments section excellent. (Comment Policy)