Sieve of Eratosthenes


Up until now I’ve done a lot of software-only projects on my own (clearly, given that I write software for a living) and electronics projects in groups, but I hadn’t yet done an entire arduino-based electronics project on my own from start to finish.

My little sister is finishing up her graduate degree in mathematics education this year, aiming to teach high school maths, and I wanted to give her something besides just a grocery store gift card for her birthday. So I decided to make an arduino-based demonstration of the Sieve of Eratosthenes, the prime number derivation sieve, that she can set on her desk and show her students.

Essentially what happens is that you have a square 2D array (in this case, let’s say of booleans), with each value originally set to true. Starting from 2, for every number that’s true, go through and set all multiples of that number to false. When you reach the end of the (outer) loop, all primes are true (and 1, which is not a prime, is true too, but it makes the array look prettier) and all composite numbers are false.

So first I bought myself an LED matrix and an 8-digit LED display driver (MAX7219) and soldered that all together:

And popped the LED matrix on:

I hooked it up to my arduino and ran some simple test code to make it run numbers (the original intention for the driver):

Figured out how to address each LED individually:

Then got my wee arduino nano involved and got it breadboarded:

And wrote up the algorithm and got that going:

Soldered the whole thing to some stripboard:

Which meant I was in business.  So it was time to move to making an enclosure for it.  I sketched something up in FreeCAD (with 5 major revisions):

And started printing on the Ultimaker.  The first print got aborted partway through, which ended up not being a big deal, because I forgot to include space for the power cord.:

The second print:

Didn’t work out because I’d not made the case deep enough to accommodate the LED matrix, which bumps up above the board quite a bit.  The next print went wrong and was aborted:

And finally, I got a good print:

A quick lid in Draftsight:

And cut it out on the CNC router (thanks, Pocky!).  It was sanded and flame-polished (thanks, Hybrid!):

And then I hot-glued the board to the tabs and screwed the lid on, resulting in the final project:

So the note along with my sister’s birthday present sends her to this URL, so that she can see how her present was made.

Happy birthday, Furball!


About darkmoonsinger