Monday, November 02, 2009

More Timelapse

Here's the camera taking images of the evening sky.  I stopped it when it got so dark that it was taking nearly 4 seconds of exposure per shot.


Here's the movie made at 25 fps with 900 photos at 5 second intervals.

Canon EOS 450D triggered by an Arduino

I was finally able to track down a 2mm stereo plug here in Belo Horizonte (Eletronica Guarani) so I can remotely control my Canon SLR from the Arduino.

It uses two SPDT relay switches, one for the shutter and one for focus.  The way it's setup, there's no way I can cross the wires and hurt my camera, even after a few beers.  In the photo the black wire is hooked to ground and the blue wire to pin 12 on the Arduino (or Seeeduino in my case).  So far I've only used the shutter and have left auto-focus off.
Here's my first attempt of a timelapse movie with this setup:



You'll find the code here. This page helped me figure out to hook-up the plug.

Making the movie is a little tricky on Linux.  First you'll need to installed GraphicsMagick (a faster version of ImageMagick):
sudo aptitude install graphicsmagick
Then you'll need to downloaded and compile from source mpeg2encode to that it can do the conversion to mpeg (this doesn't come included with GraphicsMagick because of some licensing issues).
mkdir -p ~/tmp
cd ~/tmp
wget http://www.mpeg.org/pub_ftp/mpeg/mssg/mpeg2vidcodec_v12.tar.gz
tar xvf mpeg2vidcodec_v12.tar.gz
cd mpeg2
make
sudo cp src/mpeg2enc/mpeg2encode /usr/local/bin/
sudo cp src/mpeg2dec/mpeg2decode /usr/local/bin/
cd ..
rm -rf mpeg2
rm mpeg2vidcodec_v12.tar.gz
Finally to do the conversion you need to go to a directory that has all your photos and execute:
gm convert -size 640x480 -resize 640x480 -monitor *.jpg movie.mpeg
This will convert all the jpg images in the directory to 640x480 and create a new file called movie.mpeg (-monitor is to output the progress).
It's a good idea to remember to set your camera to the lowest image quality settings before hand so you don't waste time downloading large images that will be downscaled anyway.

Halloween Fun with Arduino and LCD

For Halloween this year I did two things. I redid my spinning POV hat. I basicallly, just made it stronger, and lighter since it fell apart last year.  To make it lighter I used the Arduino Pro (5V) and two coin style batteries (CF2032) instead of the normal Arduino and the heavier 9 volt battery.  I didn't have much time to perfect it so the effect wasn't perfect (code).  I really need to put a sensor on it that senses every time it spins around for it to work correctly, at the moment I just guess how fast it's spinning and put in a delay based on that guess.  What came out doesn't look that hot:


The second device I made was a little more successful. It was a 16x2 line LCD from sparkfun (GDM1602K rev 2.1) display connected to a button so that every time you pressed it one more friend would be added.  I would go up to people and say "Press the button to be my friend on orkut".

There's a colloquialism here in Brazil: "Me Add" which is both a shortening of "Me adiciona" and a perversion of  "Add Me" in English.
Two additional items that are still in the mail that might have made things even more interesting are this big red button and the wave shield to make some interesting noises when the button was pressed. Maybe for next year.
The pages that helped me the most to set this up were both from arduino.cc (LCD, button) and the code is here.
Here's what it looks like underneath:


I stole the button from the Mame console I made before. The potentiometer is needed to get the contrast correct (otherwise the text looks either black or empty). I wired the LCD back-lighting so that it was alway on and at 100% (since Halloween is at night). The resistor is just for the button.
Too bad there's no trick or treating in Brazil, otherwise I would have made something scary as well.

Monday, October 26, 2009

I need a weedwacker for my fish tank

I think there are some fish in there somewhere...


Here's what I ended up taking out.


Here's what it looks like now


Tuesday, October 20, 2009

Making an Arduino Controlled Power Outlet

