Archive for the ‘photos’ Category

Artomatic Update: Python on the Fonera

UPDATE: Scratch that. I’ve hit a roadblock related to serial communication in DD-WRT. If you’re only interested in using Python for socket communication and simple stuff, the below text is still useful. But I’ve concluded that if you want serial, DD-WRT is not the way to go. I’ve moved on to OpenWRT — you can see the first step in this process here.


You might remember that I’ve done a bunch of work on integrating the Fonera and the Arduino. It’s a handy setup for microcontroller hobbyists: a reflashed router provides a wireless network interface that’s much cheaper than the purpose-built alternatives available for the Arduino, and one which, by virtue of its Linux firmware, is also considerably more powerful. The downsides are its size and power requirements, but for most applications those aren’t big concerns.

Last time around I just ran a cron job on the router that periodically fetched data from a web server and shoved it to the Arduino using the busybox-based command line tools that come with the DD-WRT firmware (wget, bash, stty). For my next project, those tools aren’t going to cut it. I need two way communication between the Arduino and the Fonera, and I need less latency and more flexibility than those command line tools can offer. I need a proper scripting language.

Unfortunately, things are a bit cramped on the Fonera. There’s an apt-get-like system for installing add-on packages to OpenWRT-based firmwares — it’s called ipkg — but it’s broken on the Fonera, and there’s very little space for the installation of such packages.

You can get around this, but it’s a little tricky. First: realize that ipkg is only sort of broken (on the newer firmwares, at least). You can’t update the list of packages. You can locate a package, copy it over and do an “ipkg install filename“. You’ve just gotta find the right one. (Also: note that I’ve read that using ipkg to remove items on the Fonera can badly screw up your filesystem. Better to remove them manually and/or reformat your JFFS partition.)

Packages with “mini” in their name are probably your best bet. Now you just need to find a compatible one. From the DD-WRT List of Supported Devices we can see that the Fonera uses an Atheros chipset. Start running Google searches like this one and you should be able to find what you need. Here, I’ll make it easy for you: this is the ipkg I used to install python on the Fonera. Copy it over to the Fonera with scp or something similar, then run “ipkg install python-mini_2.5.1-2_mips.ipk”. Success!

Well, until you try to do something with it. I needed three things out of this python installation: simple client/server network functionality (the socket module); the ability to fire off shell processes (the os module); and the ability to communicate with the Arduino over a serial link (the pySerial project).

The first is pretty simple. For reasons that I haven’t bothered to figure out, the socket module is named _socket in the minipython distribution. Adjust your scripts to do an “import _socket as socket” instead of “import socket” and you should be fine. I was able to run the first two examples (client and server) on this page, anyway (debugging the other end of the connection with netcat on my laptop). Good enough for me!

Firing other programs runs into problems. Try to import the os module and you’ll get some complaints about a missing UserDict class. I believe that this class wrapper has been deprecated; I cobbled this UserDict.py together from some Google searches, and after placing it in the lib-dynload path (on my router it’s /jffs/usr/lib/python2.5/lib-dynload/), I can import the os module successfully. I have not tested it thoroughly. os.system(‘touch WHATEVER’) works fine, but beyond that I can’t make any guarantees.

Finally, there’s the question of serial communication. This is actually harder than is may sound: there’s a hardware issue we need to work out before we worry about pySerial at all.

The comments on my Dorkbot post revealed a problem I didn’t know I had: the serial voltage of the Arduino is different from the serial voltage of the Fonera. The former uses 5v, the latter uses 3.3v. This is a pretty common situation, actually, and it’s generally solved through the use of a chip like the MAX232. Fortunately, we can get away with even less. The Arduino’s designers anticipated this problem and made the device able to recognize 3.3v serial input, so signals from the Fonera to the Arduino should work fine. This is why my Dorkbot project worked even though I hadn’t accounted for the voltage mismatch.

But the voltage differential of signals sent from the Arduino to the Fonera needs to be explicitly dealt with — we can’t rely on the Fonera to handle the higher voltage as gracefully as the Arduino does. Fortunately, shedding DC voltage is a lot easier than boosting it, so this is also a pretty easy problem to solve. We just need to make a voltage divider circuit that goes from 5v to 3.3v. It’s basically two resistors, simply arranged. Easy! Alternately, you might be able to step the voltage down using the magic voltage-dropping properties of diodes, but I haven’t bothered to try.

Alright! So our signals are aligned. Back to the software problems. pySerial requires the os module, but we’ve already solved that module’s UserDict problem; on to the next headache. This one is called termios, and it’s a compiled library, not just a python class. It’s commonly included with python, but apparently not with the stripped-down version that we’re using. That’s a drag. We need a version of this library that has been compiled for the Fonera’s MIPS processor. Compiling such a thing on a non-MIPS processor (like your computer) is possible, but cross-compilation is fairly involved to set up. I wanted to just find a compiled version and drop it in.

