This project shows you how to run Meadow applications straight from a Windows machine using Meadow.Windows. You can even connect physical peripherals and/or sensors using an IO Expander like Adafruit's FT232H. As an example in this project, we'll wire up an LCD 20x4 character display and control it 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.
Step 1 - Assemble the circuitWire your project like this:
Create a new.NET Console application, and open the project file and replace it with the following
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Disclaimer: we currently don't have a Meadow.Windows template, so this the only way at this time to create Meadow applications that run on Windows.
Step 3 - Add the required NuGet packagesFor this project, search and install the following NuGet packages:
- Meadow.Windows
- Meadow.Foundation.ICs.IOExpanders.Ft232h
- Meadow.Foundation.Displays.Lcd.CharacterDisplay
Add the native library (libmpsse.dll) of the FT232H IO Expander depending on your CPU's architecture (Win32 or x64) to your project and set th Copy to Output Directory to Copy if newer
or Copy always
.
Copy the following code below:
using Meadow;
using Meadow.Foundation.Displays.Lcd;
using Meadow.Foundation.ICs.IOExpanders;
public class MeadowApp : App<Windows>
{
private CharacterDisplay? display;
public override Task Initialize()
{
Console.WriteLine("Creating Outputs");
var _expander = new Ft232h();
display = new CharacterDisplay
(
pinRS: _expander.Pins.C5,
pinE: _expander.Pins.C4,
pinD4: _expander.Pins.C3,
pinD5: _expander.Pins.C2,
pinD6: _expander.Pins.C1,
pinD7: _expander.Pins.C0,
rows: 4, columns: 20
);
display.Write("Hello Meadow!");
return Task.CompletedTask;
}
void UpdateCountdown()
{
var today = DateTime.Now;
display?.WriteLine($"{today.ToString("MMMM dd, yyyy")}", 2);
display?.WriteLine($"{today.ToString("hh:mm:ss tt")}", 3);
}
public override Task Run()
{
display?.WriteLine($"Wilderness Labs", 0);
display?.WriteLine($"Meadow.Windows ", 1);
while (true)
{
UpdateCountdown();
Thread.Sleep(1000);
}
}
public static async Task Main(string[] args)
{
await MeadowOS.Start(args);
}
}
Initialize
- Instantiate a FT232h object to use six digital output ports for the character display.Run
- At this point, we write text on the character display, refresing date and time on an infinite while loop.Main
- For Meadow.Windows applications, its required to add this Main task method that starts the MeadowOS runtime on Windows.
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