From 69066c7dae4b680bd45087804a48b437af320afe Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 May 2018 22:56:02 +0100 Subject: [PATCH 1/5] Added an example and a README for the Scroll pHat device --- .../Microsoft.PowerShell.IoT.SadJoey.ps1 | 34 +++++++++++++++++++ .../README.md | 30 ++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 create mode 100644 Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md diff --git a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 new file mode 100644 index 0000000..53ffaa3 --- /dev/null +++ b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 @@ -0,0 +1,34 @@ +Import-Module Microsoft.PowerShell.IoT + +[int]$DeviceAddress = 0x60 +######### Configuration Register and Value ######### +[int]$ConfigurationRegisterAddress = 0x00 +[int]$ConfigurationRegisterValue = 0x1B + +######### Data Registers and value ######### +[int[]]$DataRegisterAddress = 0x04 ..0x08 +[int[]]$values = 0x12,0x08,0x08,0x08,0x12 +######### Lightning Effect Register and value ######### +[int]$LightningEffectRegisterAddress = 0x0D +[int]$LightningEffectRegisterValue = 0x08 #Lowest intensity + +######### Get the device and set the Configuration Register +$Device = Get-I2CDevice -Id $DeviceAddress -FriendlyName phat +Set-I2CRegister -Device $Device -Register $ConfigurationRegisterAddress -Data $ConfigurationRegisterValue + +######## Lightning Effect ##### +Set-I2CRegister -Device $Device -Register $LightningEffectRegisterAddress -Data $LightningEffectRegisterValue + +######### Write the #sadJoey pattern to the Data registers ######### +$i = 0 +foreach ($register in $DataRegisterAddress) { + Set-I2CRegister -Device $Device -Register $register -Data $values[$i] + $i++ +} + +#In order to update the registers, we need to write something to the column register, accoding to the datasheet: "A write operation of any 8-bit value to the Update Column Register is required to update the Data Registers" +[int]$UpdateRegisterAddress = 0x0C +[int]$UpdateValue = 0xFF + +#After executing this instruction, a Sad Joey should appear on your pHat :) +Set-I2CRegister -Device $Device -Register $UpdateRegisterAddress -Data $UpdateValue \ No newline at end of file diff --git a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md new file mode 100644 index 0000000..baa90cb --- /dev/null +++ b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md @@ -0,0 +1,30 @@ +# Example on how to interact with Scroll pHat + +With this example, we will see how we can interact with [Scroll pHat](https://shop.pimoroni.com/products/scroll-phat). + +## Information + +After reading the [driver's data sheet](http://www.issi.com/WW/pdf/31FL3730.pdf) we know the following: + +There are three "types" of registers: Configuration register, Update register and data registers. +The configuration register value is set to have the expected behaviour of this pHat. + +There are 11 data registers, ranging from address 0x01 to 1x0B. +Each register holds 1byte, but since ScrollPHat only has 5 lines, only 5bits are used. +To set the LED on, you need to set the correspondent bits as 1, as example, to achieve the following: + + +This example assumes that you already have I2C enabled and Microsoft.PowerShell.IoT module installed. + +Start PowerShell (**with sudo, so that you can access the I2C bus**) + +```powershell +sudo pwsh + +git clone https://github.com/PowerShell/PowerShell-IoT.git #if you haven't already +./PowerShell-IoT/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 +``` + +After running this code, you should see a "Sad Joey" on your Scroll pHat. + +Note: What's "Sad Joey"? - #SadJoey became "popular" meme/hastag [on twitter](https://twitter.com/search?q=%23sadJoey&src=typd) during the #PSConfEU 2018 \ No newline at end of file From 9fc5caf33a0fb663b27be700606db154b7821c00 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 May 2018 22:59:54 +0100 Subject: [PATCH 2/5] added the image --- Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md index baa90cb..b8edd05 100644 --- a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md +++ b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md @@ -13,6 +13,9 @@ There are 11 data registers, ranging from address 0x01 to 1x0B. Each register holds 1byte, but since ScrollPHat only has 5 lines, only 5bits are used. To set the LED on, you need to set the correspondent bits as 1, as example, to achieve the following: +![](https://i.imgur.com/nII0q7B.jpg) + +we need to set the register 1 with data 0x0D (0000 1101). This example assumes that you already have I2C enabled and Microsoft.PowerShell.IoT module installed. From 99ba98b26591495cab07b4fa5b62163b7c0cd463 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Wed, 9 May 2018 23:09:38 +0100 Subject: [PATCH 3/5] yet another image, this time it's the result of the script --- Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md index b8edd05..e055993 100644 --- a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md +++ b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md @@ -30,4 +30,8 @@ git clone https://github.com/PowerShell/PowerShell-IoT.git #if you haven't alrea After running this code, you should see a "Sad Joey" on your Scroll pHat. -Note: What's "Sad Joey"? - #SadJoey became "popular" meme/hastag [on twitter](https://twitter.com/search?q=%23sadJoey&src=typd) during the #PSConfEU 2018 \ No newline at end of file +Note: What's "Sad Joey"? - #SadJoey became "popular" meme/hastag [on twitter](https://twitter.com/search?q=%23sadJoey&src=typd) during the #PSConfEU 2018 + +This is what you should see: + +![](https://i.imgur.com/112YDk4.jpg) \ No newline at end of file From 9bc2e8b200674b3bede98e35b0977edac081d4d9 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Thu, 10 May 2018 21:40:21 +0100 Subject: [PATCH 4/5] Added the copyright. Changed from Lightning effect to brightness to be clearer. Added instructions to install the module and enable I2C --- .../Microsoft.PowerShell.IoT.SadJoey.ps1 | 10 ++++++---- .../Microsoft.PowerShell.IoT.Scroll_pHat/README.md | 13 ++++++++++++- Examples/README.md | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 index 53ffaa3..ec3d28b 100644 --- a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 +++ b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 @@ -1,3 +1,5 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. Import-Module Microsoft.PowerShell.IoT [int]$DeviceAddress = 0x60 @@ -8,16 +10,16 @@ Import-Module Microsoft.PowerShell.IoT ######### Data Registers and value ######### [int[]]$DataRegisterAddress = 0x04 ..0x08 [int[]]$values = 0x12,0x08,0x08,0x08,0x12 -######### Lightning Effect Register and value ######### -[int]$LightningEffectRegisterAddress = 0x0D -[int]$LightningEffectRegisterValue = 0x08 #Lowest intensity +######### Brightness Register and value ######### +[int]$BrightnessRegisterAddress = 0x0D +[int]$BrightnessRegisterValue = 0x08 #Lowest intensity ######### Get the device and set the Configuration Register $Device = Get-I2CDevice -Id $DeviceAddress -FriendlyName phat Set-I2CRegister -Device $Device -Register $ConfigurationRegisterAddress -Data $ConfigurationRegisterValue ######## Lightning Effect ##### -Set-I2CRegister -Device $Device -Register $LightningEffectRegisterAddress -Data $LightningEffectRegisterValue +Set-I2CRegister -Device $Device -Register $BrightnessRegisterAddress -Data $BrightnessRegisterValue ######### Write the #sadJoey pattern to the Data registers ######### $i = 0 diff --git a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md index e055993..2f446ec 100644 --- a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md +++ b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md @@ -17,7 +17,18 @@ To set the LED on, you need to set the correspondent bits as 1, as example, to a we need to set the register 1 with data 0x0D (0000 1101). -This example assumes that you already have I2C enabled and Microsoft.PowerShell.IoT module installed. +## Software setup + +### Install PowerShell Core on Raspberry Pi + +Installation instructions can be found [here](https://github.com/PowerShell/PowerShell/tree/master/docs/installation/linux.md#raspbian). + +### Enable I2C interface on Raspberry Pi + +1. `sudo raspi-config` +2. `5 Interfacing options` +3. `P5 I2C` +4. `Would you like ARM I2C interface to be enabled -> Yes` Start PowerShell (**with sudo, so that you can access the I2C bus**) diff --git a/Examples/README.md b/Examples/README.md index b8aa594..d48584f 100644 --- a/Examples/README.md +++ b/Examples/README.md @@ -7,6 +7,7 @@ Example modules that leverage PowerShell IoT in a specific way. | Example | Difficulty | Type | |---------|------------|------| | [Microsoft.PowerShell.IoT.LED](/Examples/Microsoft.PowerShell.IoT.LED) | Easy | GPIO | +| [Microsoft.PowerShell.IoT.Scroll_pHat](/Examples/Microsoft.PowerShell.IoT.Scroll_pHat) | Easy | I2C | | [Microsoft.PowerShell.IoT.BME280](/Examples/Microsoft.PowerShell.IoT.BME280) | Medium | I2C | | [Microsoft.PowerShell.IoT.SSD1306](/Examples/Microsoft.PowerShell.IoT.SSD1306) | Medium | I2C | | [Microsoft.PowerShell.IoT.ADXL345](/Examples/Microsoft.PowerShell.IoT.ADXL345) | Medium | I2C | From e0610660906c81710de44fdd46bcaa690f567142 Mon Sep 17 00:00:00 2001 From: Daniel Silva Date: Thu, 10 May 2018 21:59:04 +0100 Subject: [PATCH 5/5] Forgot to change one "lightning" --- .../Microsoft.PowerShell.IoT.SadJoey.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 index ec3d28b..0118c00 100644 --- a/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 +++ b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 @@ -18,7 +18,7 @@ Import-Module Microsoft.PowerShell.IoT $Device = Get-I2CDevice -Id $DeviceAddress -FriendlyName phat Set-I2CRegister -Device $Device -Register $ConfigurationRegisterAddress -Data $ConfigurationRegisterValue -######## Lightning Effect ##### +######## Brightness ##### Set-I2CRegister -Device $Device -Register $BrightnessRegisterAddress -Data $BrightnessRegisterValue ######### Write the #sadJoey pattern to the Data registers #########