マイクロソフト系技術情報 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。

目次

概要

Windows 10 IoT Coreの評価を実施中。

基本

Headモード、Headlessモード

Headモード

Headlessモード

切替方法

以下のコマンドで切り替え可能。

ドライバの種類

Inboxドライバ

DMAPドライバ

準備

開発用PC

IoT機器

本体

Raspberry Pi 3 MODEL B

電源

micro USB(Androidと同じ)

周辺機器

ストレージ

ネットワーク

スイッチとして機能する機器(開発用PCとRaspberry Pi 3を接続する)

入出力

セットアップ

Windows 10 IoT Coreのインストール

Windows 10 IoT Core Dashboardのダウンロード

microSDにWindows 10 IoT CoreのOSイメージを書き込む。

Raspberry Pi 3へ機器を接続

Windows 10 IoT Coreの初期設定をする。

起動時

その他、適宜

Windows 10 IoT Core Dashboardから接続・操作する。

Device Portal

SMB

PowerShell

開発環境

開発用PCの準備

Windows 10がインストールされた開発用PCを準備する。

開発環境のセットアップ

Visual Studio 2017をインストールする。

開発者モードを有効にする。

Windows SDKのインストール

Windows 10 用のWindows SDKをダウンロードしてインストールする。

“Hello World”的にサンプルを実行する準備

サンプル・プログラムをGitHubからDownloadZIPする。

HelloWorld?する。

HelloBlinky?する。

サンプル・プログラムをデプロイして起動する。

デプロイ

スタートアップアプリに指定

いろいろな処理を実装する。

空のプロジェクトから実装を始める。

プロジェクトの新規作成

UWP バージョンを選択する

[ターゲットバージョン]と[最小バージョン]を選択する。

Debug実行

Writing apps開発の設定を行う

Lチカを実装する。

Apple PiのLEDのGPIO numberについては、下記を参照のこと。

using System.Threading.Tasks;
using Windows.Devices;
using Windows.Devices.Gpio;
using Microsoft.IoT.Lightning.Providers;

namespace App1
{
    /// <summary>
    /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
    /// </summary>
    public sealed partial class MainPage : Page
    {
        /// <summary>
        /// GpioPin #5は青色
        /// GpioPin #6は白色
        /// </summary>
        private readonly int LED_PIN = 6;

        /// <summary>GpioPin</summary>
        private GpioPin _gpioPin;

        /// <summary>Lチカを実装する。</summary>
        public MainPage()
        {
            this.InitializeComponent();

            // LightningProviderが利用可能かどうかチェックする。
            if (LightningProvider.IsLightningEnabled)
            {
                // LowLevelDevicesAggregateProviderを取得
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            // GpioControllerを取得
            GpioController gpioCtrl = GpioController.GetDefault();

            if (gpioCtrl == null)
            {
                return;
            }

            // GpioControllerでGpioを取得
            this._gpioPin = gpioCtrl.OpenPin(LED_PIN);
            // GpioPinでGpioPinをコントロール。
            this._gpioPin.SetDriveMode(GpioPinDriveMode.Output);
            this._gpioPin.Write(GpioPinValue.High);

            this.loop();
        }

        /// <summary>
        /// UIをハングさせないよう、asyncなloop内でawaitを使用する。
        /// System.Threading.Threadが無いので、こうなる。
        /// </summary>
        private async void loop()
        {
            while (true)
            {
                // GpioPinでGpioPinをコントロール。
                await Task.Delay(1000);
                this._gpioPin.Write(GpioPinValue.Low);
                await Task.Delay(1000);
                this._gpioPin.Write(GpioPinValue.High);
            }
        }
    }
}

LCDに文字を表示する。

using System.Text;
using System.Threading.Tasks;
using Windows.Devices;
using Windows.Devices.I2c;
using Microsoft.IoT.Lightning.Providers;

// 空白ページの項目テンプレートについては、https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x411 を参照してください

namespace App1
{
    /// <summary>
    /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
    /// </summary>
    public sealed partial class MainPage : Page
    {
        /// <summary>
        /// Raspberry Pi 3で GPIO端子の I2C機能を有効化する方法
        ///  (ラズパイ3の GPIO端子の I2C機能を有効にして各種センサーを繋げる方法まとめ)
        /// http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_3_gpio_enable_i2c/
        /// </summary>
        private readonly byte _Lcd_Addr = 0x3e;
 
