MCP23017 GPIO Expander Demo PCB: Arduino Uno Relay Driver

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
here's a quick easy way to get up and running with the mcp23017 gpio expander we'll use it to read in button presses and control relays using this pcb sponsored by pcb way the mcp23017 is an i squared c version of the 16-bit bi-directional i o port the chip has three address pins for i squared c address configuration so you can have up to eight on one bus and the chip can run from 1.8 volts to 5.5 volts so that makes it convenient for either 5 volt or 3.3 volt projects the 16 ios are split up in two different ports there's two output interrupt pins that can be configured so that when there's activity on one of the groups of eight pins an interrupt will occur for that group or it can be configured so if there's activity on any of the pins both outputs will trigger an interrupt depending which way you want to handle it so if this is hooked up to an arduino instead of continually pulling over the i squared c bus if there's been activity on the pins the arduino can just wait to be interrupted and then go and check which pin had the activity unlike some gpio expanders this one can both sync and source current where each pin can have a max 25 milliamps so in practice i would try to not draw anywhere near this amount of current per pin but between all the 16 ios the chip itself can only have 150 milliamps through the ground pin or 125 milliamps through the positive supply pin so if you were syncing and or sourcing current simultaneously from all 16 gpios to stay within this 125 milliamps one example would be if all pins were equally sinking or sourcing 7.5 milliamps it would keep us just under this 125 milliamp max part of the max current for the chip would include its own supply current which is only one milliamp max so depending what the pins are used for this needs to be kept in mind to not exceed the limits of the chip looking at the i squared c address for the chip the address contains the seven bits where the lower three are the address configurable pins and the upper four are zero one zero zero so if we have all three address pins at zero zero zero the device would have an i squared c address of twenty hex and as we change the address pins if we make them all one the highest address is 27 hex here's the schematic for the evaluation board i came up with basically we have the gpio expander here it's capable of driving up to eight relays through this uln 2003 darlington transistor driver for the first seven and then i put a discrete transistor driver for the eighth relay and also on these eight outputs i tied in eight status leds so we can see when each relay is on four more are configured as inputs so i have four push button switches and the final four are just spare gpios on this header pin so i can use them off the board as external inputs or outputs if i want the relays are double pole double throw so each relay has two separate common and normally closed and normally open sets of contacts i put all of those sets of contacts on three pin headers so i can access both switches in each relay the relay has its own dedicated power source and these happen to be 12 volt coils so i'm providing 12 volts on this power pin with a common ground and i'm powering the rest of the logic from just 5 volts here and i would be connecting an arduino i squared c bus with ground as well on this header i have on board pull up resistors for the i squared c pins and if i don't need them like if i'm connecting multiple boards together i can just remove the jumpers and make sure there's only one set of pull ups in the whole i squared c bus i have three address pin jumpers here so i can install or remove them to set whatever address i want and there's just a couple of electrolytic capacitors here that i can scatter through the board to help filter the relay power supply the relays i'm using are the g5v-2 series low signal relays so they're only meant to do a couple of amps max but they can do low current so these are good for switching things like line level audio signals rather than heavy voltage and current loads i'm using the 12 volt coil version so the rated current is just over 40 milliamps per relay so if i have all of these on at once i might be drawing up to a total of just under 300 milliamps on this entire driver chip the uln 2003 can drive up to 500 milliamps per channel and of course as more channels are simultaneously turned on i believe i saw somewhere that if all seven channels are on you can do 150 milliamps per channel but i can't directly find that in this data sheet the i o expander output will turn on this darlington pair which turns on the relay and there's built-in protection diodes for any voltage spikes so we should be okay on a demo board doing just over 40 milliamps per channel if all channels are on with these relays being suitable for low level signals like audio one reason i chose this g5v series is because i have over 20 of these included in that big pile of parts that drex sent me a couple of years ago in a mail bag so this is a perfect opportunity to put a bunch of those to use for the demo sketch that i put together i'm using the adafruit library for this chip but there are several other libraries i'm using the arduino uno so between the uno and this demo board i'm just connecting serial clock and data directly between the two as well as 5 volts and ground to power the logic on this demo board i made note of how i've connected the switches relays and spare ios from the evaluation board to the gpa and gpb expander pins the library itself numbers the pins from 0 to 15 in this sequence and that relates to the specific pins on the chip itself i'm using address 20 hex and i'm giving names to all of those pins we want to access then down in the setup initialize the chip set all the input and output pins with pull-ups where needed and i wanted to experiment with the interrupt feature on the gpio expander so i put an interrupt on the four push buttons so that anytime it changes high to low low to high we should generate an interrupt and i can see that on the scope and because in the sketch i'm constantly reading the inputs by doing that it clears the interrupt almost immediately so i'm going to see the interrupt pin changing from an idle high to a momentary low and then it gets cleared when i read the pins again so it goes back to idle high until i change the button state again by pressing or releasing i also want to make sure all the relays start out being turned off and then i'm just going to cycle through all eight relays turning them on for a fraction of a second and turning them back off so i can see that all the relays are working once i'm done setup in the main loop what i'm doing is reading in each of the switches and the spare gpios on the header pin and i'm directly controlling one of the eight relays with each of those eight inputs so as i press a switch a specific relay comes on and as i trigger a spare header pin low a relay will come on and just as a test function in order to control all pins at once on a certain port i can just write all ones to port b using this library command and port b has the relays so if i trigger this gpa 4 pin to ground it will go and simultaneously turn on all the relays wait a second and then turn them all off so that's just another quick test as well as just trying to learn how to use all of the library commands there's some more commands that i commented out but i just put them here as a reminder of what i can do so instead of just reading in one switch at a time using digital read i can just read in the entire port a or port b into a single byte i can write a byte to an entire port all at once like i did with turning on all the relays or i can even treat all 16 gpio as one 16-bit variable reading in both ports a and b or writing to them at the same time so it just depends what i would like to accomplish having this board made it easy to get up and running with this gpio expander and it gives me an extra relay breakout board which i can use for other things like audio channel switching and i can even cascade multiple boards and share the i squared c bus setting each board to its own address and have even more inputs and outputs thanks to pcb way for sponsoring the project and thanks for watching
Info
Channel: Gadget Reboot
Views: 8,412
Rating: undefined out of 5
Keywords: mcp23017, gpio expander, arduino relay driver, uln2003 relay driver
Id: 74DgM2nAeLo
Channel Id: undefined
Length: 9min 45sec (585 seconds)
Published: Fri Feb 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.