|
| 1 | +--- |
| 2 | +RFC: 0053 |
| 3 | +Author: Andrew Menagarishvili |
| 4 | +Status: Withdrawn |
| 5 | +SupercededBy: N/A |
| 6 | +Version: 1.0 |
| 7 | +Area: External PowerShell Module / PowerShell IoT |
| 8 | +Comments Due: Apr 5th, 2018 |
| 9 | +Plan to implement: Yes |
| 10 | +--- |
| 11 | + |
| 12 | +# PowerShell IoT Module |
| 13 | + |
| 14 | +This RFC outlines creation of a PowerShell module containing interfaces (cmdlets) for working with |
| 15 | +peripheral devices in IoT applications of single board ARM computers such as Raspberry Pi. |
| 16 | +Cmdlets discussed here are PowerShell wrappers over standard elecrical interfaces (I2C, SPI, GPIO) |
| 17 | +that provide PowerShell-based automation access to peripheral hardware management. |
| 18 | + |
| 19 | +## Motivation |
| 20 | + |
| 21 | +The PowerShell team is investigating IoT scenarios for PowerShell. |
| 22 | +Single board computers (e.g. Raspberry Pi) gained popularity in recent years in fields like home automation, education and robotics. |
| 23 | +SBCs have a set of connectors for attaching peripheral devices like sensors, screens, motors, etc... |
| 24 | +PowerShell, being a powerfull cross-platform automation engine, is a perfect tool for managing such hardware. |
| 25 | +Proposed PowerShell module will allow users to implement IoT solutions without knowledge of low-level electrical details. |
| 26 | + |
| 27 | +## Specification |
| 28 | + |
| 29 | +For the initial release of the module we are targeting to cover these interfaces in the following priority: |
| 30 | +* GPIO - General-purpose input/output line |
| 31 | +* I2C - Inter-Integrated Circuit bus |
| 32 | +* SPI - Serial Peripheral Interface bus |
| 33 | + |
| 34 | +### GPIO |
| 35 | + |
| 36 | +Cmlets get and set voltage level (aka logic true/false signal) of general-purpose input/output lines. |
| 37 | +Used to turn on/off components like LEDs, power relays, reading from simple sensors. |
| 38 | + |
| 39 | +```powershell |
| 40 | +Get-GpioPin [[-Id] <int[]>] [[-PullMode] {Off | PullDown | PullUp}] [-Raw] |
| 41 | +Set-GpioPin [-Id] <int[]> [-Value] {Low | High} [-PassThru] |
| 42 | +``` |
| 43 | +Notes: |
| 44 | +* `Get-GpioPin` without parameters returns all available GPIO lines with their properties. |
| 45 | +* `-PullMode` parameter controlles built-in pull-up/pull-down resistor on the line that determines line state when nothing is connected to it. |
| 46 | +* `-Raw` parameter makes cmdlet return just the signal value as opposed to {PinId,Value,PinInfo} object. |
| 47 | + |
| 48 | +### I2C |
| 49 | +Proposed cmlets provide an interface for working with components that support I2C bus. |
| 50 | +I2C bus supports up to 127 devices on the same bus, which is 4 wires: power, ground, clock line and data line. |
| 51 | +A single operation (write or read) for just one device can be active on the bus at any given time. |
| 52 | +Proposed I2C cmdlets read and set values of logical registers on I2C devices. |
| 53 | + |
| 54 | +```powershell |
| 55 | +# Prepare a device object descriptor that will be later used in get/set operations |
| 56 | +Get-I2CDevice -Id <int> [-FriendlyName <string>] |
| 57 | +
|
| 58 | +# Read a number of bytes from a device starding from specified register address |
| 59 | +Get-I2CRegister -Device <I2CDevice> -Register <uint16> [-ByteCount <byte>] [-Raw] |
| 60 | +
|
| 61 | +# Write a number of bytes to a device as values of specified register |
| 62 | +Set-I2CRegister -Device <I2CDevice> -Register <uint16> -Data <byte[]> [-PassThru] |
| 63 | +``` |
| 64 | + |
| 65 | +Notes: |
| 66 | +* `Get-I2CDevice -Id` parameter specifies device address on I2C bus (can be found by tools like `sudo i2cdetect -y 1`). |
| 67 | +* `-Raw` parameter makes cmdlet return just the register value as opposed to {Device,Register,Data} object. |
| 68 | + |
| 69 | +### SPI |
| 70 | +Proposed cmlets provide an interface for working with components that support SPI bus. |
| 71 | +SPI bus supports high clock speeds (data transfer rate) and allows parallel read/write to/from the component. |
| 72 | +Only one device can be active on the bus at any given time (doing parallel read and write). |
| 73 | +Proposed SPI cmdlet is operating with byte streams. |
| 74 | + |
| 75 | +```powershell |
| 76 | +# Send a byte stream to a device and return a responce byte stream |
| 77 | +Send-SPIData -Channel <uint> -Data <byte[]> [-Frequency <uint>] [-Raw] |
| 78 | +``` |
| 79 | + |
| 80 | +Notes: |
| 81 | +* Default frequency is 8 Mhz which is typical in modern hardware. |
| 82 | +* `-Raw` parameter makes cmdlet return just the responce byte stream as opposed to {Channel,Data,Responce,Frequency} object. |
| 83 | + |
| 84 | +### Examples |
| 85 | +Several example component-specific modules are necessary to show the usage of proposed cmdlets. |
| 86 | +Following devices have been selected based on popularity in the community: |
| 87 | +* BME280 environmental sensor (pressure, humidity and temperature) |
| 88 | +* SSD1306 OLED display |
| 89 | + |
| 90 | +## Alternate Proposals and Considerations |
| 91 | + |
| 92 | +### Dependecies |
| 93 | + |
| 94 | +Making an interface for I2C or SPI bus with all the details is a difficult task, so we are reusing existing community-created libraries that provide simplified APIs. |
| 95 | +After comparing several libraries https://unosquare.github.io/raspberryio was selected as it is a nice .NET Core compatible wrapper over WiringPi - very popular in RaspberryPi community library. |
| 96 | +Proposed PowerShell module is expected to be redistributed with raspberryio and WiringPi binaries. |
| 97 | + |
| 98 | +### Supported OSes |
| 99 | +With the initial release of the module we are targeting Raspbian Stretch and Windows 10 IoT Core with Raspbian being a priority as it is more popular in the community. |
0 commit comments