Are you a math aficionado in need of a new desk toy? Then do we have the project for you. With nothing more than an Arduino and a seven-segment LED module, [Cristiano Monteiro] has put together a little gadget that will slowly work its way through the digits of Pi forever…or until you get bored of looking at it and decide to use the parts for something else.
On the hardware side, we really can’t overstate how simple this project is. A common four-digit LED display is connected up to an Arduino Nano, which is then plugged into the computer for power. [Cristiano] is using a breadboard here, but you could just as easily use four female-to-female jumpers to connect the two devices together. We suppose this would be a pretty good project for anyone who’s looking to get some practical experience with PCB design as well.
The real magic is in the software, which [Cristiano] has been kind enough to release under the MIT license. Calculating Pi on such a resource-constrained chip as the ATmega328P is far from ideal, but by porting over a C++ algorithm developed by [Xavier Gourdon] and [Pascal Sebah] for their paper Computation of the n-th Decimal Digit of π with Low Memory he was able to pull it off, albeit slowly.
Now if you’ve got slightly better hardware, say a pair of Xeon processors and 96 GB of RAM, you could calculate Pi out to a few trillion digits for fun, but it wouldn’t look as cool as this little guy blinking away.
10 thoughts on “Simple Arduino Build Lets You Keep An Eye On Pi”
Haha! This is great :)
I tried to do something similar on my Arduino using some code I found off the Internet based on the same paper I think. I wanted to use the time to calculate each single digit as the timing for a “sequencer” and left it running most of the day on Monday playing notes. I found it was good for around 8 hours up to the 600th odd digit, but then it stopped giving me the correct digits after that!
I’m wondering if I overflowed something in the calculation somewhere but haven’t looked further into it. I notice your comment on GitHub about inaccuracies in the 6th calculated digit – could this build up over time and cause the issue I was seeing do you think? I haven’t dug into the actual code myself to see if something like that might compound or not…
Here’s my writeup so far: https://diyelectromusic.wordpress.com/2022/03/14/pi-day-midi-sequencer/ and there was a Twitter thread about it here: https://twitter.com/diyelectromusic/status/1503273927245766656
I’d be very interested in any thoughts! :)
Author here: Yes, I noticed the same. The precision error appear to be cumulative and, over several hours, it will “contaminate” more digits (the algorithm calculates 6 digits from the starting position you specify). My plan is to migrate to Pi Pico since I believe (correct me if I’m wrong, please) it offers a true 64 bit double and for the cool factor (Pi on Pi) :)
The algorithm involved is described at http://numbers.computation.free.fr/Constants/Algorithms/nthdigit.html (to save some folks the effort of clicking through a couple of layers of links).
Author ere: Yes, thank you! Credit where credit is due. I’ve put their site and paper links on both article and Github, but the more we give visibility to his awesome paper the better.
Wasn’t there a program like this running on an HP41? Talk about low memory!
I don’t know how you resisted using a Raspberry Pi for this!
Author here: Actually, planning to migrate to Raspberry Pi since ATmega328P double is 4 bytes only and I believe this is the cause of some imprecision on the last 2-3 digits (the algorithm will calculate 6 digits from the starting position you specify).
Witchcraft. It’s complete numerical witchcraft. Why does the universe work this way?
Need to use Nixie tubes for this…
Several Arduino starter kits come with LED modules, or a 16×2 LCD.
This looks like a fine addition to such starter kits. Bravo!
Please be kind and respectful to help make the comments section excellent. (Comment Policy)