Close
0%
0%

Micro Binary Clock

Using a Microbit and an RTC to create an Binary Clock with 2 display options.

Similar projects worth following
This project (actually two related projects), uses the Microbit and a RTC to construct a Binary Clock using the Microbit display and also an add on larger display that can be mounted on a table, shelf or wall. In addition an audible alarm function is included.

Although the display area is limited in the amount of data that can be shown at any one time, it lends itself ideally to the display of bit data.

As such there is sufficient area to display 4 x 4 bit binary words to represent time with notifications and selection modes.

The display is split into 3 main areas; Time, Selection and Modes.

Time

Sixteen LED's assigned to Time, each column of 4 LED's is assigned to a time interval, the intervals being in the form H, H, M & M.

Each bit of the Binary word has a weighting of 1, 2, 4 & 8 with the LSB on row 4 and the MSB on row 1

Each Binary 4 bit word allows a count of 0 to 15, which is more than sufficient for the 24H time format, requiring a maximum count per column of 2, 9, 5 & 9.

Selection

One row of 4 LED's at row 0 are used to identify the time column selected when entering time.

Modes

One column of 5 LED's at column 4 are used to identify Modes, Functions and Operation.

Tick - LED 4,0 flashing on & off is used to indicate Seconds and operation.

Time - LED 4,1 indicates Time mode when on. (Default mode at switch on)

Alarm - LED 4,2 indicated Alarm mode when on.

Alarm Notification - LED 4,3 & LED 4,4 flash when the Alarm is triggered.

The RTC is the beating heart of the application, allowing the setting & keeping of accurate time.

Further details of the RTC can be found at Kitronik.

The RTC provides a regulated supply negating the need to power the Microbit by its own USB or JST connector and battery backup is provided to retain the time in the event of power loss.

Before using the RTC you will need to load the Extension package.

Using Makecode from the Settings icon, select Extensions and type Kitronik RTC in the search.

Select the package to install it and it will be added to the other extensions.

There are a number of code blocks to read from and write to the RTC.

We will only require 4 of these code blocks for the Binary Clock.

These will be utilised to write the set time to the RTC and to read the time back to update the clock display.

The first part of the code is program initialisation of variables, arrays and informative text.

Init

Bclk – Binary Clock

<Sel - A button selects the column that will be adjusted for time setting.

>Inc – B button increments the time.

Pressing both A & B buttons together changes the mode between Time & Alarm.

Strval – is the string value containing the time in the form “HH:MM:SS” returned from the RTC

Only HH & MM are used to display or set the time.

Mode – retains the mode value for Time = 1 and Alarm = 2 selected with the A+B button combination.

Period – is the value for the time column, selected with the A button.

0 = column 0 (H), 1 = column 1 (H), 2 = column 2 (M), 3 = column 3 (M)

Tick_en – Enables = 1 or Disables = 0 the tick (seconds), indicator.

Inc – Intermediate storage of the incremental time setting value.

Tm_list[] – stores the value of each time column during setting.

Alarm – Enables or Disables the Alarm indicator.

The forever continually calls the tick function.

Tick

The tick function which is normally enabled, displays an alternating on/off LED in the top right hand corner to indicate operation and seconds.

Additionally, it calls the showtm function which reads the RTC and processes this to be displayed in binary, whilst also calling alarm_mode, if this is enabled displays the alarm notification LED’s in the bottom right hand corner.

Showtm

Function showtm, calls rdtime and the value used from this is strval containing the time string.

A loop is created which increments through strval extracting each single number and ignoring the separator “:”

Each single number is then converted into its binary equivalent with function dec2bin and assigned to the correct column.

Rdtime

Function rdtime, reads the first 5 characters in the string returned from the RTC (ignoring the seconds portion), and passes it to strval....

Read more »

bin_clk_on2.mp4

Video of operation

MPEG-4 Video - 32.29 MB - 02/25/2021 at 02:16

Download

hex - 1.45 MB - 02/25/2021 at 02:16

Download

  • 1 × Microbit V1 or V2
  • 1 × Kitronic RTC
  • 1 × SPDT (on - on) switch
  • 2 × SPST (normally open), momentary switch
  • 4 × M3 (10+6mm), M/F standoffs with M3 nuts

