-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add an example PCF8574 script
- Loading branch information
1 parent
24b4b37
commit f294265
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
this serves as an example script for the run-script mode. connect a PCF8574 to the | ||
glasgow, and run the following command: | ||
glasgow run-script i2c-pcf8574.py i2c-initiator -V 3.3 --pin-scl 0 --pin-sda 1 | ||
this will read the pin state, and then output a pattern, before powering off the | ||
device | ||
""" | ||
|
||
from asyncio import sleep | ||
|
||
ADDR = 0x20 | ||
|
||
# set all pins high, so that their inputs may be read | ||
await iface.write(ADDR, [ 0xFF ], stop=False) | ||
p = await iface.read(ADDR, 1, stop=True) | ||
print('p: 0x{:02X}'.format(p)) | ||
|
||
await sleep(0.5) | ||
|
||
# set a pattern on the pins | ||
await iface.write(ADDR, [ 0x55 ], stop=True) | ||
|
||
await sleep(0.5) | ||
|
||
# power down the device after use | ||
await device.set_voltage("AB", 0) |