Skip to content

Commit 1cc9c83

Browse files
DanielSSilvaTylerLeonhardt
authored andcommitted
Add example for Scroll pHat (PowerShell#41)
* Added an example and a README for the Scroll pHat device * added the image * yet another image, this time it's the result of the script * Added the copyright. Changed from Lightning effect to brightness to be clearer. Added instructions to install the module and enable I2C * Forgot to change one "lightning"
1 parent 22e29ec commit 1cc9c83

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
Import-Module Microsoft.PowerShell.IoT
4+
5+
[int]$DeviceAddress = 0x60
6+
######### Configuration Register and Value #########
7+
[int]$ConfigurationRegisterAddress = 0x00
8+
[int]$ConfigurationRegisterValue = 0x1B
9+
10+
######### Data Registers and value #########
11+
[int[]]$DataRegisterAddress = 0x04 ..0x08
12+
[int[]]$values = 0x12,0x08,0x08,0x08,0x12
13+
######### Brightness Register and value #########
14+
[int]$BrightnessRegisterAddress = 0x0D
15+
[int]$BrightnessRegisterValue = 0x08 #Lowest intensity
16+
17+
######### Get the device and set the Configuration Register
18+
$Device = Get-I2CDevice -Id $DeviceAddress -FriendlyName phat
19+
Set-I2CRegister -Device $Device -Register $ConfigurationRegisterAddress -Data $ConfigurationRegisterValue
20+
21+
######## Brightness #####
22+
Set-I2CRegister -Device $Device -Register $BrightnessRegisterAddress -Data $BrightnessRegisterValue
23+
24+
######### Write the #sadJoey pattern to the Data registers #########
25+
$i = 0
26+
foreach ($register in $DataRegisterAddress) {
27+
Set-I2CRegister -Device $Device -Register $register -Data $values[$i]
28+
$i++
29+
}
30+
31+
#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"
32+
[int]$UpdateRegisterAddress = 0x0C
33+
[int]$UpdateValue = 0xFF
34+
35+
#After executing this instruction, a Sad Joey should appear on your pHat :)
36+
Set-I2CRegister -Device $Device -Register $UpdateRegisterAddress -Data $UpdateValue
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Example on how to interact with Scroll pHat
2+
3+
With this example, we will see how we can interact with [Scroll pHat](https://shop.pimoroni.com/products/scroll-phat).
4+
5+
## Information
6+
7+
After reading the [driver's data sheet](http://www.issi.com/WW/pdf/31FL3730.pdf) we know the following:
8+
9+
There are three "types" of registers: Configuration register, Update register and data registers.
10+
The configuration register value is set to have the expected behaviour of this pHat.
11+
12+
There are 11 data registers, ranging from address 0x01 to 1x0B.
13+
Each register holds 1byte, but since ScrollPHat only has 5 lines, only 5bits are used.
14+
To set the LED on, you need to set the correspondent bits as 1, as example, to achieve the following:
15+
16+
![](https://i.imgur.com/nII0q7B.jpg)
17+
18+
we need to set the register 1 with data 0x0D (0000 1101).
19+
20+
## Software setup
21+
22+
### Install PowerShell Core on Raspberry Pi
23+
24+
Installation instructions can be found [here](https://github.com/PowerShell/PowerShell/tree/master/docs/installation/linux.md#raspbian).
25+
26+
### Enable I2C interface on Raspberry Pi
27+
28+
1. `sudo raspi-config`
29+
2. `5 Interfacing options`
30+
3. `P5 I2C`
31+
4. `Would you like ARM I2C interface to be enabled -> Yes`
32+
33+
Start PowerShell (**with sudo, so that you can access the I2C bus**)
34+
35+
```powershell
36+
sudo pwsh
37+
38+
git clone https://github.com/PowerShell/PowerShell-IoT.git #if you haven't already
39+
./PowerShell-IoT/Examples/Microsoft.PowerShell.IoT.Scroll_pHat/Microsoft.PowerShell.IoT.SadJoey.ps1
40+
```
41+
42+
After running this code, you should see a "Sad Joey" on your Scroll pHat.
43+
44+
Note: What's "Sad Joey"? - #SadJoey became "popular" meme/hastag [on twitter](https://twitter.com/search?q=%23sadJoey&src=typd) during the #PSConfEU 2018
45+
46+
This is what you should see:
47+
48+
![](https://i.imgur.com/112YDk4.jpg)

Examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Example modules that leverage PowerShell IoT in a specific way.
77
| Example | Difficulty | Type |
88
|---------|------------|------|
99
| [Microsoft.PowerShell.IoT.LED](/Examples/Microsoft.PowerShell.IoT.LED) | Easy | GPIO |
10+
| [Microsoft.PowerShell.IoT.Scroll_pHat](/Examples/Microsoft.PowerShell.IoT.Scroll_pHat) | Easy | I2C |
1011
| [Microsoft.PowerShell.IoT.BME280](/Examples/Microsoft.PowerShell.IoT.BME280) | Medium | I2C |
1112
| [Microsoft.PowerShell.IoT.SSD1306](/Examples/Microsoft.PowerShell.IoT.SSD1306) | Medium | I2C |
1213
| [Microsoft.PowerShell.IoT.ADXL345](/Examples/Microsoft.PowerShell.IoT.ADXL345) | Medium | I2C |

0 commit comments

Comments
 (0)