        /// <summary>I2cDevice</summary>
        private I2cDevice _Lcd;
 
        public MainPage()
        {
            this.InitializeComponent();
            this.Loaded += MainPage_Loaded;
        }
 
        /// <summary>Loaded</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            await this.InitLcd();
            await this.DisplayLcd();
        }
 
        /// <summary>
        /// LCDを初期化する。
        /// 電子工作 - .NET 開発基盤部会 Wiki > 周辺機器 > LCD(液晶ディスプレイ)> I2C LCD AQM0802
        /// https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?%E9%9B%BB%E5%AD%90%E5%B7%A5%E4%BD%9C#b226d3e8
        /// </summary>
        private async Task InitLcd()
        {
            // LightningProviderが利用可能かどうかチェックする。
            if (LightningProvider.IsLightningEnabled)
            {
                // LowLevelDevicesAggregateProviderを取得
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }
 
            // I2cControllerを取得
            I2cController i2cCtrl = await I2cController.GetDefaultAsync();
 
            if (i2cCtrl == null)
            {
                return;
            }
 
            // I2cControllerでLCDを取得。
            this._Lcd = i2cCtrl.GetDevice(new I2cConnectionSettings(this._Lcd_Addr));
 
            // 初期化
            await WriteLcdCmd(0x38, 1); // 行数の設定
            await WriteLcdCmd(0x39, 1); // 拡張コマンドの設定開始
            await WriteLcdCmd(0x14, 1); // 内部OSC周波設定
            await WriteLcdCmd(0x70, 1); // コントラスト設定
            await WriteLcdCmd(0x56, 1); // パワー/アイコン コントラスト設定
            await WriteLcdCmd(0x6c, 250); // Follower設定
            await WriteLcdCmd(0x38, 1); // 拡張コマンドの設定終了
            await WriteLcdCmd(0x0c, 1); // ディスプレイ オン
            await WriteLcdCmd(0x01, 2); // ディスプレイ クリア
        }
 
        /// <summary>LCDに表示する</summary>
        /// <returns>Task</returns>
        private async Task DisplayLcd()
        {
            await WriteLcdCmd(0x01, 2); // ディスプレイ クリア
 
            // 一行目を指定して
            await WriteLcdCmd(0x80, 1); // Set DDRAM Address
            await WriteLcdDisplay("RzPi3"); // Write data to RAM
 
            // 二行目を指定して
            await WriteLcdCmd(0xc0, 2); // Set DDRAM Address
            await WriteLcdDisplay("ApplePi"); // Write data to RAM
        }
 
        /// <summary>LCDにコマンドを送る</summary>
        /// <param name="cmd">byte</param>
        /// <param name="waitTime_msec">int</param>
        /// <returns>Task</returns>
        private async Task WriteLcdCmd(byte cmd, int waitTime_msec)
        {
            // I2cDeviceでLCDをコントロール。
            // 10 bit 書くので2 byte で先頭は空なので 0.
            this._Lcd.Write(new byte[] { 0, cmd });
            await Task.Delay(waitTime_msec);
        }
 
        /// <summary>LCDに表示する</summary>
        /// <param name="msg">string</param>
        /// <returns>Task</returns>
        private async Task WriteLcdDisplay(string msg)
        {
            byte[] bytesMSG = Encoding.ASCII.GetBytes(msg);
 
            // I2cDeviceでLCDをコントロール。
            foreach (byte b in bytesMSG)
            {
                // 10 bit 書くので2 byte で先頭は・・・
                this._Lcd.Write(new byte[] { 0x40, b }); // 先頭0x40は?
            }
            await Task.Delay(1);
        }
    }
}

参考

電子工作

Build Insider

MS

ms-iot/samples: Windows 10 IoT Core Samples

https://github.com/ms-iot/samples

Windows 10 IoTCore ハンズオントレーニング


Tags: :インフラストラクチャ, :Windows, :IoT


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS