Archive

Posts Tagged ‘Unix’

Hardcore Hardware Hacking Weekend

July 9th, 2007

If you've seen me talk at a conference recently (perhaps XTech or ApacheCon Europe) you'll know that I'm very interested in what happens when the coders who made the web get to script the real world. Cheap and powerful hardware prototyping is now within the reach of anyone who can code a webapp or configure a Unix box.

If you've taken the first steps in tinkering with an Arduino or similar kit, why not take it up a gear and sign up for the Hardcore Hardware Hacking Weekend in London on July 21st and 22nd? Massimo Banzi, co-creator of Arduino, will be teaching advanced hardware skills and I'll be there to explain how to plug it all into software and the internet. I'm especially looking forward to hearing from guest speaker Moritz Waldemeyer. Places are limited and going fast.

Permalink

Uncategorized , , ,

Connecting First and Second Life

January 11th, 2007

I've been interested for some time in the possibilities offered by bringing external data into virtual environments like Second Life. This data might come from the web, but it could also come from the real world - from physical sensors and interfaces.

Over the last couple of weeks I've enjoyed playing with the Arduino hardware prototyping board. This week's open-sourcing of the Second Life client came at exactly the right time for a new experiment.

Here's a video demonstration (people reading the feed, start your web browsers). On the left you'll see an Arduino reading analogue values from a potentiometer and feeding the results in via the USB-serial interface to my Mac. On the right, you'll see a modified version of Second Life that is feeding those values in via my avatar's chat channel. An object in the Second Life world is reacting, with perhaps a half-second lag.

How does this work? All it takes is a few small code fragments in the right places. The Arduino code is trivial:

void setup() {
  Serial.begin(9600);
  pinMode(0,INPUT);
}
void loop() {
  delay(100);
  Serial.println(analogRead(0));
}

The in-world LSL code is trivial:

vector pos;
default
{
    state_entry()
    {
        llListen(42,"Matt Basiat",NULL_KEY,"");        
        pos = llGetPos();
    }
    listen(integer channel, string name, key id, string message) {
        float val = (float)message;
        llSetPos(pos + );
    }
}

The clever bit, such as it is, involves adding a bit of good old-fashioned Unix file-descriptor code to the SL client's idle loop (located in viewer.cpp in the source) that polls the Arduino. Once I've got the reading, all it takes to make my avatar speak to the server is the line:

gChatBar->sendChatFromViewer(reading, CHAT_TYPE_NORMAL, FALSE);

In total, I added about 150 lines of code to a single file to achieve this. Obviously this is just a concept demo, and there are plenty of places to take it from here, but I'm encouraged by the progress.

If you're curious about the details, here's the patch against viewer.cpp in the newview directory of the source. It's definitely not The Right Way To Do It - just the fastest route I could find into the heart of the code. It has hardcoded device names and other bad practice. I release it under the GPL, and must thank Tod Kurt for the use of his arduino-serial.c code and Massimo Banzi for everything he taught me about Arduino over the holiday season.

Permalink

Uncategorized , , ,