From f294265393d84a0655909f47427ddd10ff102c58 Mon Sep 17 00:00:00 2001 From: Attie Grande Date: Fri, 9 Oct 2020 14:05:57 +0100 Subject: [PATCH] examples: add an example PCF8574 script --- examples/i2c-pcf8574.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/i2c-pcf8574.py diff --git a/examples/i2c-pcf8574.py b/examples/i2c-pcf8574.py new file mode 100644 index 000000000..885f9bc8a --- /dev/null +++ b/examples/i2c-pcf8574.py @@ -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)