GPIO tinkering: 8 port expander
Vložit
- čas přidán 8. 07. 2024
- It's time to take a look at these PCF8574 GPIO expanded chips I pulled out of the mailbag a little while ago.
This isn't a deep dive, I'm just getting a bit familiar and trying them out with a few different microcontrollers.
Datasheet: www.ti.com/product/PCF8574
If you want to see another way of using this chip, Hari Wiguna made an interesting video a few years ago: • HariFun #133 - 8 LEDs,...
-----
My tip jar: / pileofstuff
My other tip jar (channel membership) : / @pileofstuff
Buy me a coffee (or a beer): ko-fi.com/pileofstuff
If you are OK with me getting a commission on your purchases, feel free to use my affiliate links:
Ebay: ebay.to/33IF7PA
Banggood: pileofstuff.ca/r/9ajsf
Some other links to products may be affiliate links
odysee.com/@pileofstuff
#ElectronicsCreators
-----
This isn't the only way to do it.
It's probably not the best way to do it.
But it's how I did it. - Věda a technologie
Great little chip with so many uses.
These (PCF8574's) are useful little chips, handy for extra GPIO. But also the PCF8591's are good for analog GPIO too, all of the PCF's are always great arduino-type add-on chips though.
Nice to see someone else tinkers🙂
I've seen these chips used on those I2C backpacks for LCD displays, it operates the display in 4 bit data mode and the driver handles the protocol. I've got some MCP23017 16 output expanders which are similar but a bigger chip that I used with an ATTINY but I don't really know why I didn't just use an ATMEGA328 :)
IBM used Libraries, then it became programmes, then it became applications and now back to libraries. Things never change.
These really shine when using a micro with limited pins, to say drive an LCD or where you just need additional pins. You can also use them as inputs, as in I2C read.
The chip does provide a high output, its ot design to drive much as it only provides 100uA's See 8.2.2 in the datasheet. If it was sink only they would have described the output as open drain in the same way the do for the int output.
This would make a nice device to read the datasheet and work out how to drive it with out a library!
These chips obviously aren't meant to be used in conjunction with Arduinos or DIY. Rather, they help with product integration by connecting various human-machine-interface elements via a single bus to the main microcontroller, thus reducing the number of connections required, and reducing cost by integration.
There's lots of things us hobbyists use that were never intended for hobby use.
That's part of the fun of it - figuring out how to use something on new ways.
@@pileofstuff Obviously, but for DIY I always recommend to use a microcontroller that has enough connections and processing power so you don't have to invest too much time into engineering for lack of processing power or high integration.
Sometimes you see projects that use multiple Arduino Unos instead of just starting out with for example a Due that would probably be able to handle everything.
Where I see this being most useful is when you need both wifi and also a lot of GPIO.
Something like remote sensor monitoring, or multi-element electromechanical displays
@@pileofstuff True, the dominant platform for Wi-Fi enabled microcontrollers for DIY, the ESP32, offers very little in the way of GPIOs.
of course they are
Instead of writing the inverted bit pattern, use the invert operator:
0xfe -> ~0x01
0xfd -> ~0x02
I'll have to look into that more. Thanks.
Nice info, thanks for sharing it :)
Did not take you long to figure this out. I like your high quality jump cables!
After seeing some examples online, I made a game out of a PCF8574 that puts a button AND an LED on each GPIO. If polling reads are done during a small slice of time, then the off-blink (high during read) is imperceptible. So if you want to prompt a user with 8 fancy light-up buttons, it is possible.
The 3d printer firmware, Marlin, has facilities to use a PCF8574 to drive displays, such as 4/5 data-wire SPI OLEDs. Extra IOs can be used to read a rotary encoder. Nifty to drive a user interface with just 2 data wires.
I'd love to see an example of using this chip as an I2C to SPI converter, particularly an example that is bidirectional, that is, read and write.
I have an SPI e-ink display that I'd rather address through I2C.
Of course a big part of the problem is modifying the display driver to use I2C rather than SPI.
Display has 3 CS, one for the display itself, one for the on-board SRAM, one for SD card reader (which can be ignored)
Then there's the D/C line that controls whether you're sending the display commands or data.
@@danman32 There are endless examples of using PCF8574 to drive LCD displays, but your bespoke E-ink driver? ... Well, that might be complicated. It is probably written in C++ though. You would need to replace the MOSI/MISO/SCK refs, and it may not be possible if driver uses hardware SPI. Oh well.
As long distance hiker, I always wanted an ultra low powered E-ink device to hold maps and do GPS on demand. Yeah, a doomsday prepper phone.
@GnuReligion the thing is, you have to hold the CS line high or low but this chip at any time is all output or all input, so I don't see how you can read from SPI with this and still control the CS (and D/C) lines at the same time.
You can read from some pins while writing the others. With both the Arduino and MicroPython libraries.
I just didn't demonstrate it very effectively.
@pileofstuff I don't think you can at the same time.
So if you output on say data 5, if you switch to input, you'd lose your output during the input.
So if you were using one of these and selected to use pin 5 to use as CS for the SPI, when you had I2C go to read from SPI, you'd lose the CS for the SPI.
Makers of beer flavoured beer, yet on the back they say it tastes of toffee and caramel.
A rats odour has been detected! 😂
There’s also a 16-bit I2C expander: MCP23017. Not sure if they’re cheap these days though.
Thanks. They look like they're $4-5 each in hobby quantities.
@@pileofstuff Yeah, I puzzle over the price of these. Pre-pandemic, it was possible to buy an ATMEGA8A for about $0.70 -- and that could be programmed act like a MCP23017.
@@GnuReligion I ended up using PIC MCU’s I had to act as IO expanders because it was cheaper than buying these IC’s. Also using an MCU as an IO expander allows more flexibility of what you have it to.
For example, on one of the boards I’m using it as an output device and I can PWM the output continuously until the get another command.
@@akhurash Yup yup. Analog read and high-impedance are useful. MCUs with lots of pins are inexpensive, as well. Wonder if all those newly made 74-series, 14-pin chips aren't really are really some kind of standardish FPGA device.
Just a heads up bit of info....there is also a PCF8574A which is exactly the same but with addresses 0x38 to 0x3F, (so you can have 128 IO). This isn't always, if ever, documented by 'sellers', is not shown as the 'A' variant on the chip, (no surprise there) and the TI datasheet for the PCF8574A confusingly and erroneously uses both ranges for the one device.
The NXP and Philips datasheets for the PCF8574 are better in this respect and do document both ranges.
So if you suddenly find a chip doesn't work then check if it's the 'A' variant and change the address in the code accordingly. (Use the I2C scanner to determine device addresses)
Excellent information.
Thank you
@@pileofstuff Excellent video, thank-you!
When are you going to get a beer that claims to taste like beer.😮