Introduction: RPi Pixel Clock

What is a Pixel Clock? I define a Pixel Clock as an electronic timepiece that displays the current time in a non-traditional way, using pixels in a unique format (and not using alpha-numeric characters).

Building a Pixel Clock is straightforward, rewarding and easy. Notice I did not say 'simple' or 'fast' - it's taken me a fair bit of effort to realize this project. However, I hope this instructable shortens your development time should you decide to build a Pixel Clock. You'll need just a handful of components: a Raspberry Pi (RPi), an 8x8 Bi-Color LED Matrix, a few resistors and a little bit of software.

Note: this instructable requires that you use a soldering iron to connect some of the hardware components. If you don't have basic soldering skills, you will need to ask a friend or colleague to solder one or two components on your behalf.

Note: I assume that your RPi has an active WiFi connection. This is important because the Python script fetches the current local time from WiFi and translates it onto the 8x8 Bi-Color Matrix. The RPi does 'NOT KNOW' the current time by itself. Ensure that you have an active WiFi connection. For example, if you are using a RPi3, then you have built-in WiFi capability. For example, if you are using a RPi2 or RPi0, then you will have to purchase a USB WiFi solution.

I wrote a Python script to control the Pixel Clock and is included in this instructable. The Raspbian operating system includes Python, so all you really have to do is copy my Python script to your RPi and execute it. I have added comments to the source code natively. I have added notes to the Python script so that you can understand why I made certain design decisions. If you have never run a Python script before, navigate to www.python.org for excellent tutorials and reference information.

So let's get to it!!!

Step 1: Quiz: Guess the Time

Quiet down, take your seats and put your phones away -- it is time for a quiz. Consider the picture and guess the time that each Pixel Clock represents. I have also included a written hint to assist you. If you can correctly guess the time for each of the four examples, then, congratulations, you are very close to understanding how I designed my Pixel Clock.

Step 2: Pixel Clock : Digits As Pixels

The Pixel Clock displays time using pixels for digits. If the Hour digit is "1" (either 1pm or 1am), then the Pixel Clock displays one red pixel. If the 10's Minute digit is "5", then the Pixel Clock displays a group of four green pixels and one additional green pixel for a total of five green pixels. If the 1's Minute digit is "9", then the Pixel Clock displays two groups of four green pixels and one addition green pixel for a total of nine green pixels.

Step 3: Pixel Clock: Frequent Updates

My Pixel Clock updates every five seconds and randomly displays the current time on the 8x8 Bi-Color LED Matrix. The Hour digit randomly moves up or down (but never left or right) at every refresh.

Note: If the Hour digit is '10', '11' or '12' (am or pm), then the Hour digit completely fills the Hour column and will stay fixed until the current time becomes '1' (am or pm).

The 10's and 1's Minute digit randomly moves up or down (but never left or right) at every refresh.

Note: The 3rd and the 6th columns are never illuminated. The 3rd column separates the Hour digit and the 10's Minute digit. The 6th column separates the 10's Minute digit and the 1's Minute digit.

Taken together, my Pixel Clock displays the Hour digit, a blank column, the 10's Minute digit, a blank column and the 1's Minute digit. The image for this step shows various time representations of 5:42am or 5:42pm.

Step 4: Purchase Hardware (Option 1: Prototype)

You will need to purchase the following hardware components to build your Pixel Clock. There are two options: Prototype and Project. Regardless of the option you choose, these components are inexpensive and can be purchased quite easily from internet vendors.

Option 1: Prototype

  1. Raspberry Pi Zero (www.adafuit.com/products/2885)
  2. Female GPIO Header (www.adafruit.com/products/2222)
  3. 8x8 Bi-Color LED Matrix (www.adafruit.com/products/902)
  4. C4Labs Breadboard (www.adafuit.com/products/3004)
  5. Hook-up wires, male-to-male (www.adafruit.com/products/1956)
  6. Two 10k-ohm resistors (www.adafruit.com/products/2784)
  7. OTG Micro USB Cable (www.adafruit.com/products/1099)
  8. WiFi Adapter for RPi (www.adafruit.com/products/814)

There are many ways that you can create a Pixel Clock Prototype using various hardware components. Above, I have found every hardware component at www.adafruit.com. But, many of these hardware components can be bought at other vendors. For example, I strongly favor the "Inland" OTG Micro USB Cable (SKU: 900365) available at MicroCenter. I strongly favor the Edimax N150 WiFi Nano USB Adapter (SKU: 879528) available at MicroCenter. Many DIY and Raspberry Pi Zero enthusiasts will recommend the 2x20 Dual Male Header (www.adafruit.com/products/2822) to mate with a Raspberry Pi Zero. I prefer the Female version (www.adafruit.com/products/222) especially with the C4Labs Breadboard. I prefer the Female version so that I can use male-to-male hook-up wires consistently across my DIY projects. The Female Header fits snugly in the C4Labs Breadboard, making this solution a favorite in my toolbox.