View all 9 components

  • 1
    Selection buttons and Alarm

    The Microbit will fit into the socket in two orientations, facing the main part of the RTC of facing away.

    If facing the main part of the RTC the link connections cannot be used however, if the Microbit is facing away from the main part of the board then we can make use of these connections.

    The assembly starts by soldering a right angle SIL pin header onto the RTC, this is to enable the connections to be made with push fit connectors.

    The RTC is fitted by 4 * M3 (10+6mm), M/F standoffs with M3 nuts which are secured to the lid with 4 * M3 (8mm), screws in the prefabricated holes.

    The switches are fitted in the prefabricated holes in the lid.

    The connections required are:

    GND, 3V, P1 (set), P2 (alert), P5 (sel) & P11 (inc)

    Note *** Resistors (1R), on the diagram for P5 & P11 are simply reference connection points as direct connection to these pins on the Microbit in Code blocks is not available at this time. ***

    P5 is the external connection for Button A which is connected by a SPST momentary switch. One connection to P5 and the other pin is connected to GND this button is for column selection during time setting.

    P11 is the external connection for Button B which is connected by a SPST momentary switch. One connection to P11 and the other pin is connected to GND his button is for number increment during time setting.

    P1 is a SPDT (on-on) switch which is used to enable or disable the setting options. The centre pin goes to P1 whilst one pin to connected to GND and the other to 3V via a 10k resistor. This enables a H (3V) and L (0V) to be applied to this pin. When P1 is connected to 3V this enables the time setting options and when 0V disables time setting. Thereby controlling whether the A & B buttons have any effect.

    P2 is a SPDT (on-off-on) switch which is used to enable or disable the alert sounder and optional external lights.

    The alert sounder is a Piezo Buzzer (simply affixed with a double sides sticky pad), requiring a pulse drive which is provided by the Microbit.

  • 2
    The main components

    Plug the Microbit into the RTC and power the RTC board via USB or the screw terminals.

    The Tick LED will start to flash and shortly after this the time will be displayed.

    If this is the first time of use the displayed time is very likely to be wrong and will need to be set to the correct time.

    Mode selection.

    Pressing the Selection (A) & Increment (B) buttons together will allow cycling of the Mode options between Time & Alarm.

    Setting the Time

    The time setting is in 24H mode.

    Use the Selection button (A), to move the LED across the top row, this indicates the column where the time can be changed. The selection columns correspond to H, H, M & M.

    Where H = Hours and M = Minutes.

    Having selected a column press the Increment button (b), repeatedly to increment the count by one on each press. The counts are indicated in binary, after all its a Binary Clock.

    The increment button only increases the count and once the maximum is reached resets to zero, further presses will again increase the count.

    Once the first column time is set, press the Selection button for the next column then use the Increment button to set the column time.

    Note: *** When you set the Time or Alarm you will need to enter a time in the selected column even if the time in the column is to remain unchanged as skipping a column sets that column time to zero ****

    Repeat the process until the time has been set using all 4 columns.

    Press the Selection button for the fifth time to move it to the fifth column and the time is set.

    Setting the Alarm

    Setting the Alarm time is done in exactly the same way as for the Time.

    In order for the Alarm to be triggered on the required time leave the Mode set to Alarm.

    To switch the Alarm off set the Mode to Time.

    To display the Alarm time set, cycle the Mode between Time and Alarm and the Alarm time will be displayed for a short period of time before reverting to displaying the current time.

    The Alarm time is not stored in the RTC, therefore if power is removed it will require resetting.

  • 3
    Box

    The project will sit at the appropriate angle to view the clock but a box adds a sense of permanence.

    You could buy a suitably sized box and cut and drill out the appropriate areas to allow the Microbit to fit in the socket.

    However; additionally I wanted to duplicate the Microbit buttons along with other controls and indicators.

    Typically, legends will need to be applied to the box to identify buttons.

    These could be applied by hand; painted, engraved or applying labels.

    A method to realise all these options would be to 3D print the box but first we would need to create a CAD file with which to create the printer file.

    The file creation options are hand drawn or drawn with code.

    I opted for "drawn with code" using Tinkercad CodeBlocks

    The files for the Box Lid and the Box Base can be found on Tinkercad CodeBlocks

View all 3 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates