Arduino digital clock

As free time project I’ve built a digital clock using Arduino Duemilanove, the DS1307 Real Time Clock, the MCP23017 port expander and a bunch of blue leds.

 

clock

 

Seven segment display

The idea is to show the current time using four 7 segment display, the display are built using some leds and a cardboard.

Each digit segment is realized using a blue led. The led is inserted in a hole partially covered with reflective material (I’ve used the internal part of a Tetra Pack container). The front part is covered with masking tape.

segment

Each digit has seven segments. The segments holes have been made in a cardboard using a stencil.

stencil

Controlling the seven segment display

The first two digits segments are controlled by the MCP23017 port expander, the other two are controlled directly using the Arduino ports.

The MCP23017 port expander can control 16 ports, the 16 ports are managed by two registry. The port expander is controlled by Arduino using I2C.MCP23017The single registry controls 8 ports and you can set which ports are ON or OFF using a byte. Each bit of the byte tells the port expander if the port should be ON or OFF.

For example in the following image you can see the registry turning ON leds 1 and 4 having his value set to 9.

leds1Here you can see the bits converted to the byte value 9:

I’ve used one registry for digit then I’ve left unused one port for registry.

In order to identify each segment they have been labeled as follow:

7_segment_display_labeled

“7 segment display labeled” by user:h2g2bob – Own work using Inkscape. Licensed under CC BY-SA 3.0 via Wikimedia Commons – https://commons.wikimedia.org/wiki/File:7_segment_display_labeled.svg#/media/File:7_segment_display_labeled.svg

Assigning each port to a single digit segment you have this mapping:

For example if you want to display the digit 2 you need to turn ON segments A, B, G, E and D.

7_segment_display_labeled_two

 

In order to do so you have to set the registry value to 91 (0x5B in HEX).

I wasn’t lucky and due to wires length and leds positions I had to connect the leds to the ports in a random order getting such mapping:

This random order required to “re-map” the segments before converting it as byte.

Here you can find a nice tutorial about the MCP23017 port expander.

The remaining two digit segments are controlled one by one using Arduino ports and standard digital write.

The time

The time is keep using the DS1307 RTC. The RTC is controlled through I2C and the RTC library.DS1307RTC

Schema

Here a schema of main components connections.

schema

The code

In the setup phase the program setup the I2C library, the RTC library and the Arduino ports.

In the loop phase it reads the current time value from the RTC and “print” it.

The hour value is split into two digits, each digit is mapped into a segments configuration then translated in a byte value for the registry. Finally the byte value is sent to the correct registry.

The minute value is split also into two digits, each digit mapped into a segments configuration and then each Arduino port set consequently.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.