Wednesday, 22 August 2012


Not the snake, the language.

Python is a popular scripting/interpretive language that uses object oriented structures, so as a scripting language it is pretty sophisticated. Not only that it is easy to run it from Eclipse, including debug mode which allows you to step through the code, examine the variables etc, much the same way I can do with Java and C++.

I'm having to learn this because I'm building a small add-on to Gramps. Gramps is the genealogy program I am using to maintain my family history data. I have to recommend Gramps. It is open source, and it can spit out a fully interactive website with the information when you've got everything entered. These two points mean I know I can easily pass the data around to people who just want to view it (the html) or edit it (the open source thing). I'm not sure I'll actually do the latter (well, maybe when I am dead) but the former is good if I just want to dump it all to a CD and hand it around. The recipients don't need to install anything, just run their browser. I even threw a copy onto my phone and it works fine (so I have it with me if I need to look up something).

Gramps also has a nice plugin architecture so it is fairly simple to write some extra code and add it to the system... as long as you do it in Python because that is what the system is written in. I am doing something to the database (more on that in a moment) so I assumed I could just write a bit of Java, talk to the database with JDBC and do what I need. I don't actually have any interactive stuff, just a batch database update.

Except Python has built in a non-SQL database which doesn't really handle JDBC, and Gramps, naturally, uses this because it is right there. It is also, I suspect, more suitable for this kind of data than SQL, though that's always arguable either way. Regardless, it is not happy with JDBC. There are Java interfaces to it, but they look a bit messy and with the entire source of Gramps loaded up I have plenty of Python example code, so I set to work.

What I did was not hard. It is a plugin to scan all the media objects (photographs, in practice) and pull the Exif data from them. Depending on what is present I push the relevant Exif data into the Gramps database. The idea is I keep titles, descriptions and dates on the actual image files. This means they show up in various photo management tools automatically and they don't get detached from the photo. But I also want them to show up in Gramps.

Gramps doesn't do this for itself, or not the way I want anyway. This is partly because the Exif data structures are very loose and they can't cater for the endless combinations to figure out what is where. My images are tagged explicitly by me so I know what Exif tags are being used, so I can write the code to map what I want.

It was not a big deal. But do I like Python?

Not really. It was easy to set up in Eclipse and fairly simple to pick up the syntax, and the debug tools work well. But I prefer a compiler phase that finds my syntax errors (especially when I am making a lot as I feel my way through a new language). Python finds these at runtime, which means I have to keep working through my test sequence. I could have shortened this with a unit test, and I would have done that with Java anyway, but that was more figuring out and I got lazy.

So I'm not keen to switch to Python any time soon, but I can see why people like using it. I will stick to Java and C code for now.

Thursday, 9 August 2012

Steampunk laser pistol

This is the second generation pistol. The one I made last year was both simpler and more complex. Last year I cut a handle out of MDF and used a Teensy 2.0 to generate a noise when the laser was active. It looked okay. This one is better.
  • 3D printed handle, nicer shape, more detailing etc
  • Blinky LEDs to make it more exciting
  • A glass barrel. It isn't actually glass, but it looks like it.
  • A charger circuit so I don't have to take it apart to charge the battery
  • A more interesting noise
  • Using an Attiny85 rather than a Teensy
The handle was a big deal but it was worth it. I used blender to model my shape in 3D and then got shapeways to print it for me. Fairly pricey when I add freight all the way to NZ, but so much better than MDF.

Here's the handle as it arrived.
It might not be too obvious that this is a gun handle but it will come clear soon enough.

The handle is hollow to accommodate the battery and it has a ridge around the edge so the pearl inset I'm adding will fit snugly. There are two curly bits I'm rather pleased with. It took some fairly fine detail work in blender to get those right and they turned out pretty good. Getting detail that fine with MDF is, of course, impossible. MDF just tears and you cannot carve it.

The next step was to paint it so it looks like metal, and you can see how those curly bits look pretty cool. This picture also shows the pearl insert in the handle.

I also want to mention the raised lozenge shape just above the lower curly bit. There's a wide hole through the structure underneath that and I wanted to add some strength to it at that point. I think the material, now that I've actually handled it, didn't need it. But these are the kinds of decisions you can make with 3D.

The next picture shows the insides of it held in place by a stand with a couple of claws so I can work on it. There is a round green perf board and you can see the speaker dangling underneath and to the right. Opposite that are some stiff wires with the LEDs attached. There's another LED, a green one, on the board. This will light when the battery is charging. You can just see the black corner of the Attiny85 IC between the two claws. I chose this angle to conceal my bad soldering. I have a really good soldering iron, it isn't that. I solder badly anyway.

The code the Attiny85 is running is in a google code project. That also has the 3D model, which I've made public on shapeways too.

The almost finished gun looks like this. Now you can see the barrel in place and you can also see the round perf board sitting at the base of the barrel. The tiny speaker slots into the top of the handle just behind the barrel. It almost fit but I had to scrape back some material with a knife. The actual laser is that brass thing in the tip of the barrel. All it really needs is that and a battery to be a laser, which would not be nearly as much fun. The barrel is made out of a clear plastic bottle, so it won't break if dropped. The trigger is a red push button.
The copper coil is decorative only and the LEDs are kind of tangled in amongst it.

Here's what it looks like in action:  

So far the gun has the electronics exposed. What it needs still is some leather to cover the end of the barrel to give it a more steam punk look. The glue around the actual laser at the barrel tip is a bit messy too so I made some covers for both. There's a thin strip of leather at the tip now, and a copper cover at the other end. So now it looks more steam punk.

The original of this, just so you know where I got the idea, is this classy Derringer. which is a good deal more ornate but much the same shape.

But I was also influenced by one of the guns on Warehouse 13, especially for the glass barrel.

Neither of those are real lasers though.