Archive for the ‘fun’ Category

Controlling Arduino via Serial USB + PHP

28 Dec

Paloma bought me an Arduino for Christmas, and I’ve been having lots of fun with it, first following some tutorials to get familiar with the platform but of course the real excitement for me is being able to control it from my computer, so I’ve started playing around with serial communication over the USB port.

I messed around with Processing a bit, and while Processing seems pretty cool and pretty powerful for drawing and making a quick interface, I want to be able to get up and running fast communicating with all of our existing systems, so I thought PHP would be ideal.

I’ve never used PHP to communicate over a serial port before, so I did some digging and actually came across an example of using PHP to communicate with an Arduino, but it wasn’t working properly for me. My LED was blinking twice every time, and if I changed it to a value comparison (i.e. sending 1 in PHP and checking for 1 on Arduino) it was never matching. Turns out for some reason by default the com port wasn’t running in the right mode from PHP. The solution is a simple additional line:

exec("mode com3: BAUD=9600 PARITY=N data=8 stop=1 xon=off");

…but make sure you adjust to match the settings appropriate for your computer.

Of course I had to write my own little demo once I got it working. This PHP script takes command line arguments and passes them along to the arduino, which looks for ones and zeroes to turn the LEDs off or on. Unlike the example I linked to, I’m working with a shift register to drive 8 LEDs, but you’ll get the idea, and it should be obvious how to convert it to work with a single LED.

ini_set('display_errors', 'On');
exec("mode com3: BAUD=9600 PARITY=N data=8 stop=1 xon=off");
$fp = fopen("COM3", "w");
 foreach ($argv as $i => $arg) {
    if ($i > 0) {//skip the first arg since it's the name of the file
        print "writing " . $arg . "\n";
        $arg = chr($arg);//fwrite takes a string, so convert
        fwrite($fp, $arg);
print "closing\n";

And for the Arduino:

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 4;
const int clockPin = 3;
const int dataPin = 2;
void setup() {
    pinMode(latchPin, OUTPUT);
    pinMode(dataPin, OUTPUT);  
    pinMode(clockPin, OUTPUT);
    //reset LEDs to all off
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000);
    digitalWrite(latchPin, HIGH);

void loop() {
    byte val = B11111111;
    if (Serial.available() > 0) {
        byte x =;
        if (x == 1) {
            val = B11111111;
        } else {
            val = B00000000;

        digitalWrite(latchPin, LOW);
        shiftOut(dataPin, clockPin, MSBFIRST, val);
        digitalWrite(latchPin, HIGH);

For bonus debugging points, if you’re using a shift register like this, send x instead of val to shiftOut, and you can actually see which bytes are being sent, very handy if you’re not getting what you are expecting (like I was)!

1 Comment

Posted in Coding, fun


Obama Scary

12 Aug

I hope I’m not the only one who finds this incredibly amusing. I made this clip:

From this clip:

The Daily Show With Jon Stewart Mon – Thurs 11p / 10c
Healther Skelter
Daily Show
Full Episodes
Political Humor Spinal Tap Performance
No Comments

Posted in fun


What’s been keeping me busy

14 Apr

Katy and I have been hard at work this past month on a top-secret project, code-named tambourine. It will be known to the public as Grooveshark Lite.

We’re nearing the end and we’ve been given permission to leak a tiny little bit. There’s other big news coming down the pipe very soon, but this is pretty big to us too. Teaser screenshots:

Grooveshark Lite:


Listen to any song cached on Grooveshark:

Unlike the current Grooveshark website, Grooveshark Lite doesn’t require the sharkbyte client, and doesn’t require a user account to listen, search or browse.


Fun office pranks

08 Feb

One of our co-workers recently managed to leave his computer unlocked when he left work for the day. Time for hilarious pranks!

The standard “punishment” for leaving ones computer unlocked is to modify their system settings, often times setting their background to something humorous or embarrassing.

Katy wrote up a long blog post explaining in detail how to hijack the background of an unlocked mac, inspired by a prank we pulled on a co-worker who made just such a mistake. In summary we set his background wallpaper to get set every couple of minutes, also causing his dock to restart, very closely mimicking the symptoms of a virus…but on a mac. I don’t have any Mac-fu, but I was able to use my linux-fu to make the prank even more devious.

touch -f sourcefile destinationfile
copies the timestamp from one file to another. If you put your prank image in a directory with a bunch of other files, you can help your file blend in by giving it a timestamp that’s the same as another file.

The other trick is to move the file into a folder whose name starts with a . so it is harder to find. While you’re at it, might as well name the file with a starting with a . also.

We stashed the trouble files in his .keepass folder and named them things like .specialkey.

finally, history -c clears out your terminal history so that nobody can see what you have been up to.

Sadly, Katy felt guilty about being so mischievous and left instructions on how to ‘fix’ it, so he never got to appreciate the extra detail we went through to make it tricky to find and fix.

But you can bet he locks his computer now, and he learned how to make his Mac show hidden files.

No Comments

Posted in fun



27 Jan

What happens when your UI doesn’t behave the way you expect it to?
Yesterday, Katy managed to create a new type: BooStringlean.

Oddly, her IDE did not complain that it had never heard of a BooStringlean; it was her auto-documenter that complained.

No Comments

Posted in fun