Not enough Arduino Pins? Try this I2C Port Expander! | Chip Tips #1: PCF8574

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
have you ever been working on an Electronics project and find yourself running out of IO pins with so many different sensors and actuators available you may find yourself quickly running out of microcontroller connections a typical Arduino Uno only has six analog pins and 14 digital pins how do you connect everything you need that's when you need one of these it's a PCF 8574 Port expander and today I'm going to show you how to use it my name is Luke and this is terminal [Applause] [Music] curiosity [Music] so this is a PCF 8574 it comes in through hole and surface mount packages and it provides eight additional IO pins using just two on the microcontroller or three if you want to include interrupts but this is optional it uses iqu C to communicate and you can stack up to eight of these chips on the same two micro pins which means up to 64 extra iOS in total for the cost of just two this is done by using these three address select pins which let you configure unique iqu C addresses for each chip there's also an a variant of this ship which is exactly the same but with a different set of iqu C addresses so you could actually stack another eight devices on the same bus if you really needed to although that might be really pushing the capacitance limit of the i c plus if this ship doesn't suit your project for whatever reason then you have a few other options there's the mcp23017 which has 16 iOS per device and a few other fancy features there's also the 74 lvc 595 which is an 8bit serial shift register and there's also the mCP 23 s17 which uses SPI instead of iqu C if you prefer that today's chip tips video is about the pcf8574 and how to use it but if you'd like to see a video on any of these other options listed let me know in the comments I should also briefly cover iqu c as a communication protocol it's a very common interface used between devices over short distances on a circuit board typical applications are one or more microcontrollers communicating to external peripheral ic's the microcontroller is typically the master which controls the clock signal and sends instructions to the slave devices over the data signal these listened for their unique addresses and perform instructions as communicated since it only needs two communication pins it's a very versatile protocol and is used very commonly for a variety of sensors and gips I'm wiring up this circuit using the pinout from the data sheet I'll be using my trusty Arduino Uno to drive the circuit and a separate breadboard power supply this chip can run on 2.5 Vols to 5 Vol power which giv you some flexibility I'll be using 5 Vols I'm using four LEDs and four switches so we can get a good idea of both the input and output functionality the switches are all switching the io pins to ground and have 4.7k pull-up resistors to 5 Vols in this case I'm going to wire all three address pins to ground which gives us an i squ c address of hex 20 as seen here the SDA and pins of the chip are wired to pins 12 and 13 of the Arduino which are dedicated i squ c pins on the Arduino Uno you could theoretically use any digital pins to perform this I squ C function but it's much easier if you use pins intended for that purpose I need to connect the ground pins between the Arduino and the Bread Board according to the data sheet the chip is more effective at sinking current rather than sourcing it so I've wired the LEDs from 5 Vols to the chip with a 470 ohm current limit resistor each in most applications you'll also need to include pull-up resistors on the data and clock lines unless they're already included in the master device the Arduino I'm using here has very weak internal Pull-Ups so I'm going to add 4.7k external ones just to make sure it works properly now let's plug it in and nothing happens that's because we need to write some code first I'm going to start with the simple program to test the outputs of the chip this will work by cycling from 0 to 255 which is 8 Bits and turning on each LED for each corresponding bit I'm using the wire Library which is a standard Library included with the Arduino IDE and it's the default Library used for communicating through i squ c the address of the chip is hex2 and the read right bit is automatically managed using the read or right function with don't have to worry about that there's a silly typo let's fix that and uploaded so it looks like that worked well we can see the LEDs are cycling in a binary counting function they seem to be changing a bit slower than I thought they would Ah that's right this is because we're counting for all eight bits of the port but only the four most significant are used for the LEDs as outputs the others are inputs so if we change this line of code to shift all bits by four and recompile there we go now we can see all LEDs are counting much quicker next I'm going to modify the program we've just worked on so that instead of writing to the outputs we're now going to read them as inputs so I'll comment out the previous code and push that out the way I'm going to define a new variable called read value and this will be used to capture the read information of the chip which in this case is the four different switches this information will then be printed to the terminal so that I can directly verify that the code is working and reading the states of each switch I'll print out these states in binary format just to make it easier to read we'll compile it again open the terminal looks pretty good so when I press one of the switch buttons it transitions from a 1 to a zero on the terminal and as I click down multiple switches it affects multiple answers in this case I've wired it so that when the switches are activated the signal gets pulled to ground which the Arduino reads as a zero and when the switch is disabled the resistors pull it high so the aino reads this as a one I spent a little time playing with that code and now I've made a program that combines the input and output features of the last two that we' looked at so first it includes the wire Library so that we can talk through iqu C Communications then we Define the device address as hex2 in the initialized code I'm setting all outputs as on so that when I turn on any switches it can pull them down to zero I found that if I didn't set this the code would get stuck on certain inputs and I could only change them once next I Define read value which will be the value that captures any red values from the port and that's also been defined as all ones so that it can be reset to Zero by the switches next I have an infinite Loop and within this we check if there are any data on the bus that can be read if so I read it and capture it and then shift all the four lowest bits to become the four highest bits this captures all four values of switches and then sends them back onto the LEDs and here's the result of this final code here we can see that we have four inputs that are being directly translated to four outputs using only two pins of the Arduino for iqu C this is a great demonstration of the PCF 8574 and how it can provide extra iOS to your project now I briefly mentioned earlier that this chip also has interrupt capability in this case if we refer to the data sheet this tells us that an interrupt signal is generated anytime there's a rising Edge or a falling Edge on one of the port inputs so this tells us that anytime one of the input signal changes the interrupt pin gets pulled low you could wire this directly to an interrupt capable pin on the Arduino itself and then link that to an interrupt service routine in code now if you'd prefer to not do all the fun component wiring work yourself there are breakout boards available just like these ones which can be used exactly the same all you need to do is plug in power ground clock and data and program it using the same software some of these use jumpers to set your address whereas some of them use switches and many of them allow you to daisy chain them multiple together in case you want to use multiple devices these units are good for if you want to save time by skipping all the component work and just do plug and play for a larger scale assembly personally I quite like doing the Hands-On component level stuff but it's up to you and that's how you can use the PCF 8574 to get more IO pins on your electronics projects if you found this video helpful give it a like and if you want to see what I'm using these chips for in my next project consider subscribing cheers
Info
Channel: Terminal Curiosity
Views: 2,652
Rating: undefined out of 5
Keywords: #arduino, #PCF8574, #I/O pins, #hobbyElectronics, #electronics, #microcontroller, #i2c
Id: 4vDW4iMZMSo
Channel Id: undefined
Length: 7min 59sec (479 seconds)
Published: Sat Apr 06 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.