Over the weekend I created a Arduino controlled power outlet based on this design.


With this connected to a the Arduino I can control the two plugs independently.  One end (which I cut an old US style plug) I plug into the mains power, the other end I connect to the Arduino (four connections):


The fit was a bit tight!

I did some tests to see if when the solenoids are on whether is would heat up too much.


After about about a 1/2 hour it did heat up to 32 C° which isn't too bad.  So now I'm all set to scare some animals.

Wednesday, October 14, 2009

Arduino Sonar Trigger Part 2

The idea this weekend was to setup the sonar with the Arduino so that I can get a shot of the Siriemas that pass daily at the farm, or maybe a hummingbird.

Well that didn't work out so well, turns out that the sonar is affected by the wind. Adding a bit of hysteresis to the code, fixed it for the most part.

I used lua to program the camera, except that it looks like there some issues with it and my Canon SD450.  Calling get_shooting() repeatedly causes problems, for example. I got my intervalometer code to work correctly only after removing that test.  Here's some timelapse photography that did work.

Monday, October 05, 2009

Canon SD450 Triggered by Sonar and the Arduino

This weekend I played with my Canon PowerShot SD450 (aka IXUS 55) and the CHDK along with the Arduino and the MaxBotix MaxSonar LV-EZ1.  The idea is to automatically take pictures when an object moves into frame.
Part of the job involved hacking a USB cable to hook up to the Arduino which I promptly did, as you can see below.


Unfortunately, I was supposed to hack a Mini-USB cable (of which I have a dozen) and instead hacked my (only) Micro-USB cable (oops).
The end I soldered two break away headers and then encased the whole thing with hot glue.

Here's the setup. You can see the sonar on the right.  I soldered a female header to it instead of soldering wires directly to the board.  The hacked USB cable is connected to ground and pin 13.  For the sonar I've plugged it into Ground, 5V, and pin 7.

You may also note that I'm not using the AN (analog) pin on the MaxSonar, but instead the PW (pulse width) pin, unlike most code I saw on the web.  The code is near the bottom on this arduino.cc page. My final code for the arduino is here.

I should mention that the CHDK is a little tricky to setup on the SD450 for shooting remotely by USB.  From what I understand it's supposed to be able to do that out of the box, but it didn't work for me.  However, by creating a LUA script for the camera I was able to get this to work.

To finish the project I'm going to glue that bolt you can see under the plastic container which just happens to be the right size for a tripod bolt.  I'll also add a potentiometer which I'll hook up to a threshold, how far the subject must be before I take a shot.  I'll probably try and take some pictures of hummingbirds near the feeder this weekend.

Saturday, August 22, 2009

Has the Web Made Us Better Readers?

In the recent past, when writers used expressions like "Procrustean bed" or "Sisyphean task", they might have been considered rather 'snobby', even if those expressions might have been appropriate.

Today, of course, we can link to the definitions or have the reader search for the definition easily. It think, as long as the article isn't full of these types of references, it isn't too much work for the percentage of readers that may not remember their greek mythology.

Today, writers don't even need to go back to ancient Greece for their archetypes:

