Raspberry Pi Binary Clock 
Sunday, July 14, 2013, 09:08
Posted by Administrator
I have been fascinated by number systems for most of my life. I especially like binary since it is so incredibly fundamental to the deep underpinnings of our technological society yet incredibly simplistic. I take a special delight whenever technology is combined with art and what better way to demonstrate this concept than through a binary clock.

I had been formulating this project in my head for months and gradually assembled the materials required. Amazon had a great deal for buying 100 white LED's + resistors so I made sure to snatch those up. I also accumulated a couple solderless breadboards and variety of m/m m/f wires to make everything easier.

To drive the logic behind this project I decided on going the easiest route possible by using a Raspberry Pi since their GPIO handling Python libraries are so pleasant to work with. I also decided on not doing any sort of multiplexing to drive the LED's and just addressing them all individually through separate GPIO pins. At first I was going to include seconds on the clock but decided against it due to both the additional wires that would be required and to the aesthetic appeal of not having lights constantly blinking on the finished clock.

I also decided against my original idea of using ping pong balls to be light diffusers for the LED's. While this technique does work fairly well the light distribution proved not to be as uniform as I would have liked. The LEDs I have tend to do a sort of short distance projection effect which leaves a circle of light on whatever is in front of them. Without the ping pong balls the final design was also able to be quite a bit smaller and more compact.

After getting some time off of work and a few days of getting bored of not tinkering with any code I decided to get around to building out the binary clock. The first thing I did was take some black construction board and drill holes for all of the LEDs. I placed this board inside of a picture frame and then attached all the appropriate wires. An unexpected bonus was that the picture frame backing was able to be remounted on-top of the wires which served to prevent them from dislodging. One of the lights had to be replaced as it was DOA.

Image Removed

After this I started assembling all of the ingredients into the breadboard and connecting all of the wires into free GPIO pins on the Raspberry Pi. This proved to be the most tedious part of the project. Since I used a spare IDE cable to access the GPIO pins everything is in reverse on the other end of the cable and about halfway down due to the extra pins that an IDE cable has. I tested these out one by one and recorded what light went to what GPIO pin on a notebook. During this initial prototyping phase I duct taped everything down to a dresser as seen below.

Image Removed

Finally everything was in place and it was time to get to programming. I had expected this to take most of the time of the project as I have not worked with Python very much in the past but it ended up taking the least time of all. I sat down to start it on a Saturday night around 21:00 and ended up finishing it off well before 22:00. Most of the time spent was in learning more about Python conditionals and not building the clock itself. Every time I write anything in Python it amazes me how few lines are necessary and how easy it is to learn the small amount of overhead needed to write the code.

Admittedly things were made much easier for me since I was able to make use of the script I had written in the past for my last bash binary clock project. I removed much of the code and limited it to producing just a string of the current hours and minutes in binary.

Image Removed

After this it was just a matter of initialising all the GPIO ports to be in their OFF state as a number of them are turned on by default when the Raspberry Pi boots up. An array of all the lights in order is used to address all the lights as they correspond to the output of the bash script. The lights are set on and off accordingly and this process is repeated every three seconds. Three seconds seems like a good trade off on accuracy vs system load as I don't like the idea of this having to run every second since I still intend to use it as the primary Raspbmc media player in the bedroom.

The code for the clock came out much shorter than anticipated.

Image Removed

I also made another small script to turn all the lights off. It is quite similar to the one above except it basically just goes through up past the initialization step and stops.

Too make things really fancy I decided I wanted to be able to control the operation of the light with an Android smartphone. A free app called LazierGeek made this pretty easy to accomplish. I've set up one shortcut to run the remote ssh command:

sudo nohup python clock.py &

Which starts a background process of the clock without the need for an active session. To stop the clock and turn off all the lights I run another appropriately lazy command:

sudo pkill python; sudo python alloff.py

Which kills Python ( Effectively stopping the clock ) and then runs the initialization script on all the lights to get them in their off state.

At this point the clock was still duct taped down to my dresser. After a few days of taking extra care not to disturb any of the wires I decided that it was time to put it in a box for extra mobility and durability. A spare empty shipping package was selected for this purpose and I began to cover the entire thing with black duct tape. I also cut a hole in one side of the box to fit the picture frame screen as well as a smaller hole in the back for all the wires to come out. After a great deal of coaxing I got everything off of the dresser and smushed into the box where I taped everything down.

Image Removed

The box was then sealed with more tape.

Image Removed

At this point I'm debating leaving it like this, or putting this box within a spare computer case to make it look even sharper. In some ways I like the duct tape's charm and how it serves to draw attention away from some of the lights being positioned a bit wonkily.

Thoughts and comments are welcome.
3 comments ( 28628 views )   |  permalink   |  related link   |  $star_image$star_image$star_image$star_image$star_image ( 3 / 5923 )
Raspberry Pi: Tao Te Ching Morse Code LED 
Sunday, March 24, 2013, 15:27
Posted by Administrator
I spent my three day spring break this year working with the Raspberry Pi GPIO and learning some more about python in the process. My first task was to get all the necessary GPIO packages installed on one of my dedicated raspbmc machines. The RPi.GPIO Python library was pretty easily installed with pip and was much friendlier to work with than I was expecting.

