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..0118c00 --- /dev/null +++ b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1 @@ -0,0 +1,36 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +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 +######### 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 + +######## Brightness ##### +Set-I2CRegister -Device $Device -Register $BrightnessRegisterAddress -Data $BrightnessRegisterValue + +######### 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..2f446ec --- /dev/null +++ b/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md @@ -0,0 +1,48 @@ +# 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: + +![](https://i.imgur.com/nII0q7B.jpg) + +we need to set the register 1 with data 0x0D (0000 1101). + +## 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**) + +```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 + +This is what you should see: + +![](https://i.imgur.com/112YDk4.jpg) \ No newline at end of file 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 |