Build A Clock With Meadow's Onboard Real Time Clock Chip
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: Microsoft, SparkFun, Meadow, Wilderness Labs
Estimated time: 1 hour
License: MIT license (MIT)
Items used in this project
Hardware components
View all
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 circuitWire your project like this:
Fritzing Diagram for Meadow Clock project
Fritzing Diagram for Meadow Clock project
Step 2 - Create a Meadow Application projectCreate a new Meadow Application project in Visual Studio 2019 for Windows or macOS and name it MeadowClock.
Step 3 - Add the required NuGet packagesWindows
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 MeadowClockCopy 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.
Click the Run button in Visual Studio. It should look like to the following GIF:
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.
Leave your feedback...