I used an old IDE hard drive cable to interface with the Pi's GPIO pins. This proved to be one of the harder parts of this project since these type of cables don't have the same number of pins as the Pi's GPIO. For lights I used a doubled up white LED + Resistor combination I had lying around.

Image Removed

To start with I just got an initial feel for the outputs by plugging the LEDs into the 3v power and ground. I then used the RPi.GPIO python library to get the lights blinking on and off at a medium pace. The rest of the night was spent trying to think of something more interesting a single light could do.

After some light googling I eventually became inspired by m0xpd's gmail notifier script. I loved how elegant the design was and decided to apply the same concept to read in a text file and display it all in morse code via the LEDs.

Python is such a joy to work with, in about half an hour I was able to finish forking over m0xpd's code into what I wanted. Coolest thing I learned in the process was about anonymous functions by using the keyword lambda. I also found that there aren't any morse code standards for some common ascii characters like asterisks or dashes so I came up with a few substitutions I thought were appropriate.

One of my favourite books is the Tao Te Ching (especially the translation by S. Mitchell), so I decided to use that to power this LED art piece. Here is a video of the project running. The rest of the day was spent monitoring how long it took the contraption to process the entire book. It finished a little while before bed, taking 637 minutes and 4.257 seconds to run through the entirety of the text.

The full code I used for this project is available in an easy to read color scheme at pastie.org here.

Next up on my list of personal things to work on is to extend my old binary bash clock concept to work with the Pi's GPIO. It turns out that there are exactly as many controllable outputs ( Seventeen ) as I need to run the kind of display I want without using a decoder or shift register to address all the LEDs. I've even ordered some ping pong balls to use as LED diffusers. :)

For now though, I'm calling this weekends endeavour finished.

Image Removed
1 comment ( 13400 views )   |  permalink   |  related link   |  $star_image$star_image$star_image$star_image$star_image ( 3 / 5762 )
Simple Kindle Temperature Display 
Thursday, February 7, 2013, 12:41
Posted by Administrator
I've been wanting to make an e-paper temperature display ever since seeing the beautiful weather forecast display that Matthew Petroff put together but as is my style I wanted to do something much simpler and easier to get running. My main self imposed requirement was to make something that would work on an unrooted device. With my kindle touch laying around mostly unused the last few weeks I finally got determined to put it to some better use around the apartment.

I started off with my old weather grabbing script to pull the current temperature information from Wunderground. Wunderground claims to be phasing out their API that I like, but it shouldn't be difficult to scrape another site once they finally can it. I cut out a lot of the extra information I had been grabbing before since I wanted to dedicate this display to just temperature information.

The revised bash script follows below:

#!/bin/bash
# Temperature Grabbing Bash Script From Wunderground
# Created by Spike Snell 2013

# Make sure there is an argument which could have a zip
if [ $# -lt 1 ] ; then
echo "Please include a zipcode as an argument such as: ./weather.sh 72703"
exit 1
fi

# Grab the Zipcode from the command line argument
zip=$1

url="http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=$zip"

# Grab the content from the Wunderground API
weather_wget=`wget -q $url -O -`
weather_xml=`echo "$weather_wget" | sed 's/<current_observation>.*//'`
weather=`echo "$weather_xml" | sed 's/></>\n</g'`

# Get the temperature in C
temp=`echo "$weather" | grep -e '<temp_c>' | \
sed -e 's/\t\t<temp_c>//' -e 's/<\/temp_c>//'`

# Print out all the information
echo $temp

# Write it to a gif
echo $temp | convert -pointsize 555 text:- n.gif


The biggest change in the code from the old one is that I'm now using imagemagick to do a convert on the temperature text into a gif file. This is because I found that the kindle's experimental web browser was very iffy about displaying very large fonts, it would work about 1/10th of the time. It was able to display a large picture great though.

This whole project was made much simpler than Matthew's by driving the process with the kindle's built in web browser. I have a server running a lamp stack that I like to use and put the previous shell script and the following php code up on.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="refresh" content="360" charset=UTF-8">
<META NAME="DESCRIPTION" CONTENT="A small temperature indicator to run as an art piece displaying degrees C.">
<META NAME="KEYWORDS" CONTENT="temperature,art,large,tool">
<title>Current Local Temperature Indicator</title>
</head>
<body bgcolor="#FFFFFF">
<h1>
<?php
$z = 72703;
if (isset($_GET['z'])) {
$z = $_GET['z'];
};
$t = `./t.sh $z`;
# convert to F
$f = $t*9/5+32;
echo $f;
?>
</h1>
<img src="n.gif">
</body>
</html>


All that was left to do was to point the kindle's browser towards the php file, this triggers the bash script, writes the image and does a simple conversion of C -> F degrees to display above the large C readout. Voila! A temperature readout, self updating every 6 minutes with a meta refresh. So now everything is finished, except the kindle has one last gotcha, it blanks the screen and displays a screensaver after about a 15 minute inactivity period. Luckily this can be easily disabled. At the home screen of the kindle you can enter "~ds". This will disable the screensaver until the device is restarted.

Now some glamour shots of the kindle temperature display in operation, along with a closeup of my tacky wall-mounting job.

Image Removed


Image Removed
add comment ( 5192 views )   |  permalink   |  $star_image$star_image$star_image$star_image$star_image ( 3 / 6001 )

<<First <Back | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Next> Last>>