From 61480b04fc8d802a3a464c6ee66575711e81beff 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 | 17 +++++++++++++++++ 1 file changed, 17 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..05454b723 --- /dev/null +++ b/examples/i2c-pcf8574.py @@ -0,0 +1,17 @@ +""" +An example of a script that can be used with the run-script mode. + +This will read and write the pins of a PCF8574. Once connected, run: + + glasgow run-script i2c-pcf8574.py i2c-initiator -V 3.3 +""" + +# read pin values +p = await iface.read(0x20, 1) +print('I/O pin state: 0b{:08b}'.format(p)) + +# write pin values +await iface.write(0x20, [ 0x55 ]) + +# power down the device after use +await device.set_voltage("AB", 0)