Pi on a Pi for Pi Day

Calculating Pi on a Pi

Here’s a quick and dirty post for Pi Day which uses Python code by David Bau (http://davidbau.com/archives/2010/03/14/python_pipy_spigot.html) to compute pi to an arbitrary number of digits. The code implements a “spigot algorithm” developed by Jeremy Gibbons (http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf). This algorithm can generate the nth digit of pi independently from the preceding digits and runs O(n) in time.

In honor of Pi Day, I ran the code on a Raspberry Pi 3. I slightly modified the calling function to write the generated digits to files in batches of 10000. The computations get slower as the decimal place gets larger. I didn’t time the code exactly, but the time stamps on the files written indicate the first 10000 digits took less than 1 minute, the next 10000 took approximately 2 minutes, then 4 minutes, 6 minutes, 8 minutes, 12 minutes, etc…

Sure you could find and download pi from some online source, but it’s much more fun to do it yourself. I’m running it on my Raspberry Pi 3 right now, and plan to write a another quick and dirty project by tomorrow display them in some way for Pi Day.

Modified source code is below (original code on David Bau’s blog)

#Pi digit generator function
def pi_decimal_digits():
  q, r, t, j = 1, 180, 60, 2
  while True:
    u, y = 3*(3*j+1)*(3*j+2), (q*(27*j-12)+5*r)//(5*t)
    yield y
    q, r, t, j = 10*q*j*(2*j-1), 10*u*(q*(5*j-2)+r-y*t), t*u, j+1

#Caller program writes digits to disk in batches of 10000
count, digits = 0, pi_decimal_digits()
n_per_file = 10000
while 1:
  fn = "pidigits_" + str(count+1) + "_to_" + str(count + n_per_file) + ".txt"
  f = open(fn, 'w')
  print "at " + str(count)
  with open(fn, 'w') as f:
    for j in xrange(n_per_file):
      f.write(str(digits.next()))
    f.close()
  count += n_per_file

 

Apocalyptometer – an IoT Connected Poll Tracking Display

I think I’m not alone in feeling anxious about this election season.  My favorite distraction has always been to throw myself into making, so I decided to channel my politically-driven anxiety into a new project.  Since I find myself repeatedly checking the polling aggregator site FiveThirtyEight for the election odds, this new project is a constantly updating display for the current polling statistics.

Polls-only election forecast from FiveThirtyEight.com
Polls-only election forecast from FiveThirtyEight.com

The specific statistic in question is FiveThirtyEight’s polls-only prediction of the race outcome – shown above, and accessible here.

Read more

LED Matrix Handbag 2.0 – How To

Bag PicturesMy previous post describes a handbag containing a Twitter-connected LED matrix.  The project was somewhat complicated to assemble – particularly the handbag sewing and construction.  This post describes a simpler and more practical way to incorporate an LED matrix into a handbag.  I’ve made several different versions of this project now, involving different styles of handbag.  The version described here produces a vinyl tote bag with contrasting accent fabric as seen above.

Video demonstration of the handbag below:

Read more

LED Matrix Handbag 2.0 – Coming Soon

I recently made a simpler and more attractive version of the LED Matrix Handbag to bring to the Bay Area Maker Faire.  It is far easier to sew than the original, with more streamlined and compact electronics.    Hackaday spoke to me at the Maker Faire about the handbag, and published the interview. If you’re interested in making one yourself, I plan to have a project write-up finished within the next few weeks as soon as I can get to it.  It’s here!  In the meantime, here are some pictures and footage of the latest LED Handbag:

 

 

 

 

Tweet My Purse! (LED Matrix Handbag)

Handbag displaying "hi"
Handbag displaying “hi”

My goal with this project was to create a wearable electronics project that incorporated the electronics in an organic and subtle way.  The end result is a handbag containing a programmable 10×6 LED matrix hidden inside the lining, with the LEDs visible from behind metal eyelets.  The LED matrix is controlled by a Teensy 3.2,which connects to an iPhone via an Adafruit BlueFruit BLE UART Friend.  The Adafruit Bluefruit App on the iPhone subscribes to a MQTT feed (from Adafruit.io in this case), which streams data culled from Twitter via IFTTT.  Any tweets with the hashtag “#wearables” have their Twitter handle displayed on the handbag’s LED  matrix.  Video demonstration below:

Read more

Entering the IoT with CheerLights and Adafruit Huzzah

CheerLights with Huzzah showing blue.
CheerLights with Huzzah showing blue.

It’s hard to avoid the Internet of Things (IoT) these days.  I thought I’d join the trend by starting simply.  I was inspired by the CheerLights project, which uses a Twitter feed to synchronize the color of lights around the world.  I first saw it through a link to an implementation by Dr. Lucy Rogers, who made a color-changing Christmas tree to adorn the cast on her arm.

Read more

EtchABot Part 2: Vector and Raster Images

This post describes how to draw vector and raster images on an Etch a Sketch with EtchABot.  As described previously, EtchABot converts an Etch A Sketch to an versatile, easy-build CNC drawing machine.

In image drawing mode, EtchABot receives instructions through the Arduino serial port.  When connected to a computer running software that converts images to a series of drawing commands, EtchABot can reproduce vector (SVG) or raster images.

Read more

A Tribute to Mechanized Etch A Sketches on the Internet

Motorized Etch A Sketch from http://www.paleotechnologist.net/?p=3625
Motorized Etch A Sketch from paleotechnologist.net

In working on my latest project, a CNC Etch A Sketch, I’ve come across a LOT of similar projects online.  There is obviously something very appealing about taking a childhood toy and giving it electronic controls.

Before adding my own version of this project to the canon, I would like to recognize and thank the large number of people who have so generously shared their knowledge and projects.  So, this post is a listing of mechanical Etch A Sketches I’ve found online.   If you know of a project that you don’t see here but would like to include, please email it to me, and I’ll add it to the list.

Read more

EtchABot: a CNC Etch A Sketch

The EtchABot - a CNC Etch A Sketch
EtchABot – a CNC Etch A Sketch

EtchABot turns your Etch A Sketch into a CNC (Computer Numerical Control) drawing machine.  I’m really excited about this project because of its versatility and its well balanced combination of entertaining and educational aspects.  It’s always fun to hack a toy to do something above and beyond its original intent, and if you build the EtchABot and run the example Arduino sketches, you can make:

EtchABot Gallery

There is an EtchABot Arduino library, so it’s also easy to program it with your own ideas.

Read more