There is a saying: "If all you have is a hammer, everything looks like a nail". Well, when I see a display, I think of clocks :)

I will show you here how to easily make a simple digital clock by hacking Meggy Jr RGB. This is an Arduino-programmable device, featuring an 8x8 RGB LED matrix, a few buttons and a buzzer. Ideal candidate for an alarm clock.

The clock will use the ubiquitous DS1307 as RTC (real-time-clock). This chip can be bought on ebay or digikey/mouser for about \$1.
You will ask why we need an RTC chip at all. Why can't we just count the seconds and calculate the minute, hour, day, week, month and year with the on-board ATmega328? Of course we can. We would only need to write and test a bunch of functions. But who is going to record the passing of time when the processor is not powered? DS1307 does all these for us: for only \$1 or so, it counts the seconds for as along as the coin battery lasts (which is a few years) and increments the minutes, hours, days etc., and even keeps track of leap years. All we need to do to get the current time is to ask the little frugal RTC chip for it.

Here are the requirements (or the few issues to think about):
1. build a small RTC breakout board ("BOB"), according to the datasheet (basically connecting the crystal and coin backup battery to the DS1307 chip);
2. make the RTC BOB fit somewhere nicely over the Meggy Jr board;
3. connect this RTC BOB to the Meggy Jr board, as cleanly as possible, with no wires soldered to the Meggy Jr board.

This tutorial will show how I solved these minor challenges.

In the end, the Meggy Jr clock will look and work as shown in this video:

## Step 1: The Parts

Beside a working Meggy Jr RGB, here is the complete list of things we will need for this project:
• DS1307 and a 8-pin socket;
• crystal (32768Hz);
• coin battery (CR1220) and a holder for it;
• a small piece of prototyping board;
• 2 pieces of 6-pin female header;
• a few wires.
Of course, we will also use a soldering iron, solder and desoldering wick (flux pen is also recommended).

## Step 2: Understanding the Challenges

As I said previously, there are few issues to think about, and especially:
• size and placement of the RTC BOB;
• connecting the RTC BOB to the Meggy Jr board only through the plug-in headers.

A bit of background.
DS1307 talks with a host processor on I2C interface, also known as "two wires". This interface uses two lines, named SDA and SCL.
DS1307 has a set of these (pins 5 and 6, respectively), as has ATmega328 (pins 27 and 28, respectively). We will need to connect these pins as shown in the attached schematic.

Meggy Jr board makes SDA and SCL available through the headers PC4 and PC5, highlighted in the image below.

To power the DS1307 chip we will also need the 5V line (Vcc) and the ground (GND). Since we don't want to solder wires to the Meggy Jr board, we will take them somehow from the FTDI connector, shown highlighted in the last image.

## Step 3: Preparing the Meggy Jr Board

To avoid soldering wires between the RTC BOB and Meggy Jr board, we will use headers, Arduino-style.
One of the headers will be placed in the freely available connections named "PC0" through "PC5". This header will provide access to SDA and SCL signals.
The second header will replace the FTDI connector and it will provide the necessary power (5V) and ground. We still need an FTDI connector to program the device, so we will re-create it on the RTC BOB.

So go ahead and carefully remove the FTDI connector. The desoldering wick comes handy in this case. Make sure you moist it with the flux pen before every use. After most of the solder is gone, the 6-pin header can be pulled out pin-by-pin, with some pliers. After the 6 holes are clean (use a safety pin to go through each hole, since the solder does not stick to it), place and solder the 6-pin female header.

After soldering both headers, the Meggy Jr board will look as shown in the photos below.

One more step is required here: connecting the 5V line to the "FTDI header", by soldering a short wire (a cut-off resistor terminal can be used) as shown in the diagram, with the red line.

## Step 4: Making the RTC BOB

This has been done millions of times before. What we will do specifically for the Meggy Jr hack, is soldering the male headers first.
Then we will place and solder the components in the remaining space.

The photos below show how I did it. But everybody is free to do it their own way.

The usual advice when soldering male headers is to have them plugged in. Place the small prototyping board, cut to fit between the edge of the board and the LED matrix, on top of the male headers and solder in place, pin by pin.

Then find a place for the new FTDI connector, as close as possible to the top header, so it is easy to connect each of the 6 pins.
Next, place the components in the remaining space and make the necessary wiring according to the datasheet/schematic.

Make sure that:
• the crystal is connected between pins 1 and 2;
• the 5V power line is connected to pin 8;
• the backup battery is connected to pin 3;
• pin 4 is connected to ground;
• pin 5 and 6 are wired to pins PC4 and PC5 of the bottom header;
• connect each of the 6 pins of the top header to their corresponding pins of the FTDI "replacement".

## Step 5: Put Together and Test

Plug the RTC BOB into the modified Meggy Jr.

Now, using the Arduino IDE, try to upload the test sketch for the DS1307 chip. This will test both the newly replaced FTDI connector and the RTC.

If the upload fails, check the pin-to-pin wiring between the new FTDI connector and the top header (use the soldering points on the bottom of the Meggy Jr board).

If the RTC monitor shows zeroes, indicating that the RTC is not working, first check that the backup battery is present. Then, check the wiring according to the schematic/datasheet.

After we made sure the newly installed RTC board works with Meggy Jr, upload the clock sketch. This is a quickly modified version of the scrolling sketch.

From this point on, new features can be added:
• user interaction through the buttons (the left-right arrows on the left side are not functional anymore, because the RTC took over their lines);
• support alarm functionality (user sets alarm time, alarm triggered etc);
• show the day of week through the row of separate LEDs.
You got my vote!!
Thank you!