Simple Arduino Build Lets You Keep An Eye On Pi

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

  1. 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! :)

    Kevin

    1. 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) :)

    1. 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).

Leave a Reply to BTCancel 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.