Of course, you can use a Raspberry Pi 3 or a Raspberry Pi 2 in your Pixel Clock prototype. You will then need female-to-male Hook-up wires (www.adafruit.com/products/825). You can use a Raspberry Pi 3 in your Pixel Clock Prototype. You will not need the OTG Micro USB Cable or WiFi Adapter for RPi because the Raspberry Pi 3 includes WiFi support in that product.

Regardless of your choice, you only need a small number of hardware components to create your Pixel Clock Prototype. If you prefer a more permanent solution, then I suggest you consider Option 2 in the next instruction.

Step 5: Purchase Hardware (Option 2: Project)

Option 2: Project

In this option, you will be mounting the 8x8 Bi-Color LED Matrix and Raspberry Pi Zero to an acrylic picture frame using nylon screws, spacers and hex nuts. The 8x8 Bi-Color LED Matrix has four smaller mounting holes (#56, below). The Raspberry Pi Zero has four larger mounting holes (#40, below). You will need spaces to separate the two components from the acrylic picture frame.

All of the hardware components in "Option 1: Prototype", and the following:

  1. Acrylic Picture Frame (an inexpensive 3.5"x5" or 4"x6" free-standing picture frame)
  2. Small perf-board, proto-board or bread-board
  3. Four Nylon Screws 2-56x3/4" Round SL (Waldom FN-883-0025P, 16048, EV9881)
  4. Four Nylon Hex Nuts 2-56 (Waldom FN-853-0025P, 16102, EY7910)
  5. Four Nylon Screws 4-40x3/4" Round (Waldom FN-887-0025P, 15096, EG1575)
  6. Four Nylon Hex Nuts 4-40 (Waldom 0 10151 76434 8, 15229, EM1859)
  7. Round Nylon Spacer #4 (Micro Connectors Inc.)

Step 6: Assemble Pixel Clock

Follow the instructions, below to assemble your Pixel Clock.

I have included a (1) Wiring Diagram and a (2) Schematic Diagram, both of which may help you assemble your Pixel Clock, regardless of the Option you choose. If you are building the Pixel Clock Project, I have also created a 3.5"x5" PDF template that includes drill hole locations that you can use with your acrylic photo stand.

Option 1: Prototype

  1. Attach the 8x8 Bi-Color LED Matrix to the left side of the breadboard.
  2. Add two pull-up resistors to the I2C Clock and I2C Data lines.
  3. Attach the hook-up wires to the RPi header as shown.

Option 2: Project

  1. Print the 3.5"x5" PDF template onto a piece of paper. Use scissors to trim the paper to yield a 3.5"x5" template. Insert the template into the acrylic photo stand.
  2. You probably want to trim the acrylic photo stand back plate using a Dremel tool or small saw.
  3. Use a drill to drill holes as indicated on the 3.5"x5" PDF template.
  4. Mount the 8x8 Bi-Color LED Matrix so that the terminals are facing 'East' using the nylon screws and hex nuts.
  5. Mount the RPi Zero so that the header is facing 'West' using the nylon screws and hex nuts.
  6. Add two pull-up resistors to the I2C Clock and I2C Data lines.
  7. Attach the hook-up wires to the RPi header as shown.

Once you complete these steps, you have successfully assembled your Pixel Clock. Now, you can shift your focus from Hardware to Software. Honestly, assembling your Pixel Clock requires patience, time and effort. Now comes the easy part: Software.

Step 7: Drill Mounting Holes (Option 2: Project)

If you are creating the Pixel Clock Project, then you will be drilling mounting holes into a 3.5"x5" or 4"x6" acrylic picture frame. You can use the attached document, 20161126 Pixel Clock Drill Template.pdf, to aid you when drilling mounting holes. Simply print attached document onto an 8.5"x11" piece of paper and cut out the 3.5"x5" template or the 4"x6" printed on the piece of paper. Then, slide the 3.5"x5" template into the 3.5"x5" acrylic picture frame, or, the 4"x6" template into the 4"x6" picture frame.. You may want to tape the paper to the frame temporarily to prevent the paper from moving into the frame.

Note: Most if not all acrylic picture frames have a close-fitting second acrylic pane running behind the picture frame to keep the picture close to the front of the picture frame. You will have to use a fine saw or rotary tool to remove the close-fitting second acrylic pane. This leaves a smooth, rounded top to the picture frame.

Using a precision tool, drill four holes for the 8x8 Bi-Color LED Matrix and four holes for the Raspberry Pi Zero.

Note: Acrylic may emit an undesirable odor when drilled. Ensure you are working in a well ventilated area if odors bother you.

Once you have drilled the mounting holes, you may remove and discard the paper template.

Step 8: Configure RPi and Enable I2C

Your RPi likely does not enable I2C by default, so you must configure your RPi and enable I2C before exercising your Pixel Clock..

Here, I must make a few assumptions. I assume that you are somewhat familiar with Raspberry Pi, the Raspbian Operating System and the RPi configuration tool, raspi-config. If you are not familiar with these concepts, navigate to www.raspberrypi.org for excellent tutorials and instructions. Don't be discouraged! All engineering requires courage in the face of the unknown. The only barrier to learning is a little time and effort. I have made many mistakes in creating this Pixel Clock. But I learned from my mistakes and persevered.

There exists an excellent tutorial that shows how you can enable I2C on your Raspberry Pi at Adafruit (www.adafruit.com). Navigate to https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c. Following the instructions. You will need to run "sudo raspi-config". You will need to update your boot.txt configuration file. Execute the command, "sudo i2cdetect -y 0", as instructed. You will need to reboot your Raspberry Pi.

Step 9: Test Your I2C Connection

This is a valuable tip that may prevent hours of frustration! If you have you assembled your Pixel Clock and connected the 8x8 Bi-Color LED Matrix to your RaspberryPi, you can use issue a terminal command to confirm that your connection to the matrix is valid. The command is "sudo i2cdetect -y 0", where "sudo" is 'super-user do', "i2cdetect" is the execution code that checks your I2C connection, "-y" executes the code without end-user interaction and "0" is I2C port 0 and is valid for Raspberry PI devices with 512MB or more RAM such as the Raspberry Pi Zero and Raspberry Pi 3.

sudo i2cdetect -y 0

When I issue this terminal command I get the following output information, which confirms that my Raspberry Clock is correctly communicating via I2C with the 8x8 Bi-Color LED Matrix.

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --

Notice the value, 0x70 in the table, above? This terminal command output is reporting that the Raspberry PI has found a device on I2C port 1 with the address, 0x70. The 8x8 Bi-Color LED Matrix with I2C backpack has a default address of 0x70. So, if you see this, rejoice, your hardware setup is confirmed and you can move on. If you don't see this, then you will need to troubleshoot your hardware setup by carefully reviewing the previous steps.

Step 10: Test This Python Code

In this step, you will test your Python Code.

I will suggest that you create a directory to hold your Python scripts. In your Terminal, issue the following commands:

pi@raspberrypi:~ $ ls
Desktop Documents Downloads export logs Music Pictures Public python_games
pi@raspberrypi:~ $ mkdir python
pi@raspberrypi:~ $ ls
Desktop Documents Downloads export logs Music Pictures Public python python_games
pi@raspberrypi:~ $ cd python
pi@raspberrypi:~/python $

Notice that you have created the directory, python, and have navigated to that directory.

Now, you will want to create a Python script and paste the following source code into that script and save it.

Once you have done so, you will then need to execute your Python script.

python PixelClock.py

Now check your 8x8 Bi-Color LED Matrix. Do you see bit patterns on the screen?

If all is well, then you will see bit patterns representing the current time and updating every 5 seconds.

Step 11: Summary and "Thank You"

Thank you for reviewing my first instructable.

I welcome your constructive suggestions to improve my design.

I also welcome your questions should you have difficulty constructing your own Pixel Clock.

Until next time...

Comments

author
rodmorehead (author)2017-01-02

Very nice instructable, the detailed parts list and code are both very well done.

I did have on suggestion in regards to the code...there is a slim chance that at the top of an hour the minute and hour could be from different hours, thus displaying a later time (for example, display 12:59 when minute was retrieved at 11:59 and hour was retrieved at 12:00).

I would suggest using time.localtime() to get the time "set", then pulling out the parts you need:

curTime = time.localtime()

curMinu = curTime.tm_min

curHour = int(time.strftime("%I", curTime))

author
DIY Hacks and How Tos (author)2016-12-18

Cool. I need something like this for my office desk.

author

Mounting a Pixel Clock in an inexpensive acrylic picture frame is an attractive solution for any desk. The picture frame 'angle' is almost ideal. Also, the pixel patterns are discernable at a distance..

About This Instructable

1,443views

25favorites

License:

Bio: I am very interested in technology and have been my entire life. Formally trained in electrical engineering, I have broad interests, but thoroughly enjoy DIY ... More »
More by jhaletx:RPi Pixel Clock
Add instructable to: