Interface ESP32 with the PCF8575 I/O Port Expander

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the esp32 microcontroller contains multiple pins that can drive different sensors and devices however many Internet of Things projects may require more pins and the esp32 only has a fixed number of gpio keys as you can see here they have a 16 channel relay where I am driving several high voltage AC devices in my home automation system in one of my projects I ran out of gpio pins as I am controlling several other sensors connected to my esp32 fortunately the pcf8575 io expander module allows you to add or expand the number of gpio pins that you can control with a 16 channel of bi-directional gpio ports which you can use as either input and output you can use this to drive your LED light display or if you need to read the button switches you only need two I Square C pins and you can attach multiple PCF 8575 for the same serial I squared C bus to drive multiple sensors if you want to learn more then let's start explore going [Music] [Music] hi welcome to donkey Tech in this video I am gonna be explaining how you can interface your esp32 microcontroller with the PCF 8575 io4 expander so what is support expander and why do we need to learn about it basically your esp32 country contains several gpio pins that you can use in your Internet of Things project however if your internet of this project needs to control several sensor devices then chances are you will run out of gpio things to use for example if you're doing a home automation project and you need to control several high-powered devices and you need to control a relay and for each relay input things need to connect it with your esp32 the problem is if you are already connecting or or you have already connected several input or output sensor in your esp32 then you cannot connect this relay directly to your sp32 so that's why you need to have a port expander so that you can expand the number of tpio pins you can control using your esp32 so what is basically this PCF 575 a PCF 8575 module is an IC or it comes in a virtual form in there is already some pull up resistors and some protection circuit devices that you can use I highly suggest that you use the module type so that there's no problem for you or there's no need for you to attach several external pull up resistors this pcf8575 is an i squared C for parallel for expander what it means is that the connecting the accuracy pins SDA and SEL to your esp32 then you can have 16 output for 16 additional gpio for here so this is the port which is the p00 and this is zero seven and from P10 up to the p17 will take a look at the back of this particular module you would notice that face a setup for the a0 A1 or A2 is uh you will need so that you can set the ice currency address of your tf8575 make sure that the middle part is connected in either the ground or in the bdd because this will tell the PCF 8.75 which I squared C address it is I encountered specifically this problem when using this pcf8575 and I did not solder the pattern here and what happens is that my pcf8575 has a different I squared C address that it returns to me whenever I run the Arduino I squared C scanner uh make sure that the middle pad is soldered properly so that you would not encounter the issue that I have encountered spcf8575 is compatible also with most microcontrollers and the standby current consumption is very minimal which is deep and microampere ampere Max so what is this I squared C and how and it helped me the reason that I squared C is really a good uh first of all is that by just using these two uh I squared C's bus Which is the SDA and SEL and we can connect multiple pcf8575 for example first PCF 8.75 may be directly connected with the SDA and SEL pins and in parallel we can have the PCF 8575 connected also to the same serial bus the only thing that you need to remember is that each of your pcf8575 should have a unique I squared C address by soldering the back side of this module so how do you communicate or wire your PCF 8575 with your esp32 it's actually simple as I have mentioned you only need to connect the SDA and the scl PIN to your SD SDA and scl pin of your esp32 and Supply the needed Power by using 5 volts in here so that you can connect it with the BCC and the ground and after these things are connected then the only thing that you need to do is just connect the output Port which is for example this one the P0 I connected it in a switch and then the other end of the switch is connected to Brown for a pull down resistor and this the Power Pin is connected to the five volts of the esp32 in order to control the LED then you just need to connect one of the pins which is the p01 in the anode part and add a current limiting resistor at the other end so basically that's how easy it is to wire the pcf8575 in in the project emulator you would see how this project works the other thing that is really easy to use about the esp32 is when you need to control several high-powered AC devices seeing a wheelie as you can see in here it follows the same wiring or schematic and the only difference is that P0 pin and a p7 up to the p17 just need to connect everything in here to the pins in here of your 16 channel relay so for example the pin one zero zero is connected to pin one of my 16 channel relay and the one thing that you need to make sure is that you have an external power supply that can power for the Relay of relay coil of your 16 channel relay plus the esp32 cannot power directly the channel here so you might encounter some power shortage issues so first thing that I can tell you is just use the internal power supply to power the relay and the next question is how are we going to drive the pcf8575 uh so far I have been using this every Shanti it's called the X-ray pcf8575 are using this library is really easy as you just need to set the values that they're high or low so let's go now on how you can use this Library so this is the project that I am using so the only thing that you need to do is to add this particular library in your platform that I am and I file in my affirm IO so this is the library and the version is 1.1.0 but you have added the library then all you need to do is just import it then set the I squared C address after setting Tab and all you need to do is to hold the pin mode which is the P0 and pin one as you can see it's actually easy similar to how we set it up in a normal Arduino program and You Begin the transaction by communication by using this dot begin once the dot begin is created then you can see in here this is my switch project so in the switch project we just need to create a digital read so in the digital read all you need to do is to read the status or the value in the P0 since the value is low or is in pull down you I'm using a pull down resistor so if it's low then we just turn off the LED and if it's high then it will turn on the LED so in here uh you can even use the pcf8575 i o expander to read the values of the switch here so I have here a button switch and you can expand this project to use the keypad if you have a keypad Matrix of button switches then you can use the pcf8575 for that purpose also as you can see if I just click this one the button then you would notice that the LED is turned on and if I remove my hand then it will turn off so let's try again the other thing is regarding the blink LED and it's really simple it's just the same pattern so this is the blink LED pattern you just need to set the output once the output is set then you would notice that by running this look attraction then you would turn on or turn off the LED so I have here my esp32 and my pcf8575 i o expander including the LED and a button switch and as you can see the LED is being driven by the uh PCF 8.7 the pipe IO expander now we can go into something much more interesting about how you can control a 16 channel relay so this is the code on how you can control the 16 channel relay and the only thing that you need to do in here is that you just need to follow this wiring and the schematic diagram once you have followed the wiring and the schematic diagram it's almost similar to what we did earlier when we blink the LED so we just need to import the pcf8575 and the iceberg address and we need to set also these are two variables if you wanted to control all of the relays in your 16 channel I set it into 0 or 16. everything is okay all you need to do is just set it to Output so I have a for Loop here that will look from 0 to 16 then set the pin mode into output once it is in output mode then you need to begin and I'll just turn up everything in here also since my relay is actually low for it to turn it off you need to set it to high so same a function also in the loop function as you can see in here we can turn on the relay by setting and low but right now if we set the unit right low and we can turn on the relay and then I have added several delays in here and if you want to turn off highlights again then all you have to do is to set the value input so basically that is how easy it is to control your AC devices no matter how many numbers or how many AC devices you need to control by just using the same PCF 8575 library in this video I'm going to show you how we can control our 16 channel relay with the esp32 and the pcf8575 port expander so I have here my 16 channel relay so there is eight here and there are also eight relays in here it contains also the LED for each Channel so that you would see if the relay is triggered and it contains also the octopodler these are the optical blur one for each side so that the input from the esp32 would be isolated from the output that we are controlling it contains also the array here Darlington array transistor so this IC controls each of the individual relay relay and it has also an lm2596 regulator so that the voltage would be properly handled and as far as the input is concerned you have here the DC plus and the DC minus this is where we're going to supply the power external power for our relay and then you have here the 16 channel input so that's numbered from 1 to up to 16 and then there is a ground pin also this is the ground pin and the positive five volts so in our case in here we're going to control the whole Circ this 16 Channel with the esp32 so we're only going to use two pins from the esp32 to control the 16 channels so let's go to the connection so I have here the esp32 and the pcf8575 uh gpio Port expander so it has 16 channels also which is actually appropriate for our 16 channel relay so what we're going to do is just wire up the I squared C SDA pin of our gpio Port expander and connect it also into the BCC and the ground module which I'm using right now is the 3.3 volts so this is the 3.3 volts and the ground is right here I have prepared also the connecting wires for the gpio Port connection so I have here the PC raw up to p7 and then the P10 and up to the P 17 so all of this will be connected into our relay module and usually the connection is really simple for now what I'm doing is just to connect the ground pin here with the ground and then this is my batch power supply so I have here the positive and I have also the negative here so what we're going to do is just wire up the positive into the DC plus and the negative into the DC minus and for each pin that we have in here in the gpio we're just going to match it into the pin of our gpio Port expander so the P0 would be placed in here in the pin one and then the the next pin would be placed here and so on and support foreign
Info
Channel: DonskyTech
Views: 6,345
Rating: undefined out of 5
Keywords: esp32, pcf8575, arduino, portexpander, relay, iot
Id: UJH-STJ3-xA
Channel Id: undefined
Length: 16min 58sec (1018 seconds)
Published: Mon Jun 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.