Reading Pcf8574 as pins rather than 8 bit word

Lancsrick
Posts: 30
Joined: Mon Apr 10, 2023 5:48 pm

Reading Pcf8574 as pins rather than 8 bit word

Postby Lancsrick » Fri Apr 05, 2024 7:11 am

I have a project that already makes use of the components from Unclerus, including the hd44780 for driving an LCD display.

I need to expand my Gpio ports so I've added a discrete pcf8574 board in. Now I already have the includes in my project as it's part of the lcd setup. I can happily read from the new pcf8574 board. Sounds great? Not really.

I seem to only be able to read or write to the pcf8574 as an 8 bit word, effectively using it as an 8 bit parallel port. What I'd like to be able to do is read each pin individually at any point, but they don't seem to be addressable.

Any help? Many thanks. Link to the unclerus lib below.

https://github.com/UncleRus/esp-idf-lib ... ts/pcf8574

MicroController
Posts: 1735
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Reading Pcf8574 as pins rather than 8 bit word

Postby MicroController » Fri Apr 05, 2024 9:15 am

What I'd like to be able to do is read each pin individually at any point, but they don't seem to be addressable.
For reads, you'll have to extract the individual pins' states from the 8-bit value 'manually' via bit-wise AND (and possibly right-shifting).
To write individual pins, you'd maintain a copy of the current output state in an 8-bit variable which you modify via bit-wise OR and AND NOT before sending the updated 8-bit value to the IO expander.

Lancsrick
Posts: 30
Joined: Mon Apr 10, 2023 5:48 pm

Re: Reading Pcf8574 as pins rather than 8 bit word

Postby Lancsrick » Fri Apr 05, 2024 2:50 pm

Thanks @microcontroller, I wasn't sure if there was a different way of interfacing with the pcf8574 or if I just needed to go down that route. Cheers!

Who is online

Users browsing this forum: Google [Bot] and 152 guests