Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit 6ddb744

Browse files
Misc docs updates (#30)
* WIP LED example * add led doc and remoting doc * misc feedback * change resistor ohms * ohms range
1 parent 66e82d7 commit 6ddb744

File tree

8 files changed

+192
-7
lines changed

8 files changed

+192
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
@{
5+
GUID="0432ee36-7e87-4a21-814f-8feb17974641"
6+
Author="Microsoft Corporation"
7+
CompanyName="Microsoft Corporation"
8+
Copyright="© Microsoft Corporation. All rights reserved."
9+
Description='PowerShell module for working with a single-color LED.'
10+
ModuleVersion="0.1.0"
11+
FunctionsToExport = @('Set-Led')
12+
CmdletsToExport = '*'
13+
AliasesToExport = @()
14+
NestedModules=@('Microsoft.PowerShell.IoT','Microsoft.PowerShell.IoT.LED.psm1')
15+
HelpInfoURI = 'https://github.com/PowerShell/PowerShell-IoT'
16+
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
17+
PrivateData = @{
18+
PSData = @{
19+
# Tags applied to this module. These help with module discovery in online galleries.
20+
Tags = 'IoT','RaspberryPi','Raspbian','LED'
21+
22+
# A URL to the license for this module.
23+
LicenseUri = 'https://github.com/PowerShell/PowerShell-IoT/blob/master/LICENSE.txt'
24+
25+
# A URL to the main website for this project.
26+
ProjectUri = 'https://github.com/PowerShell/PowerShell-IoT'
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function Set-Led
2+
{
3+
[CmdletBinding()]
4+
param
5+
(
6+
[Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName="Pin")]
7+
[ValidateNotNullOrEmpty()]
8+
[string] $Pin,
9+
10+
[Parameter(Mandatory=$true, Position=1, ValueFromPipelineByPropertyName="State")]
11+
[ValidateSet('On','Off',ignorecase=$true)]
12+
[string] $State
13+
)
14+
if ($State -eq 'On')
15+
{
16+
$value = "High"
17+
}
18+
else
19+
{
20+
$value = "Low"
21+
}
22+
23+
Set-GpioPin -Id $Pin -Value $value
24+
}

Diff for: Examples/Microsoft.PowerShell.IoT.LED/README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Example module Microsoft.PowerShell.IoT.LED
2+
3+
This simple PowerShell module is for turning on/off a single color LED.
4+
5+
![An LED is on](https://i.imgur.com/nJPJ9Vk.jpg)
6+
7+
This showcases GPIO functionality of [the Microsoft.PowerShell.IoT module](../../README.md).
8+
9+
## Hardware setup
10+
11+
Hardware pieces:
12+
13+
* [Breadboard](https://en.wikipedia.org/wiki/Breadboard) (Optional)
14+
* Male to female [jumper wires](https://en.wikipedia.org/wiki/Jump_wire)
15+
* 1 270-330Ω resistor
16+
* A [single-color LED](http://upload.wikimedia.org/wikipedia/commons/e/e8/LEDs.jpg)
17+
18+
## Wiring diagram
19+
20+
![wiring](https://i.imgur.com/lCaxMWZ.png)
21+
22+
## Software setup
23+
24+
### Install PowerShell Core on Raspberry Pi
25+
26+
Installation instructions can be found [here](https://github.com/PowerShell/PowerShell/tree/master/docs/installation/linux.md#raspbian).
27+
28+
### Start Powershell and install modules
29+
30+
```powershell
31+
sudo pwsh
32+
33+
Install-Module -Name Microsoft.PowerShell.IoT
34+
35+
git clone https://github.com/PowerShell/PowerShell-IoT.git
36+
37+
Import-Module ./PowerShell-IoT/Examples/Microsoft.PowerShell.IoT.LED
38+
```
39+
40+
### Usage
41+
42+
```powershell
43+
# Turn LED on
44+
Set-Led -Pin 1 -State On
45+
# or
46+
Set-Led 1 On
47+
# or
48+
[PSCustomObject]@{Pin=1; State="On"} | Set-Led
49+
50+
# Turn LED off
51+
Set-Led 1 Off
52+
```

Diff for: Examples/Microsoft.PowerShell.IoT.Plant/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ Import-Module ./PowerShell-IoT/Examples/Microsoft.PowerShell.IoT.Plant
4949
PS /home/pi> # working with light
5050
PS /home/pi> Set-Light On
5151
PS /home/pi> Set-Light Off
52-
PS /home/pi>
52+
PS /home/pi>
5353
PS /home/pi> # working with water
5454
PS /home/pi> Start-Water
5555
PS /home/pi> Stop-Water
56-
PS /home/pi>
56+
PS /home/pi>
5757
PS /home/pi> # reading soil moisture level
5858
PS /home/pi> Read-SoilIsDry
5959
```
@@ -64,4 +64,4 @@ See `full-plant-demo.ps1`.
6464

6565
This script runs 2 PS jobs - one controls light, the other - water.
6666

67-
For demo purposes script runs for 2 minutes. Adjust timeouts in the script for your scenario.
67+
For demo purposes script runs for 2 minutes. Adjust timeouts in the script for your scenario.

Diff for: Examples/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Examples
2+
3+
Example modules that leverage PowerShell IoT in a specific way.
4+
5+
## Table of Contents
6+
7+
| Example | Difficulty | Type |
8+
|---------|------------|------|
9+
| [Microsoft.PowerShell.IoT.LED](/Examples/Microsoft.PowerShell.IoT.LED) | Easy | GPIO |
10+
| [Microsoft.PowerShell.IoT.BME280](/Examples/Microsoft.PowerShell.IoT.BME280) | Medium | I2C |
11+
| [Microsoft.PowerShell.IoT.SSD1306](/Examples/Microsoft.PowerShell.IoT.SSD1306) | Medium | I2C |
12+
| [Microsoft.PowerShell.Plant](/Examples/Microsoft.PowerShell.IoT.Plant) | Hard | GPIO |

Diff for: README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,16 @@ Get-GpioPin 2 # gets the data from GPIO pin 2
154154

155155
#### Testing
156156

157-
You can run tests,
158-
but they don't do anything right now:
157+
You can run tests, but they require a particular setup. Here is how you run them:
159158

160159
```powershell
161160
./build.ps1 -Test
162161
```
163162

164-
We will investigate standing up a test rig of supported devices and OS's so that we can test against actual hardware.
163+
The setup required:
164+
165+
* For I2C: An [Adafruit BME280 I2C or SPI Temperature Humidity Pressure Sensor](https://www.adafruit.com/product/2652)
166+
* For GPIO: Bend pins 26 and 22 to touch each other or connect them in some way
167+
* For SPI: An [Adafruit LIS3DH Triple-Axis Accelerometer](https://www.adafruit.com/product/2809)
168+
169+
We currently have a build agent that will deploy PR code onto a test Raspberry Pi and run the tests found in the `test` directory.

Diff for: docs/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ This folder contains documentation on how to get started with PowerShell IoT and
55
## Table of contents
66

77
* [Raspberry Pi 3 Pin layout](/docs/rpi3_pin_layout.md)
8-
* [API reference](/docs/api_reference.md)
8+
* [Remoting via SSH](/docs/remoting.md)
9+
* [API reference](/docs/api_reference.md)

Diff for: docs/remoting.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# SSH Remoting Docs
2+
3+
> NOTE: These docs were created while using a Raspberry Pi 3 with Raspbian Stretch.
4+
5+
## Prereqs
6+
7+
First you need to get the IP address of the device. You can do this by running this on the device:
8+
9+
```bash
10+
PS > hostname -I
11+
12+
123.123.123.123 <ignore this extra stuff>
13+
```
14+
15+
You also need to have [PowerShell Core](https://github.com/powershell/powershell) installed on your device.
16+
17+
You'll also need some SSH client. macOS and linux have it installed by default, for Windows, check out the [Win32 port of OpenSSH](https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH).
18+
19+
## Using pure SSH
20+
21+
First ssh into your pi:
22+
23+
```plaintext
24+
25+
26+
# At this point you are remoted into to the device and can start PowerShell
27+
28+
> sudo pwsh
29+
PS > Get-GpioPin 1
30+
```
31+
32+
## Using PowerShell Remoting (PSRP) over SSH
33+
34+
> NOTE: This will only work if your device doesn't require a password when you run `sudo pwsh`. The Raspberry Pi 3 with default configuration does not prompt.
35+
36+
First you need to install [PowerShell Core](https://github.com/powershell/powershell) on your client machine. Windows PowerShell does not support PowerShell Remoting (PSRP) over SSH so that will not work.
37+
38+
Second you need to set up PSRP over SSH. You can [follow this guide](https://github.com/PowerShell/PowerShell/blob/11631e7412197f3f803ebbef95a3ddb174a387ec/demos/SSHRemoting/README.md).
39+
40+
When you get to the part where it says:
41+
42+
> Add a PowerShell subsystem entry
43+
44+
Put this:
45+
46+
```plaintext
47+
Subsystem powershell sudo pwsh -sshs -NoLogo -NoProfile
48+
```
49+
50+
Note the use of `sudo`.
51+
52+
If done correctly, you should be able to run:
53+
54+
```powershell
55+
PS > Enter-PSSession -Hostname 123.123.123.123 -UserName pi
56+
57+
# At this point you are remoted into to the device already in PowerShell
58+
59+
[123.123.123.123] PS > Get-GpioPin 1
60+
```
61+
62+
By doing this, you should be able to automate working with your device using PowerShell 🎉

0 commit comments

Comments
 (0)