"Jumped the Shark" is a great expression for when something has become passé (follow the link if you don't know this one).

"Streisand Effect" is when the attempt to suppress information backfires and just makes it even more widely publicized.

"Take the redpill" when you need to leave your fantasy world and meet reality.

"Dialed Up to Eleven" for when something exceeds beyond, say, 10.

If you grokked all that, I think you might agree that writing on the web can and probably will become richer over time since there's little fear in throwing in an obscure allegory, idiom, metaphore, or colloquialism. You just a click away from being a snob, to being illuminating.

Here's to the end of dumbing down for the masses and instead writing rich, interesting and insightful articles.

Thursday, August 13, 2009

What I'm working On

At Google we have lots of internal tools, many for the command line. On occasion some googler will take one of these tools and make it into an internal web site.

Usually, when this happens I think "Why? The command line tool is much more convenient!". At first, the web site isn't all that useful, but week by week, features get added until the web version is faster, and has more useful features than the command line version.
I started thinking that I have some old programs that I wrote, years ago, which could be better off on the web.

One program I did this to is mm2notes which takes FreeMind MindMap and creates meeting notes. The original version was only for the command line. Already I can see the web version could be far more useful than running from the command line. For instance, I can e-mail the action items to the people that have something to act upon.

Another program that I wrote, even longer ago, was a program to help me learn Portuguese. It had two parts, one to train on the conjugation verbs, the other on writing checks. I wrote it in C++ and and MFC, so you have to run it in Windows.

The other day I had to write a check and I remembered that old (2005) program. I figured it was time for me to learn the Java version of the Google App Engine version with GWT and so I converted the code to Java and GWT.

It's really quite pleasant working with GWT, I have so say. This whole program is client side, you could be practicing writing checks on the airplane. If you run the program in a new version of Firefox or Safari you'll also get the benefit of @font-face css tag which will download a handwriting like font (which I purchased a long time ago from Corel).

The web site is escrevecheque and the source code can be found here.


Saturday, July 25, 2009

I'm Liking Mercurial



I've been a longtime user of subversion for source control, and with Google's Project Hosting, that was the only choice.
For a new project I'm working on I decided to try mercurial, instead.

I think I'll stick with mercurial from now on:
  • It's very close to subversion for most commands.
  • It's incredibly fast.
  • I can perform commits without an internet connection.
  • It uses only one hidden folder for the whole tree.
The only issue I've found so far is that the default Mercurial version for Ubuntu is before version 1.3 which allows you to store the password in a ~/.hgrc file. So, for now, I need to type in the password every time I do a push.

Sunday, June 28, 2009

First Wave Robot

I took advantage of the fact that some wave developers were passing by our office and wrote a wave robot during a jam session. This robot monitors what is being typed and makes it easy to convert to different units. If you type "100kg (? lbs)" it will replace the ? with the correct value of 220 after you type the closing parenthesis, for example.

I went a bit further and tried to be sensible with the significant figures. I didn't want it say '220.462262 lbs. So I examine the number of significant figures from the original number and try to duplicate it in the result. If you say "100 kg" it'll put "220 lbs". If instead you enter "100.0 kg" it'll put "220.5 lbs".

Test revealed, however, that this wasn't good enough. If I put in "1 inch" in would convert this to "3cm", a 18% error. I put in an extra rule to increase the precision if the error was greater than 10%, which got these corner cases.

What's interesting is that it took more time to write the conversion routines than it did to hook it up with wave. If you use Google App engine in Python or Java it's dead easy.

Google Wave is really a new way to communicate and collaborate, even without robots and gadgets. With robots it goes to a whole new level. You really should take a look at the wave api documentation.

The code for my converter is available here and the robot is called convertsy@appspot.com.

Tuesday, April 21, 2009

Grub Could be A lot Simpler

Today I reinstalled Windows XP on my son's machine (my old machine). Ubuntu works perfectly with sound, video, and internet, but Windows...
In Windows, I had no sound, no internet, and problems with the video card. Then when I tried to update, it said I can't use and English version of XP in Brazil!
So I reinstalled with a Brazilian version of XP which blew away the boot sector (and thus the menu for selecting Ubuntu is gone).
There are some good instructions here on how to restore grub, but jeez, such a simple program has to be so much work:
sudo␣grub
find␣/boot/grub/stage1
root␣(hd0,1)
setup␣(hd0)
Worse, it's even picky about spaces, you need to put a space (shown above as '␣') or you'll get an error message, you've got to be kidding me. If you forget the sudo, it gives you useless error message instead of mentioning that running as root is probably a good idea.
I suggest they fix grub with tab completion so that I can just press "r" and get:
restore my goddamn boot menu!
It should just figure out the rest, possibly asking a question if there's any doubt.

Speakers Housing Part II


Today's a holiday (Tiradentes Day) , so I finished off my speakers!
This time I even tested them (last time I was so exhausted that I didn't even want to know if they worked or not).
I ended up putting the screw covers on with contact cement - I don't know how long they stay up there.
One project completed!

Monday, April 20, 2009

Speaker Housing


This weekend I finished my speaker housing so I can have some sound on the veranda.
It was a lot more work that I had hoped, I'm still sore. My reciprocating saw didn't survive the experience either.

Unfortunately, I still have some work to do:
  1. put some edge strip laminate in the missing parts
  2. plane down this piece so that it's flush.
  3. Hide the screws. I bought some covers, but I realize now they won't work, all my screws are flush and they must be protruding.

Thursday, April 16, 2009

How I'd Improve the Nintendo Wii


Nintendo is coming out with the Wii MotionPlus, which improves the already revolutionary controller. It started me thinking on what else Nintendo could do.

For instance, one or two cameras could be mounted on the TV pointing to the players. This has been done before and makes for some fun games. It also could be used to improve the playability of the games. Imagine a sword fight where you can physically jump out of the way of the sword!

Today if I want to play a quick game on the Wii Fit, I have to:
  1. Drag out the Wii Fit platform and turn it on.
  2. Find the Wii Fit DVD.
  3. Eject the game that's already in the console, home that my son saved his game and put the DVD somewhere.
  4. Put the Wii Fit DVD in the console and restart the console.
  5. Move and click the cursor to select the Wii Fit game.
  6. Go through several screens and warnings.
  7. Select which player I am.
  8. Start playing, whew!
It could be a lot easier. Putting in a DVD to select a game seems sooo 2001. I can't remeber the last time I put in a CD to listen to music. It should be more like this:
  1. Drag out the Wii Fit platform and turn it on.
  2. The Wii suspends my son's currently game and shows me a list of games that run with the Wii Fit.
  3. Allows me to select the game by gesturing to the screen (using the camera, I should need the wiimote for something a simple as this). It loads up the game nearly instantly from it's internal drive. It already knows who I am since it used face recognition from the camera.
  4. Start playing.
Wii Fit could now tell if I'm doing the posture correctly confirming my position in the camera. Now instead of saying "You have good posture" it could say "You have lousy posture, but your balance is good".

Wednesday, April 08, 2009

Wake on lan works

I previously tried to get wake-on-lan to work and had no luck. I was never sure if my code was wrong, or if a firewall was filtering the command of if my motherboard just doesn't support it (probably the latter).
Today I got a new computer and the old wake-on-lan.py worked!

So here's the program that works for me.


#!/usr/bin/env python

import socket
import struct
import sys

def wake_on_lan(macaddress):
""" Switches on remote computers using WOL. """

# Check macaddress format and try to compensate.
if len(macaddress) == 12:
pass
elif len(macaddress) == 12 + 5:
sep = macaddress[2]
macaddress = macaddress.replace(sep, '')
else:
raise ValueError('Incorrect MAC address format')

# Pad the synchronization stream.
data = ''.join(['FFFFFFFFFFFF', macaddress * 20])
send_data = ''

# Split up the hex values and pack.
for i in range(0, len(data), 2):
send_data = ''.join([send_data,
struct.pack('B', int(data[i: i + 2], 16))])

# Broadcast it to the LAN.
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(send_data, ('255.255.255.255', 7))
sock.close()

if __name__ == '__main__':
machines = {
'hera' : '01-23-45-67-89-AB',
'zeus' : 'CD:EF:01:12:45:67',
}
machine = 'scott'
if len(sys.argv) > 1:
machine = sys.argv[1].strip()
wake_on_lan(machines[machine])


In the BIOS settings I turned on both "PME Event Wakeup" and "Power On Ring" (neither of which is written "wake on LAN").

I'm quite happy with the computer, it has a very silent power supply and I also got a 22" Samsung LCD to go with it.
No I'll have to go and setup my old computer for Victor.

Monday, April 06, 2009

Weight Log

I've put together a web site to track my weight and exercise.
But mostly it's to play with Google App Engine.



In the process I discovered two things I didn't know about before:
  1. The Google Visualization API. It's a very neat way of putting up charts easily. One nice feature is the separation of data to data views. You can, for instance, download (via AJAX) one table with six columns and produce 5 charts from it with 5 views, very neat.
  2. You can use some libraries for free (i.e. it's doesn't count for your application's quota, and you get updates without having to manage it). For my app I used the dojo library.
I figure the more of these web application I make the easier it will become.

I'm not going to do an app a week like Web App Wednesday, but Google's sure making it easy to put up a site.

Saturday, April 04, 2009

Hard Drive Cloning in Ubutnu

I'm buying a new computer, but the new computer is without a hard drive nor a video card. My computer is going to Victor who's has increasingly found it difficult to buy games for his computer, even games that are 4 years old. Victor will get my old 120 Gig drive and I'll just use the 450 Gig drive that's also been on my computer for a while.
I've been running my computer off an older 120 Gig Maxtor with another 450 Gig used for backup and some larger files. My idea was to offload all the files off the 450 Gig (to my 1 TB drive my video server) and move all my stuff from the 120 to the 450 and just use the 450.
I searched the Internet but it was not clear what the best method was to use.
In short I:
  • Copied off all the old files off my 450 Gig drive using rsync.
  • I used GParted to clone the 120 GB drive to 450 GB (using copy-paste!). I created a bootable "live" version of GParted CD from here.
  • I unplugged the 120GB drive and just left the 450GB in it's place.
  • I used an Ubuntu boot disk to create a boot partition.
  • Rebooted, and it worked!
The links above goes through the steps. I would have been nice if GParted had created the boot partition as well (and maybe it can, I don't know), but this method worked just fine.
My usual m.o. when getting a new drive has been just to put it in the computer, and mount it as a separate folder. Now that I've done this once, I think I'll clone the drive instead and use the older drive for backup, etc.

Sunday, February 01, 2009

Toilet seat up or down?

These are some of the important questions in life.

The Way Women See It
  • If I didn't have you in my life, I would never have to bring the toilet seat down.
  • If I forget to check that it's down, I'll end up sitting in toilet water.
  • Men could pee sitting down, if they wanted to.
  • You are already getting free sex, it's the least you can do.
The Way Men See It
  • If I didn't have you in my life, I would (almost) never have to put the toilet seat down.
  • 9 times out of 10 when I go to the toilet it's to urinate. Having to both lift the seat up and put the seat back down seems like a lot of work.
  • Peeing sitting down takes longer, and doesn't get the last drops (especially when you get a little older).
  • You're being selfish for not put up the seat for me, why shouldn't I be selfish and not put the seat down for you?
The Solution
Put both the seat and the seat cover (lid) down.
  • If you have to put the seat down, it takes as much work to put one down as two.
  • It can make the bathroom look nicer.
  • It's a lot more sanitary, but you have to put it down before you flush.
  • Equality for the sexes!

The Tipping Point

I just finished reading the Tipping Point and started thinking.

I realized that a site like Good Reads, is a place for "mavens", people who love books come there and tell others what books they should read. The whole publishing industry should pay for this site and encourage these mavens to flock there and give their opinions.
It also made me realize that Good Reads needs more work on developing their network. Make it easier to find others that have the same interests as you do.

Also from my work on orkut I realize that competition is very powerful. You see that your friends have 300 'friends' and you feel inadequate, and work to build up your list of friends. The same could happen to books, you see someone with 100 books that they have reviewed and you start wondering what's wrong with you. You start buying, and reading more books - and giving opinions about these books.