Once again, googling around downloads.openwrt.org turned out to be a good idea. But don’t go looking for termios — you won’t find it. Instead, I looked for a beefier python ipkg — one designed for more powerful machines, and which contains all of the normal libraries that ship with python. I found it, downloaded it and then uncompressed it (ipkgs are just tarball archives with a specific layout). That yielded two more tarballs; I opened the one named “data.tar.gz”. Within the directories spawned by that I found termios.so. I took that file, dropped it into the aforementioned /jffs/usr/lib/python2.5/lib-dynload/ directory, and was immediately able to import pyserial. Well, okay, not immediately — the first version of the python ipkg that I grabbed was built for mipsel processors, not mips, and gave me a helpful error message when I tried to import it. Once I had the right binary everything went surprisingly smoothly. I haven’t currently got the necessary hardware set up to properly test pySerial, but will report back when I do.

For those of you trying to follow my steps exactly, here’s the termios.so that I’m using. This method should work more generally for selectively loading python libraries that you need onto your Fonera.

Incidentally, all of this is a massive overengineering of what’s necessary to finish my Artomatic project: those requirements could probably be satisfied with a wireless doorbell kit from Logan Hardware and a couple of 555 ICs. But I want this system to ultimately work over the internet, so for me it’s worthwhile to create an IP-capable device.

I guess someone still buys software

Yes, this is pretty dispiriting: an iPhone app that does nothing but cost $999 dollars managed to rack up eight purchases before Apple yanked it. Amusingly, those who’ve jailbroken the new 2.0 firmware have had access to a copycat app since yesterday. It makes me sort of wish Apple hadn’t pulled the app — now the free app won’t proliferate and those eight dopes will be able to continue to enjoy showcasing their elite levels of wealth/idiocy.

plutocrat!

actual institute may not match photo

Last night I went to go see Ray’s band, Truman Sparks. They were supposed to play at Millcreek, a West Philly venue that Emily and I had been to before. We’d gone to see the final show by Bear Attack, a now-defunct punk band known for dressing up as an owl, bear and hunter and performing a catalog of songs solely concerned with bears and their sundry activities. Sadly, the band wasn’t in costume for their final show (I’m told that costume-related disputes are the reason they broke up), and it soon became apparent that their foremost and perhaps only non-ursine distinguishing characteristic was volume.

Millcreek was a weird venue. Picture a personality-free “fitness center” from a timeshare condo development, then imagine using it to serve alcohol — that covers the physical structure, at least. The bartender eyed us suspiciously, distributing Miller Lite while silently assessing our allegiance to Philadelphia’s sports teams. A steady progression of black, middle-aged couples arrived and immediately went upstairs and past a second bouncer, not paying any attention to the show or bar — it’s still unclear whether their destination was a poker club, a swinger’s club, or both. Outside, a West Philly club kid took drags from a cigarette and earnestly told us a story about entering into a sham green-card marriage with a guy she met on the road; each of them assumed the marriage was interracial until they stopped traveling and showered.

The venue was teetering on the edge of civilization in what I’m assured is a distinctly West Philadelphian way. Ray & co. showed up to play Milcreek and found it was closed. The only option left was left was to tumble right over that edge.

So instead we ended up heading to The Philadelphia Institute For Advanced Study, the online hilarity of which probably can’t be appreciated unless you’ve set foot in the place. Located in Fishtown’s warehouse-and-murder district, the building is actually a former sheet metal storage facility that’s been taken over (by UVA alums, according to Ray) and converted into artists’ studios. It was freezing cold, full of broken electronic slot machines, and in a wholly deserted neighborhood. After doing some superficial equipment unloading Emily and I set out in search of beer, but found only rotting industrial carcasses. The traffic consisted solely of very occasional ricers tearing down the wide, empty boulevards at 80 mph, killing time until the next Fast and the Furious movie is released.

Somehow we managed to get back to the warehouse without being robbed or murdered. The band had acquired some PBR tallboys in the meantime, which made the earnest Minneapolitan openers’ set considerably easier to take. After their triumphant acoustic-guitar-and-clarinet alt country finale, the crowd retired to the more rock-capable photography department, where Truman Sparks made good on their promise to melt our faces off amidst scattered photochemicals. At some point a threatening-looking guy in gold chains and an orange blazer showed up wearing airport-style ear protection. But he didn’t end up trying to murder us, either, which was strangely disappointing.

But the show wasn’t. I’m sure the band would’ve preferred to be somewhere with heat, comped beers and a functioning PA, but I don’t really feel any need to revisit Mill Creek until I’m a graying African-American professional looking to spice up his marriage. PIFAS was rock and roll, goddammit, and I had a great time.

also, there was Halloween

Right, Halloween: it’s already happened, as far as I’m concerned. I’m exhausted, haven’t been to the gym in ages, and have a ton of work to finish. I intend to nod approvingly as Charles hands out the massive quantities of candy that he bought, but my holiday celebrations occurred last Saturday. I think I’m even skipping out on a fun-sounding bar outing.

But last weekend was pretty great. Here’s a shot of me as Dr. Doom, looking disoriented:

Doom, disoriented

And here’s a shot of me fighting Galactus.

