Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Latest commit

 

History

History
77 lines (53 loc) · 4.43 KB

File metadata and controls

77 lines (53 loc) · 4.43 KB

Windows IoT Edge PWM Sample

This is a sample showing an Azure IoT Edge deployment for Windows IoT Core with a .NET Core C# console app to demonstrate PWM control of a DC motor. Additionally, it can do this in a way that can coordinate with the Fruit WinML sample.

App Overview

The pwm sample expects to be run on a board that is connected to a pwm motor circuit. When it receives a D2C Fruit Message or DirectMethod call it maps the fruit to a motor speed and runs the motor at that speed. the mapping is Grapes - 100%, apple, pear - 50%, pen - 0%.

Other things of interest in this sample

  • The deployment.json file demonstrates container creation options for exposing PWM controllers into the container.

Prerequisites

  • Azure subscription with the following resources:
  • Hardware:
    • An x64 Board with Windows 10 IoT Core version 1809 (Build 17763) installed and PWM driver support.
    • A PWM peripheral and support circuit. What was used for developing this sample is a simple DC motor with fan from an Arduino starter kit. There are many tutorial examples using an L293D motor controller chip that can be found on the internet. And, there are several other alternatives using different motor control circuits.
  • Required packages to install

Build and Publish the app

Dotnet CLI

  1. cd to the directory container the .csproj
  2. dotnet publish

VSCode

  1. See Edge development How-To

Visual Studio

  1. Load the solution
  2. Right click on the cs project and select publish.

Build module container for the app

Container build for amd64

Unfortunately, this can't be done from a developer desktop since the IoT Core container cannot run on desktop. Instead it must be done on real hardware. After you have published your app do the following steps:

  • Obtain an x64 machine with IoT Core installed.
  • ssh into a command prompt on the machine.
  • Install Docker on the IoT Core machine
    • Download x64 docker.exe
    • And x64 dockerd.exe
    • Copy them to the IoT Core machine and put docker.exe in the path.
    • from a command prompt run 'dockerd.exe --register-service'
    • sc.exe start docker
  • Copy your app to the machine
  • Choose properties\dockerfile.dotnet or dockerfile.standalone depending on which kind of project you've built and copy that docker file to the machine
  • Do 'docker login' with creds to your container registry.
  • Do 'docker build -f < path to dockerfile> -t <registry/repo:tag> .' to build the image.
  • docker push <registry/repo:tag>

Update deployment.nocreds.json

The "preview" creds in the deployment.json are public read-only creds to the standard edge runtime modules. But, for the sample you must update the creds in the deployment.json file to provide access to your module container repository where you've stored the module you just built. And, you must update the image url in the module section with the correct url for your module image.

Deploy the module

There are multiple ways to deploy the module:

The recommended way to get started is VSCode with the Azure IoT Edge extension. But, for larger scale production deployments scripting with CLI is likely preferable.