# Metro Minimalist Clock

## Overview

https://youtu.be/8F8kPWR0KR8

![](https://cdn-learn.adafruit.com/assets/assets/000/043/402/medium800/adafruit_products_IMG_2559_2k_b.jpg?1499030826)

This Metro Mini microcontroller-based clock is a minimalist timepiece that celebrates, rather than hides, its components. It's a straightforward build, electronically, and it's up to you to house and display it any way you like!

You can build it onto a breadboard, a perma-proto board, or even wire it dead-bug style without a board at all.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/382/medium800/adafruit_products_IMG_2592_2k.jpg?1499027529)

## For this build you'll need:
### Part: Metro Mini Microcontroller
quantity: 1
Arduino-IDE compatible microcontroller!
[Metro Mini Microcontroller](https://www.adafruit.com/product/2590)

### Part: DS3231 breakout
quantity: 1
Real Time Clock breakout board
[DS3231 breakout](https://www.adafruit.com/product/3013)

### Part: 4 Digit 7-segment Display
quantity: 1
Clock display, pick any color!
[4 Digit 7-segment Display](https://www.adafruit.com/product/1002)

### Part: 5V USB Power supply
quantity: 1
We stock or use one you have around the house
[5V USB Power supply](https://www.adafruit.com/product/501)

### Part: Breadboard
quantity: 1
A full-size breadboard will give you plenty of workspace
[Breadboard](https://www.adafruit.com/product/239)

Optionally:

- Perma Proto board, or
- Female header pin strips, x2
- Colored filter gel, tape

Let's have a look at building the electronics next.

# Metro Minimalist Clock

## Clock Circuit

You can technically make a clock using only the Metro Mini and the display, but the clock&nbsp;would need to be re-set every time it looses power or is reset. It also isn't super accurate. That's where the real-time clock module comes in. It has a coin cell battery backup, and is a much more accurate timekeeper than the crystal onboard the Metro Mini.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/403/medium800/adafruit_products_metroMiniClock.png?1499036103)

First, solder on the male header pins for the Metro Mini, the [RTC module](../../../../adafruit-ds3231-precision-rtc-breakout/assembly), and the [display backpack](../../../../adafruit-led-backpack/0-dot-56-seven-segment-backpack). You can find more info by following the assembly notes linked here.

![adafruit_products_components_insertbatt.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/404/medium640/adafruit_products_components_insertbatt.jpg?1499036981)

![adafruit_products_led_matrix_7segsolder.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/405/medium640/adafruit_products_led_matrix_7segsolder.jpg?1499037069)

![adafruit_products_2590-06.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/406/medium640/adafruit_products_2590-06.jpg?1499037298)

Next, place the three boards onto the breadboard as seen in the diagram above.

Both the RTC module and the display can communicate with the Metro Mini over the I2C protocol, so there are only two pins&nbsp;for needed to connect them all for communications. Grab a breadboard, and then wire them this way:

- Metro Mini pin **A4** to RTC **SDA** to display **SDA&nbsp;**
- Metro Mini pin&nbsp; **A5&nbsp;** to RTC&nbsp; **SCL&nbsp;** to display&nbsp; **SCL**

The other wiring needed is common ground and 5V power among them all. Wire this:

- Metro Mini&nbsp; **5V&nbsp;** to RTC&nbsp; **Vin&nbsp;** to display&nbsp; **+**
- Metro Mini&nbsp; **GND&nbsp;** to RTC&nbsp; **GND&nbsp;** to display&nbsp; **-**

&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/043/410/medium800/adafruit_products_IMG_2559_2k_d.jpg?1499038448)

# Metro Minimalist Clock

## Code the Clock

I based my code off of Tony D's excellent [Arduino GPS Clock project](../../../../arduino-clock/software)&nbsp;and modified it to work with the specific hardware we're using here, as well as eliminating the GPS receiver code he used to auto-set the clock.

First, make sure you're comfortable using the Arduino IDE to upload code to your Metro Mini. You can [start here](../../../../adafruit-arduino-lesson-1-blink) if you aren't familiar with this, and make sure you can successfully upload the Blink sketch to your Mini.

Next, you'll add three libraries to your Arduino IDE,&nbsp;

Go to&nbsp; **Sketch \> Include library \> Manage libraries...&nbsp;** to open the&nbsp; **Library Manger.&nbsp;** Here, search for and install these three libraries:

- **Adafruit GFX Library**
- **Adafruit BusIO Library**
- **RTCLib by Adafruit**
- **Adafruit LED Backpack Library**

Now, you're ready to upload the clock code. Copy&nbsp;the code shown here, then paste it into a new Arduino sketch. Save the sketch as **metroMiniClock.ino** , and then upload it to your board.

```
// Clock example using a seven segment display &amp; DS3231 real-time clock.
//
// Must have the Adafruit RTClib library installed too!  See:
//   https://github.com/adafruit/RTClib
//
// Designed specifically to work with the Adafruit LED 7-Segment backpacks
// and DS1307 real-time clock breakout:
// ----&gt; http://www.adafruit.com/products/881
// ----&gt; http://www.adafruit.com/products/880
// ----&gt; http://www.adafruit.com/products/879
// ----&gt; http://www.adafruit.com/products/878
// ----&gt; https://www.adafruit.com/products/264
//
// Adafruit invests time and resources providing this open source code, 
// please support Adafruit and open-source hardware by purchasing 
// products from Adafruit!
//
// Written by Tony DiCola for Adafruit Industries.
// Released under a MIT license: https://opensource.org/licenses/MIT

#include &lt;Wire.h&gt;
#include &lt;Adafruit_GFX.h&gt;
#include &lt;RTClib.h&gt;
#include "Adafruit_LEDBackpack.h"


// Set to false to display time in 12 hour format, or true to use 24 hour:
#define TIME_24_HOUR      false

// I2C address of the display.  Stick with the default address of 0x70
// unless you've changed the address jumpers on the back of the display.
#define DISPLAY_ADDRESS   0x70


// Create display and DS1307 objects.  These are global variables that
// can be accessed from both the setup and loop function below.
Adafruit_7segment clockDisplay = Adafruit_7segment();
//RTC_DS1307 rtc = RTC_DS1307();
RTC_DS3231 rtc;

// Keep track of the hours, minutes, seconds displayed by the clock.
// Start off at 0:00:00 as a signal that the time should be read from
// the DS3231 to initialize it.
int hours = 0;
int minutes = 0;
int seconds = 0;

// Remember if the colon was drawn on the display so it can be blinked
// on and off every second.
bool blinkColon = false;


void setup() {
  // Setup function runs once at startup to initialize the display
  // and clock.

  // Setup Serial port to print debug output.
  Serial.begin(115200);
  Serial.println("Clock starting!");
  delay(3000); // wait for console opening

  // Setup the display.
  clockDisplay.begin(DISPLAY_ADDRESS);
  clockDisplay.setBrightness(15);
  // Setup the DS3231 real-time clock.
  rtc.begin();

  // Set the clock if it hasn't been set before.

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // following line sets the RTC to the date &amp; time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date &amp; time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  
  /*
  bool setClockTime = !rtc.isrunning();
  // Alternatively you can force the clock to be set again by
  // uncommenting this line:
  //setClockTime = true;
  if (setClockTime) {
    Serial.println("Setting DS3231 time!");
    // This line sets the DS1307 time to the exact date and time the
    // sketch was compiled:
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // Alternatively you can set the RTC with an explicit date &amp; time, 
    // for example to set January 21, 2014 at 3am you would uncomment:
    //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
*/
  
}

void loop() {
  // Loop function runs over and over again to implement the clock logic.
  
  // Check if it's the top of the hour and get a new time reading
  // from the RTC clock.  This helps keep the clock accurate by fixing
  // any drift.
  if (minutes == 0) {
    // Get the time from the DS3231.
    DateTime now = rtc.now();
    // Print out the time for debug purposes:
    Serial.print("Read date &amp; time from DS3231: ");
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    // Now set the hours and minutes.
    hours = now.hour();
    minutes = now.minute();
  }

  // Show the time on the display by turning it into a numeric
  // value, like 3:30 turns into 330, by multiplying the hour by
  // 100 and then adding the minutes.
  int displayValue = hours*100 + minutes;

  // Do 24 hour to 12 hour format conversion when required.
  if (!TIME_24_HOUR) {
    // Handle when hours are past 12 by subtracting 12 hours (1200 value).
    if (hours &gt; 12) {
      displayValue -= 1200;
    }
    // Handle hour 0 (midnight) being shown as 12.
    else if (hours == 0) {
      displayValue += 1200;
    }
  }

  // Now print the time value to the display.
  clockDisplay.print(displayValue, DEC);

  // Add zero padding when in 24 hour mode and it's midnight.
  // In this case the print function above won't have leading 0's
  // which can look confusing.  Go in and explicitly add these zeros.
  if (TIME_24_HOUR &amp;&amp; hours == 0) {
    // Pad hour 0.
    clockDisplay.writeDigitNum(1, 0);
    // Also pad when the 10's minute is 0 and should be padded.
    if (minutes &lt; 10) {
      clockDisplay.writeDigitNum(2, 0);
    }
  }

  // Blink the colon by flipping its value every loop iteration
  // (which happens every second).
  blinkColon = !blinkColon;
  clockDisplay.drawColon(blinkColon);

  // Now push out to the display the new values that were set above.
  clockDisplay.writeDisplay();

  // Pause for a second for time to elapse.  This value is in milliseconds
  // so 1000 milliseconds = 1 second.
  delay(1000);

  // Now increase the seconds by one.
  seconds += 1;
  // If the seconds go above 59 then the minutes should increase and
  // the seconds should wrap back to 0.
  if (seconds &gt; 59) {
    seconds = 0;
    minutes += 1;
    // Again if the minutes go above 59 then the hour should increase and
    // the minutes should wrap back to 0.
    if (minutes &gt; 59) {
      minutes = 0;
      hours += 1;
      // Note that when the minutes are 0 (i.e. it's the top of a new hour)
      // then the start of the loop will read the actual time from the DS1307
      // again.  Just to be safe though we'll also increment the hour and wrap
      // back to 0 if it goes above 23 (i.e. past midnight).
      if (hours &gt; 23) {
        hours = 0;
      }
    }
  }

  // Loop code is finished, it will jump back to the start of the loop
  // function again!
}
```

Make sure under the&nbsp; **Tools -\> Board** &nbsp;menu the **Adafruit&nbsp;**** Metro **&nbsp;is selected, and under the&nbsp;** Tools -\> Port **&nbsp;menu the serial port for the** Metro Mini **&nbsp;is selected.&nbsp;Then press the upload button or click the&nbsp;** Sketch -\> Upload**&nbsp;item to send the code to the board.&nbsp;

Once uploaded, the **Metro Minimalist Clock** will start up, and display the time! You can now unplug the USB cable from the computer, and plug it into a wall adapter -- it only needs to get the time from the computer once, from now on it will maintain correct time from the RTC module. Even when unplugged, the RTC clock's battery will keep it ticking.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/419/medium800/adafruit_products_IMG_2559_2k_c.jpg?1499045247)

If you'd like you can change whether the clock displays time in 24-hour or 12-hour time format by slighting changing the sketch code. &nbsp;By default the clock uses 12-hour format and it's set by this line:

```
// Set to false to display time in 12 hour format, or true to use 24 hour:
#define TIME_24_HOUR      false
```

If you'd like to use 24-hour time change the line to set the define as true, like:

```
// Set to false to display time in 12 hour format, or true to use 24 hour:
#define TIME_24_HOUR      true
```

Primary: 

# Metro Minimalist Clock

## Display the Clock

You can use your Metro Minimalist Clock as is, on the breadboard. Or, for a slightly more permanent look, go ahead and solder it onto a Perma Proto breadboard, using the same wiring pattern as before. You can get really minimal and creative with your design by doing a bit of "dead bug" soldering with a couple of strips of female header as seen here.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/420/medium800/adafruit_products_deadBug.jpg?1499045513)

All of the same connections are being made as before on the breadboard, only now the relevant pins of the female header strips are connected&nbsp;to each other with short lengths of thin wire.

# Display Stand

I decided to reuse a short length of hardwood flooring as a display&nbsp;for my Metro Minimalist Clock. This video shows the process, which involved measuring and drilling holes, screwing the electronics in place with 2.5mm nylon standoffs, and gluing on a small stand.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/421/medium800/adafruit_products_IMG_2563_2k.jpg?1499048561)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/422/medium800/adafruit_products_IMG_2564_2k.jpg?1499048592)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/423/medium800/adafruit_products_IMG_2567_2k.jpg?1499048599)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/424/medium800/adafruit_products_IMG_2570_2k.jpg?1499048604)

