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

Add example for Scroll pHat #41

Merged
merged 5 commits into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Import-Module Microsoft.PowerShell.IoT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah this file will need the copyright. You can do it if you want or I can add it before merging.


[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
48 changes: 48 additions & 0 deletions Examples/Microsoft.PowerShell.IoT.Scroll_pHat/README.md
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions Examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down