A few things learned during the costume construction process:

  1. I think Dr. Doom probably makes his own outfits. If you find yourself in possession of a lot of green fabric, an enthusiasm for diabolical technology and little to no sewing skill, a Doomesque cape and tunic combo is a not-unlikely result.
  2. Dr. Doom’s enthusiasm for goblets is born of necessity: it’s really hard to hold onto a beverage while wearing gauntlets. Cupping your drink from beneath is really the only viable strategy. The fact that it looks good when paired with a menacing glower is just a happy coincidence.
  3. Negative ion generators are a nice idea, but they’re also likely to stop working pretty quickly. And you need to think seriously about electrical isolation if you want to build up any kind of charge — ancient sneakers spraypainted silver (and paired with a cape that occasionally drags) are not the best way to keep voltage from leaking into the ground. I managed to give a few people pinprick shocks before the whole thing stopped working, but it mostly served to gently electrocute my right foot. Overall, it was a bit of a disappointment (although thankfully not a very expensive one).

    But I got some late advice from Dan Rutter of DansData.com, which may be useful for aspiring Dooms:

    You might like to try buying one of those “shocking” lighters or pens
    that’re all over eBay and joke shops these days; they’re basically
    just a little Tesla coil inside, I think, and it ought to be quite
    easy to hack one into a shock-glove.

    (A friend of mine made a rather higher powered version of the same
    thing years ago, and installed it in a small project box with
    external contacts, a button, and a label that said “DO NOT PRESS”.
    Needless to say, people picked it up, and pressed the button, and
    sometimes then smashed themselves in the face with the box. :-)

    Sounds promising. Next year: Electro?

At any rate, here are the rest of my photos from the evening. As you might notice, there are kind of a lot of shots of a jack o’lantern sitting in front of a smoke machine’s output hose. That’s because this is totally awesome and should enthrall the lot of you the way it does me. Some people will tell you that on Saturday night I could often be found stumbling around the shrubs, fiddling with the smoke machine. More responsible accounts of the evening will reflect the fact that A) it takes a lot of work to maintain an optimally foggy environment for the enjoyment of all and B) it’s pretty hard to navigate a garden while wearing a cape and cardboard armor regardless of how many beers you’ve just consumed.

part of my Halloween costume

part of my Halloween costume

Can you guess what it is? Winner gets to not be subjected to it. And no fair guessing if I’ve already told you.

beach accomplished

Well, I’m back. I brought with me a tan, a briefly-broken camera, five new pounds of body fat and a profound sense of bewilderment at having missed my college reunion.

Not that I would have gone — it would have been nice to see old friends, but I wouldn’t have wanted to leave my vacation early. But I’m a little miffed that I didn’t heard a peep about it from UVA. I guess they don’t bother keeping track of you if you don’t join the alumni association — something that I refused to do, despite many lame entreaties. “Free Burrito Dinner!” they’d proclaim, “You just have to join the alumni association!”

A delicious burrito did sound pretty good at the time. But since the deal basically amounted to $250/burrito, I declined. Admittedly, I wouldn’t have had to make any payments for several years (it’s the burrito interest that kills you). But the sense that someone was trying to trick me in an insultingly stupid way led me to foreswear the alumni association permanently. Hence: no reunion mailings.

I’m much happier to have spend that time at the beach, anyway. And there are pictures! My own collection is a little truncated, both due to apathy and to sand getting into my camera partway through the trip, making it unable to focus on anything. A little zooming in and out seems to have dislodged the wayward grain, though, and everything’s okay again. Here are the ones I managed to snap before that happened:

You can find everyone else’s photos here.

more in sadness than in anger

Pretty pathetic:

more in sadness than in anger

new header

Courtesy of a Saturday visit to the National Arboretum (or Arbotreeum, as one cellphone-using patron near us called it). It’s pretty nice out there, and easy to get to on the weekend thanks to the X6 bus. In fact, it’s so pleasant that you can easily forget how close you are to the Washington Times building.

They’ve got a bunch of plants & stuff, I guess, but my botanical photography skills are pretty poor. This seemed worth showing, though: DC’s state tree. It’s surprisingly non-crappy, especially compared to, say, Indiana. Now there’s a sorry-ass tree.

DC's state tree

californiaaaaa

Let’s not leave things on a down note. You know what I haven’t posted yet? Photos of California. So here they are — the best ones, anyway. The full set of at-least-vaguely-redeemable photos can be found here.

I wish I’d taken more shots of my friends, any of my relatives, and fewer pitcures of natural splendor — pictures of the first two are usually pretty fun, and pictures of the latter are usually kind of a letdown next to the real thing. But there are a few decent pics in there that at least hint at how astoundingly beautiful Point Reyes is.

But of course the highlight of the trip wasn’t any of the touristy crap, but rather just getting the chance to see folks I hadn’t in a while. It was really good to meet up with Jon, Jeff, Marie and Paul, and to meet Paul’s girlfriend. And seeing Noree, Ron, Jeb and Mimi was wonderful. I really can’t thank Jeff & Marie and Noree & Ron enough for putting us up. Berkeley is a pretty great location for a California vacation home base, it turns out. Not only because it’s walkable and close to the BART, but also because co-op pizza is GREAT pizza. You can really taste the collectivism — delicious, delicious collectivism.