Saturday, June 27, 2009

The real google calculator

I have just completed the first major stage in a funky new project, building a real "google calculator."

Well, sort of...

Essentially, you are looking at the combination of a clunky old NS600 reverse polish notation calculator with a USB->RS232 adapter and a small chunk of Python brought together to create a cloud information display (think of it like a chumby, but far more ghetto...)

Using the python script, the calculator displays how many unread emails I have in my gmail account, and how many unread items are in my google reader list. The decimal point display (actually just a LED) splits the two, so the counter will show no more that 99 unread google reader items and no more than 9999 unread emails (this may seem the wrong way around, but I'll explain this later on). Using this logic, the (crummy, low-light) image above shows that I have 12 unread emails and 47 unread google reader items.

The logic of the python script is pretty simple:
  1. Get the current unread counts for gmail and google reader
  2. Make sure the unread counts are less than there maximums
  3. Multiply the email count by 100 and add it to the google reader count
  4. Press the +/- keys (using relays) until the number displayed is correct
The script keeps a record of the current calculator state so it can work out how many times it has to "press" '+' or '-' and it assumes the initial start point is zero.

The modifications

The mechanicals of the modification are also really simple. A pair of 5v DIP relays are directly triggered from the Request To Send (RTS) and Data Terminal Ready (DTR) pins. These two pins are directly controllable through the python pyserial library, using the setDTR() and setRTS() methods. The calculator was originally powered off a 9v battery, but the internal ic's work perfectly well off the 5v from the usb port.

The relay's are switched on for 0.1 seconds, and the delay between sequential "on's" is also 0.1 seconds - this was the fastest reliable speed. This means that the calculator can increment by 5 every second. This time is important because when a new email is received, it has to "press" the '+' key 100 times, which takes 20 seconds. That is why the emails are on the left of the "decimal point", and the unread google reader count is on the right, as I receive google reader items more often than I receive new emails.

Well, that's it. Of course I should attach the code to this post but, to be honest, it is a bit of a shambles. A reliable, working shambles, but not something that should be inflicted on other people. I will re-factor it properly, give the calculator a clean up, add some more technical detail, take some better photos and make a nice video for my next post.

If you are reading this and want more information before my next post, please don't hesitate to leave a comment.