Monthly Archives: May 2012

The Weirdo

After sketching out a few different characters, I think that this is the overall shape that the Weirdo will take.

Yeah he kind of looks like Marvin the Martian, but meh. He’s easy to draw and that’s pretty important for me.


Coursera Classes

I’ve been increasingly impressed by the quality of the online classes on Coursera.

At present, I’m taking two classes, Machine Learning and Human-Computer Interaction.

The Machine Learning class is provided by Stanford University and is taught by Andrew Ng.  The class is challenging but very gratifying.  The class uses Octive/Matlab for its assignments.  The biggest challenge for me so far has been the conversion of mathematical formulas into efficient “vectorized” Octave code.  I’ve always taken for granted that matrix operations did specific tasks… like rotate a shape or change the contrast in an image.  I’ve never really had to face the task of how they do it.  I enjoy that the class takes you from zero knowledge of machine learning to a Neural Network that recognizes handwriting in just the first 5 weeks.  Extremely gratifying.  As part of my learning process I’ll be coding some of the stuff that I learned from the class in Java and later C++.  These things will probably be useful as I work on the pi-like stock market predictor from my previous post… Hopefully I won’t end up drilling a hole in my head.

the Human-Computer interaction class only just started … so I have only gotten through the introduction videos, but I can already tell that the class will affect and inform a lot of the design decisions that I make in the future. The class is also provided by Sanford University and is taught by Scott Klemmer.   The class itself seems to be about formalizing the process of making good user interfaces.  By formalizing, I don’t mean some kind of rigorous proof that X is the best design, I just mean putting enough process around design that will make it approachable to people who have no design intuition (like myself).  I have to wonder if maybe I can use this as an excuse to explore some of Buckmeister Fuller‘s design and engineering principals…. I recently saw an exhibit at SFMOMA entitled “The Utopian Impulse: Buckminster Fuller and the Bay Area“.  Extremely inspiring.

Another Pi Image is Born

I recently saw the movie Pi for the first time.  A number of friends and family recommended the movie to me when it first came out.  Me specifically.  As in, this movie would somehow resonate with me on some fundamental way.   It just seemed, though, that the harder I was pushed to see the film, the less likely I felt like actually watching it.

Fast forward about 10 years to a week ago.  I was trolling Netflix streaming for something to watch and decided… “Oh, what the hell.”  I hit play.

I can understand why so many people thought that I’d like this movie.  I think though, that it hits a little too close to home in some aspects but is somewhat dumb in others.  I don’t really want to get into a technical review of the movie because I’m sure that it wasn’t intended to be scrutinized in that way.  I did enjoy it as a story though.

Every computer scientist I know has thought about how to predict the stock market.  I’m not sure that each and every one creates some explicit mantra as does the guy in the movie, but, you know… we don’t all live in a black and white film.

When I’m done with the Machine Learning class over on Coursera, I do plan on trying to make a short-term sale predictor AI.  I’m hoping that I won’t inadvertently learn a true name of God and end up drilling a hole in my head.  I guess we’ll see.

Instead of just stealing someone else’s colorful pi image, I thought I’d be fun to make one.  The image used in this blog post was based on the Wikipedia SVG of the Greek Letter.  I imported it into the GIMP and exported it as text (Yeah, you can do that!).  After cleaning it up a little, I wrote a program that would populate the actual pi digits into the exported image.

use strict;

