Project updated to beta 6.2 (released on March 5th, 2022)
In this project we're going to build a Christmas countdown display using a 20x4 LCD display connected to a Meadow F7 Micro. You can get this display and more sensors to build more projects by getting a Wilderness Labs Meadow F7v2 w/Hack Kit Pro.
The main objective of this project is to get familiar on how to wire up a 20x4 display to Meadow, and see how easy is the API to display strings on an specific line, clear the screen, and more using Meadow.Foundation. With beta 6.0 released, we can now make Meadow join our WIFI network and get the UTC date and time automatically at startup with two simple configuration files.
Meadow.Foundation is a platform for quickly and easily build 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 circuitFor this project, wire up your breadboard and Meadow as shown in the Fritzing diagram:
Create a new Meadow Application project in Visual Studio 2019 for Windows or macOS and name it ChristmasCountdown.
Step 3 - Add the required NuGet packagesFor this project, search and install the following NuGet packages:
Step 4 - Add Configuration Files (if missing)In your project, create and add the following configuration files:
meadow.config.yaml
# Acceptable values for true: true, 1, yes
# Acceptable values for false: false, 0, no
#===============================================================================
# main device config
Device:
# Name of the device on the network.
Name: ChristmasCountdown
#===============================================================================
# Network configuration.
Network:
# Automatically attempt to get the time at startup?
GetNetworkTimeAtStartup: 1
# Time synchronization period in seconds.
NtpRefreshPeriod: 600
# Name of the NTP servers.
NtpServers:
- time.google.com
- time1.google.com
- time2.google.com
- time3.google.com
# IP addresses of the DNS servers.
DnsServers:
- 142.103.1.1
- 65.39.139.53
This configuration file is used for when Meadow is powered on, it looks for these values here and takes action depending on what's defined, like GetNetworkTimeAtStartup set to true, to get the UTC date and time using the NtpServers and DnsServers listed.
IMPORTANT: Right click the config file and go to the Properties, and make sure the Build Action is set to Content and Copy to Output Directory to Copy Always or Copy If Newer.
In the MeadowApp main class, copy the following code below:
// public class MeadowApp : App<F7Micro, MeadowApp> <- If you have a Meadow F7v1.*
public class MeadowApp : App<F7MicroV2, MeadowApp>
{
CharacterDisplay display;
public MeadowApp()
{
Initialize().Wait();
Start();
}
async Task Initialize()
{
var onboardLed = new RgbPwmLed(
device: Device,
redPwmPin: Device.Pins.OnboardLedRed,
greenPwmPin: Device.Pins.OnboardLedGreen,
bluePwmPin: Device.Pins.OnboardLedBlue);
onboardLed.SetColor(Color.Red);
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,
rows: 4, columns: 20
);
ShowSplashScreen();
var connectionResult = await Device.WiFiAdapter.Connect(Secrets.WIFI_NAME, Secrets.WIFI_PASSWORD);
if (connectionResult.ConnectionStatus != ConnectionStatus.Success)
{
throw new Exception($"Cannot connect to network: {connectionResult.ConnectionStatus}");
}
onboardLed.SetColor(Color.Green);
}
void ShowSplashScreen()
{
display.WriteLine("====================", 0);
display.WriteLine("Christmas Countdown!", 1);
display.WriteLine("= Joining WIFI =", 2);
display.WriteLine("====================", 3);
}
void Start()
{
display.WriteLine($"{DateTime.Now.ToString("MMMM dd, yyyy")}", 0);
display.WriteLine("Christmas Countdown:", 2);
while (true)
{
UpdateCountdown();
Thread.Sleep(1000);
}
}
void UpdateCountdown()
{
int TimeZoneOffSet = -8; // PST
var today = DateTime.Now.AddHours(TimeZoneOffSet);
display.WriteLine($"{today.ToString("MMMM dd, yyyy")}", 0);
display.WriteLine($"{today.ToString("hh:mm:ss tt")}", 1);
var christmasDate = new DateTime(today.Year, 12, 25);
if (christmasDate < today)
christmasDate = new DateTime(today.Year + 1, 12, 25);
var countdown = christmasDate.Subtract(today);
display.WriteLine($" {countdown.Days.ToString("D3")}d {countdown.Hours.ToString("D2")}h {countdown.Minutes.ToString("D2")}m {countdown.Seconds.ToString("D2")}s", 3);
}
}
The app starts calling the Initialize
method, where the onboard LED is turned on in Red to indicate the app has started, the CharacterDisplay
is instantiated, we activate the WIFI adapter to join our network, and finally the onboard LED turns Green to indicate the app has finished setting everything up.
The ShowSplashScreen
method is called to show a welcome message while we wait for the device to join the network.
Finally, the Start
method updates the display showing the Date and time in the first two lines, and a countdown indicated on the last line, updating on an infinite while loop every second (when calling UpdateCountdown
to properly format the reminding time).
Click the Run button in Visual Studio. It should look like to the following GIF:
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.
Comments