Christmas Countdown Timer W/ An Lcd Display, Rtc And Meadow

Photo of jorgedevs

Made by jorgedevs

About the project

Use Meadow. Foundation to quickly and easily wire up a LCD screen and a RTC module to make a Christmas countdown display.

Project info

Difficulty: Easy

Platforms: MicrosoftMeadowWilderness Labs

Estimated time: 1 hour

License: Apache License 2.0 (Apache-2.0)

Items used in this project

Hardware components

Resistor Network - 10K Ohm (6-pin bussed) Resistor Network - 10K Ohm (6-pin bussed) x 1
Tiny Breadboard Tiny Breadboard x 1
Compute Modules 3+ Compute Modules 3+ 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

Software apps and online services

Microsoft Visual Studio 2019 Microsoft Visual Studio 2019

Story

In this project we're going to build a Christmas countdown display using a 20x4 LCD display and a RTC module connected to a Meadow F7 Micro. Most of the components needed to build this project is included in the Wilderness Labs Meadow F7 w/Hack Kit Pro.

The main objective of this project is to get familiar on how to wire up a display to Meadow, and see how easy is the API to display strings on an specific line, clear the screen, and more. Also we'll learn how to use a DS1307 Real Time Clock (RTC) module, so your clock will always be on time regardless if the project is running or not. The logic is using Meadow.Foundation to build the logic with ease.

Meadow.Foundation 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

For this project, wire up your breadboard and Meadow as shown in the Fritzing diagram:

Christmas Countdown Circuit

Christmas Countdown Circuit

Christmas Countdown Circuit

Step 2 - Create a Meadow Application project

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

Step 3 - Add the required NuGet packages

Windows

Right-click on the ChristmasCountdown project and click Manage NuGet Packages and install the following packages to our project:

Adding CharacterDisplay and DS1307 NuGet packages

Adding CharacterDisplay and DS1307 NuGet packages

Adding CharacterDisplay and DS1307 NuGet packages

macOS

Alt-click on the ChristmasCountdown project in the Solution Explorer, and click Add => Add Nuget Package to open the NuGet Package window. Search for the following packages and add them to the project:

Adding CharacterDisplay and DS1307 NuGet packages

Adding CharacterDisplay and DS1307 NuGet packages

Adding CharacterDisplay and DS1307 NuGet packages

Step 4 - Write the code for ChristmasCountdown

In the MeadowApp main class, copy the following code below:

using System;using System.Threading;using Meadow;using Meadow.Devices;using Meadow.Foundation.Displays.Lcd;using Meadow.Foundation.RTCs;namespace ChristmasCountdown{    public class MeadowApp : App<F7Micro, AnalogReadApp>    {        DS1307 rtc;        DateTime currentDate;        CharacterDisplay display;        public MeadowApp()        {            rtc = new DS1307(Device.CreateI2cBus());            // Uncomment only when setting the time            // rtc.SetTime(new DateTime(2019, 11, 23, 20, 19, 20));            display = new CharacterDisplay            (                device: Device,                pinRS: Device.Pins.D15,                pinE: Device.Pins.D14,                pinD4: Device.Pins.D13,                pinD5: Device.Pins.D12,                pinD6: Device.Pins.D11,                pinD7: Device.Pins.D10            );            StartCountdown();        }        void StartCountdown()        {            currentDate = rtc.GetTime();            display.WriteLine("Current Date:", 0);            display.WriteLine(rtc.GetTime().Month +                 "/" + rtc.GetTime().Day + "/" + rtc.GetTime().Year, 1);            display.WriteLine("Christmas Countdown:", 2);            while (true)            {                UpdateCountdown();                Thread.Sleep(60000);            }        }        void UpdateCountdown()        {            var date = rtc.GetTime();            var christmasDate = new DateTime(date.Year, 12, 25);            if (currentDate.Day != date.Day)            {                currentDate = date;                display.WriteLine(currentDate.Month + "/" +                     currentDate.Day + "/" + currentDate.Year, 1);            }            var countdown = christmasDate.Subtract(date);            display.WriteLine(countdown.Days + "d" +                 countdown.Hours + "h" + countdown.Minutes + "m to go!", 3);        }    }}

In the MeadowApp's constructor, we first create a DS3231 object (rtc) and we immediately set the current date and time. We only need to set the date and time once, since the RTC module will remain having the right time. Next we instanciate a CharacterDisplay object (display)

Lastly, in the StartCountdown() method, we use the WriteLine(string text, int lineNumber) method on the display to show strings on the screen, and in the infinite while loop, we subtract the current date with Christmas eve date to get the remaining time, and we call UpdateCountdown() method to format the remaining time and update the 4th line of the screen.

Step 5 - Run the project

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

ChristmasCountdown project running

ChristmasCountdown project running

ChristmasCountdown 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

ChristmasCountdown circuit diagram

Code

ChristmasCountdown complete project

You can check the complete project in our Meadow_Project_Samples repo

Credits

Leave your feedback...