Build A Clock With Meadow's Onboard Real Time Clock Chip

Photo of jorgedevs

Made by jorgedevs

About the project

Build your own clock with an LCD display, a couple of Push Buttons and a Meadow F7 board and its onboard RTC, all using full.NET and C#.

Project info

Difficulty: Easy

Platforms: MicrosoftSparkFunMeadowWilderness Labs

Estimated time: 1 hour

License: MIT license (MIT)

Items used in this project

Hardware components

Tiny Breadboard Tiny Breadboard x 1
Resistor Network - 10K Ohm (6-pin bussed) Resistor Network - 10K Ohm (6-pin bussed) x 1
Resistor 10K Ohm 1/4 Watt PTH - 20 pk Resistor 10K Ohm 1/4 Watt PTH - 20 pk x 2
Momentary Pushbutton Switch - 12mm Square Momentary Pushbutton Switch - 12mm Square x 2
Raspberry Pi 4 Model B 1GB, 2GB, 4GB or 8GB RAM Raspberry Pi 4 Model B 1GB, 2GB, 4GB or 8GB RAM x 1
Tiny Breadboard Tiny Breadboard x 1
Jumper Wire Kit - 140pcs Jumper Wire Kit - 140pcs x 1
Raspberry Pi 4 Model B 1GB, 2GB, 4GB or 8GB RAM Raspberry Pi 4 Model B 1GB, 2GB, 4GB or 8GB RAM x 1

View all

Software apps and online services

Microsoft Visual Studio 2019 Microsoft Visual Studio 2019

Story

In the latest beta release on Meadow.OS, we now have access to the onboard Real Time Clock module, which is saves us ports and extra hardware for applications where we need to keep the time for logging or set alarms to do a certain task, etc.

In this project we're going to learn how to make a simple clock using a 20x4 characters LCD display and a couple of push buttons. Everything you need to build this project is included in the Wilderness Labs Meadow F7 w/Hack Kit Pro. We'll see how easy is to program these peripherals using Meadow.Foundation.

Meadow.Foundation a platform for quickly and easily building connected things using.NET on Meadow. Created by Wilderness Labs, it's completely open source and maintained by the Wilderness Labs community.

If you're new working with Meadow, I suggest you go to the Getting Started w/ Meadow by Controlling the Onboard RGB LED project to properly set up your development environment.

Step 1 - Assemble the circuit

Wire your project like this:

Fritzing Diagram for Meadow Clock project

Fritzing Diagram for Meadow Clock project

Fritzing Diagram for Meadow Clock project

Step 2 - Create a Meadow Application project

Create a new Meadow Application project in Visual Studio 2019 for Windows or macOS and name it MeadowClock.

Step 3 - Add the required NuGet packages

Windows

Right-click on your MeadowClock project and click Manage NuGet Packages. In the Browse tab, search for Meadow.Foundation.Displays.LCD.CharacterDisplay and click Install to add it to your project.

macOS

Alt-click on your MeadowClock project in the Solution Explorer, and click Add => Add Nuget Package to open the NuGet Package window. Search for Meadow.Foundation.Displays.LCD.CharacterDisplay and click Install to add it to your project.

Step 4 - Write the code for MeadowClock

Copy the following code below:

public class MeadowApp : App<F7Micro, MeadowApp>{    PushButton minute;    PushButton hour;    CharacterDisplay display;    public MeadowApp()    {        hour = new PushButton(Device, Device.Pins.D15);        hour.Clicked += HourClicked;        minute = new PushButton(Device, Device.Pins.D12);        minute.Clicked += MinuteClicked;        display = new CharacterDisplay        (            device: Device,            pinRS: Device.Pins.D10,            pinE: Device.Pins.D09,            pinD4: Device.Pins.D08,            pinD5: Device.Pins.D07,            pinD6: Device.Pins.D06,            pinD7: Device.Pins.D05        );        Device.SetClock(new DateTime(2020, 04, 01, 11, 00, 00));        CharacterDisplayClock();    }    void HourClicked(object sender, EventArgs e)    {        Device.SetClock(DateTime.Now.AddHours(1));    }    void MinuteClicked(object sender, EventArgs e)    {        Device.SetClock(DateTime.Now.AddMinutes(1));    }    void CharacterDisplayClock()    {        display.Clear();        display.WriteLine($"Meadow RTC is now", 0);        display.WriteLine($"available in b3.9", 1);        while (true)        {            DateTime clock = DateTime.Now;            display.WriteLine($"{clock:MM}/{clock:dd}/{clock:yyyy}", 2);            display.WriteLine($"{clock:hh}:{clock:mm}:{clock:ss} {clock:tt}", 3);            Thread.Sleep(1000);        }    }}

Meadow Constructor

The app initializes both the push buttons, which one increases the clock by an hour and the other increases the clock by a minute on each press. The interface to adjust the time could be more sophisticated, but I opted to keep it simple for the purpose of this project.

Then initializes the LCD display (CharacterDisplay), and we finally call Device.SetClock(DateTime dateTime); method to initialize the date and time on Meadow.

CharacterDisplayClock

This method clears the screen, writes a couple of strings on the first and second line of the display, and finally enters an infinite while loop, where every second refreshes the Date and Time on the third and fourth line. Note that to write text on the display, you simply call the WriteLine(string text, int line); API method.

Step 5 - Run the project

Click the Run button in Visual Studio. It should look like to the following GIF:

MeadowClock project running...

MeadowClock project running...

MeadowClock project running...

Check out Meadow.Foundation!

This project is only the tip of the iceberg in terms of the extensive exciting things you can do with Meadow.Foundation.

  • It comes with a huge peripheral driver library with drivers for the most common sensors and peripherals.
  • The peripheral drivers encapsulate the core logic and expose a simple, clean, modern API.
  • This project is backed by a growing community that is constantly working on building cool connected things and are always excited to help new-comers and discuss new projects.

References

Schematics, diagrams and documents

Clock circuit diagram

Code

MeadowClock complete project

You can check the TemperatureMonitor project in Meadow.Samples/Source/MeadowClock

Credits

Leave your feedback...