open(my $pifd, "pi-image.txt") or die "couldn't open pi image";
open(my $numfd, "pi-digits.txt") or die "couldn't open pi digits";
my $ch;
while(1) {
    read($pifd, $ch, 1) or last;
    if ($ch eq "\n") {
        print "\n";
    if ($ch ne ' ') {
        read($numfd, $ch, 1) or last;
    print "$ch";

Once I had the numerically populated glyph, I pulled it back into the GIMP via screenshot and applied a rainbow gradient! Bam! Yet another Pi image is born!

Arduino Control from Web via WiFly

I bought a WiFly a while back but didn’t really do much with it.  For those of you not in the know, a WiFly is a compact wireless device that you can buy on a little break-out board… or in this case, on an Arduino Shield.

The interface to the WiFly is pretty straight forward.  You initialize the library then create a Client object.  This Client object has typical filehandle-like methods such as read(), available(), println() etc.

In this example, I took my previous setup with 8-bit latches and used the LEDs to display output that I submitted to a webservice using the WiFly.  The Webservice in question is a very simple php app that returns a single 8-bit hex number.  Here’s the code:

<?php print '@'.dechex(time() % 255); ?>

The prepended ‘@’ sign is a flag value.  Because read() returns just a single char, I wanted to skip through all of the http header information to the data.  I stop when I encounter the first ‘@’.

I modified the latch setup I had by using two triplets of pins instead of sharing the single triple.  This allowed me to independently control two latches. Here’s the final code for the project:

#include "WiFly.h"

int latchPin1 = 2;
int clockPin1 = 3;
int dataPin1 = 4;

int latchPin2 = 5;
int clockPin2 = 6;
int dataPin2 = 7;

Client client("", 80);

void setup() {
  pinMode(latchPin1, OUTPUT);
  pinMode(clockPin1, OUTPUT);
  pinMode(dataPin1, OUTPUT);

  pinMode(latchPin2, OUTPUT);
  pinMode(clockPin2, OUTPUT);
  pinMode(dataPin2, OUTPUT);


  if (!WiFly.join("ssid", "password")) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.

int convert(char ch) {
    if (ch >= '0' && ch <= '9') {
         return ch - '0';
    if (ch >= 'a' && ch <= 'f') {
         return ch - 'a' + 10;
    return 0;   

int getWebValue() {
  if (!client.connected()) {
      if (!client.connect()) {
        return 0;

  client.println("GET /arduino.php HTTP/1.1");

  char ch;
  while (client.available()) {
    ch =;
    if (ch == '@') {

  if (!client.available()) {
     return 0;

  int a = convert(;
  int b = convert(;

  return (a << 4) + b;

int count = 0;
void loop() {
    int a = getWebValue();

    if (count++ % 2 == 0) {
        digitalWrite(latchPin1, LOW);
        shiftOut(dataPin1, clockPin1, MSBFIRST, a);  
        digitalWrite(latchPin1, HIGH);
    } else {
        digitalWrite(latchPin2, LOW);
        shiftOut(dataPin2, clockPin2, MSBFIRST, a);  
        digitalWrite(latchPin2, HIGH);

Pretty simple for the most part.  As with the WiFly examples, I use the Serial Monitor to echo print.  Very useful when trying to figure out what you’re getting via network.


Terrain Tiles

The challenge here is, What is the minimal set of terrain tile types to be able to build arbitrary terrain in a side scroller?  In theory, you don’t need minimal sets of anything if your blocks fit exactly into a square.  You see that all over; especially in the older Nintendo classics.  I want to be able to use a more diverse set of borders though… and I *think* the above image represents a complete set.

That’s not to say that each type of tile won’t have many distinct tilesets… Hopefully I will have quite a few distinct tilesets for this game.

Monkeying with 8-bit Latches

I while back, I bought a couple of 8-bit Latches which I had intended to conquer the world with… but just never got around to it. As I’ve just found out… these specifically may not be the right model for that purpose. sigh.  Let me expound…

As I’ve explored in previous Arduino setups, I want to control lots of things with few output pins.  With this specific setup, I was hoping to populate two different 8-pin latches using a large number of shared pins like with the LCD project… but alas, these latches don’t really like sharing their pins…

If I share pins between the latches (clock/latch pins) but have a selectable data pin, the unselected latch still *thinks* I’m talking to it… What I need is a latch with an Enable Pin.

Pictured above, I was just testing to verify that both latches actually worked. Both are connected to the same outputs, so their values are mirrored. I won’t post any code this time because I used the ShiftOut example verbatim.