Skip to content

Commit

Permalink
examples: add an example PCF8574 script
Browse files Browse the repository at this point in the history
  • Loading branch information
attie-argentum committed Oct 9, 2020
1 parent 24b4b37 commit f294265
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/i2c-pcf8574.py
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)

0 comments on commit f294265

Please sign in to comment.