In the end, I decided to cover the raw display with a small piece of purple gel&nbsp;filter -- this helps increase the contrast of the lit segments vs. the unlit ones. Plus, purple is pretty.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/425/medium800/adafruit_products_IMG_2580_2k.jpg?1499048642)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/426/medium800/adafruit_products_IMG_2583_2k.jpg?1499048652)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/427/medium800/adafruit_products_IMG_2584_2k.jpg?1499048658)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/428/medium800/adafruit_products_IMG_2586_2k.jpg?1499048667)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/429/medium800/adafruit_products_IMG_2591_2k.jpg?1499048673)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/430/medium800/adafruit_products_IMG_2592_2k.jpg?1499048678)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/472/medium800/adafruit_products_beautyMetroMinimalistClock.jpg?1499197252)


## Featured Products

### Adafruit Metro Mini 328 V2 - Arduino-Compatible - 5V 16MHz

[Adafruit Metro Mini 328 V2 - Arduino-Compatible - 5V 16MHz](https://www.adafruit.com/product/2590)
One of our star development boards is the&nbsp; **Adafruit METRO Mini 328** , an excellent lil fellow that lets you&nbsp;make your Arduino-based project tiny.&nbsp;&nbsp;Recently we had to redesign this board to move from the obsolete CP2104 to the available CP2102N, and one thing...

In Stock
[Buy Now](https://www.adafruit.com/product/2590)
[Related Guides to the Product](https://learn.adafruit.com/products/2590/guides)
### Adafruit DS3231 Precision RTC Breakout

[Adafruit DS3231 Precision RTC Breakout](https://www.adafruit.com/product/3013)
The datasheet for the **DS3231** explains that this part is an "Extremely Accurate I²C-Integrated RTC/TCXO/Crystal". And, hey, it does exactly what it says on the tin! This **Real Time Clock (RTC)** is the most precise you can get in a small, low power...

In Stock
[Buy Now](https://www.adafruit.com/product/3013)
[Related Guides to the Product](https://learn.adafruit.com/products/3013/guides)
### Adafruit 0.56" 4-Digit 7-Segment Display w/I2C Backpack - White

[Adafruit 0.56" 4-Digit 7-Segment Display w/I2C Backpack - White](https://www.adafruit.com/product/1002)
What's better than a single LED? Lots of LEDs! A fun way to make a small display is to use an [8x8 matrix](https://www.adafruit.com/category/37_88) or a [4-digit 7-segment display](https://www.adafruit.com/category/37_103). Matrices like these are...

In Stock
[Buy Now](https://www.adafruit.com/product/1002)
[Related Guides to the Product](https://learn.adafruit.com/products/1002/guides)
### Adafruit Perma-Proto Full-sized Breadboard PCB - Single

[Adafruit Perma-Proto Full-sized Breadboard PCB - Single](https://www.adafruit.com/product/1606)
Customers have asked us to carry basic perf-board, but we never liked the look of most basic perf: it's always crummy quality, with pads that flake off and no labeling. Then we thought about how people **actually** prototype - usually starting with a solderless breadboard and...

In Stock
[Buy Now](https://www.adafruit.com/product/1606)
[Related Guides to the Product](https://learn.adafruit.com/products/1606/guides)
### Full Sized Premium Breadboard - 830 Tie Points

[Full Sized Premium Breadboard - 830 Tie Points](https://www.adafruit.com/product/239)
This is a 'full-size' premium quality breadboard, 830 tie points. Good for small and medium projects. It's 2.2" x 7" (5.5 cm x 17 cm) with a standard double-strip in the middle and two power rails on both sides. You can pull the power rails off easily to make the...

In Stock
[Buy Now](https://www.adafruit.com/product/239)
[Related Guides to the Product](https://learn.adafruit.com/products/239/guides)
### 36-pin 0.1" Short Female Header - Pack of 5

[36-pin 0.1" Short Female Header - Pack of 5](https://www.adafruit.com/product/3008)
In this world nothing can be said to be certain, except we need headers, headers, and more headers!

**Each pack contains five 36-pin short female&nbsp;headers, 0.1" pitch. These headers are very short for fitting into tight spaces with a height of&nbsp;just 5mm instead of...**

Out of Stock
[Buy Now](https://www.adafruit.com/product/3008)
[Related Guides to the Product](https://learn.adafruit.com/products/3008/guides)
### 5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable

[5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable](https://www.adafruit.com/product/1995)
Our all-in-one 5V 2.5 Amp + MicroUSB cable power adapter is the perfect choice for powering single-board computers like Raspberry Pi, BeagleBone, or anything else that's power-hungry!

This adapter was specifically designed to provide 5.25V, not 5V, but we still call it a 5V USB...

In Stock
[Buy Now](https://www.adafruit.com/product/1995)
[Related Guides to the Product](https://learn.adafruit.com/products/1995/guides)
### Black Nylon Machine Screw and Stand-off Set – M2.5 Thread

[Black Nylon Machine Screw and Stand-off Set – M2.5 Thread](https://www.adafruit.com/product/3299)
Totaling 380 pieces, this **M2.5 Screw Set** &nbsp;is a must-have for your workstation.&nbsp;You'll have enough screws, nuts, and hex standoffs to fuel your maker tendencies&nbsp;for days on end! M2.5 size screws fit almost all of the Adafruit breakout/dev board mounting holes...

In Stock
[Buy Now](https://www.adafruit.com/product/3299)
[Related Guides to the Product](https://learn.adafruit.com/products/3299/guides)

## Related Guides

- [Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack.md)
- [USB to Eurorack Power Supply](https://learn.adafruit.com/usb-to-eurorack-power-supply.md)
- [Remote Control Candy Dispenser Ghost](https://learn.adafruit.com/ble-claw.md)
- [Chilled Drinkibot](https://learn.adafruit.com/chilled-drinkibot.md)
- [Feather Scorpio Snap Fit Case](https://learn.adafruit.com/feather-scorpio-snap-fit-case.md)
- [NeoPixel Menorah](https://learn.adafruit.com/neopixel-menorah.md)
- [Espresso Water Tank Meter](https://learn.adafruit.com/espresso-water-tank-meter.md)
- [Split Ortho Keyboard with TCA8418 Matrix Expanders](https://learn.adafruit.com/split-ortho-keyboard.md)
- [Mindfulness Clock OF DOOM](https://learn.adafruit.com/mindfulness-clock-of-doom.md)
- [Square NeoPixel Display with Black LED Acrylic](https://learn.adafruit.com/sqaure-neopixel-display-with-black-led-acrylic.md)
- [3D Printed Case for Adafruit Feather](https://learn.adafruit.com/3d-printed-case-for-adafruit-feather.md)
- [Computer Space Mini Arcade](https://learn.adafruit.com/computer-space-mini-arcade.md)
- [Robotic AI Bear using ChatGPT](https://learn.adafruit.com/robotic-ai-bear-using-chatgpt.md)
- [How to Make Animated Graphics for Hologram Displays](https://learn.adafruit.com/how-to-make-animated-graphics-for-hologram-displays.md)
- [reef-pi Guide 2: Power Controller](https://learn.adafruit.com/reef-pi-power-controller.md)
- [Sandblaster - 3D printed sand buggy](https://learn.adafruit.com/sandblaster-3d-printed-sand-buggy.md)
