MCP23017 Port Expander and ESPHome: Add More I/O Pins to Your Project

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 มิ.ย. 2024
  • In this video, I'll take a look at using the MCP23017 16 port I/O expander with an ESP8266 (or ESP32) and ESPHome to add from 16 to 128 additional digital I/O pins to your project using just the 2-wire I2C bus from the ESP board. I'll cover the pin out, connections and limitations of the MCP23017, the ESPHome code and finally show how I use multiple port expanders to control 72 individual LEDs and three push buttons from a single ESP board to build a completely impractical clock!.
    Written version of this project with parts, wiring diagrams and more: resinchemtech.blogspot.com/20...
    Chapter Links:
    =============
    00:00 Intro
    01:26 ESP and MCP23017 Overview
    03:57 Pinout and Limitations
    06:29 ESPHome Component Mapping
    07:28 Basic Bench Test
    10:10 ESPHome Bench Test Config
    11:29 Multiple expander wiring and ESPHome Config
    13:07 A Crazy Clock Example with 75 I/O Pins
    14:34 Building the Clock Face
    16:16 Building the Clock Controller
    18:44 Testing the Final Clock Build
    19:36 Wrap Up And Other Ideas
    Parts Used or Shown:
    ===================
    You may not need all these parts, or may need additional parts, depending upon your particular project. This is just a list of what I used or showed in the video:
    9" Wooden Clock Face: amzn.to/3LWvUv5
    3 mm LEDs (colors of your choice): amzn.to/3QcAqIv
    24 gauge bare copper wire: amzn.to/3twydyR
    5V 10A power supply (in lieu of bench power): amzn.to/46KZD1X
    5V to 3.3V buck converter (in lieu of bench power): amzn.to/3QcB9JJ
    Wemos D1 Mini (ESP8266): amzn.to/48TXZgG
    MCP23017 16 Port I/O Expanders: amzn.to/3SeVqQr
    Breadboard Jumper Kit: amzn.to/45pqG1L
    Dupont Jumper Wires: amzn.to/3ZX8oEe
    1/4 Watt Resistors: amzn.to/46JDlxJ
    Normally Open Pushbuttons: amzn.to/45ppJ9H
    Other optional tools and items:
    ------------------------------
    Compass: amzn.to/3tt1vOG
    Digital Angle Finder: amzn.to/45uIoAU
    ILI9341 2.8" TFT Display: amzn.to/3MmE2p9
    Hot Glue Gun and Glue: amzn.to/3ZR6QLS
    Protoboard/Breadboard (updated version from the old one I used): amzn.to/3tzBPQE
    Some of these links may be Amazon affiliate links. Use of these links will not affect your pricing, but as an affiliate this channel may earn a small commission if you make a purchase. Any commission earned will go towards future projects and videos.
    Addtional Information/Links:
    ===========================
    Written version of this project: resinchemtech.blogspot.com/20...
    MCP23017 Data Sheet: ww1.microchip.com/downloads/e...
    ESPHome Code used for Breadboard Test: gist.github.com/Resinchem/2d1...
    If you'd like to help support this channel, or just say thanks, you can consider buying me a cup of coffee:
    www.buymeacoffee.com/resinche...
    #esp8266 #esp32 #esphome
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 55

  • @Dorff_Meister
    @Dorff_Meister 7 หลายเดือนก่อน +2

    Really useful overview given the limited IO on these uCs. Nice find and great explanation. Thanks!

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +1

      It's not something that will be used very often in most projects, but it is a nice component to have in your pocket should you need extra I/O. I was really surprised at how easy they were to code in ESPHome (and Arduino)... I expected that part to be a bit more complex, but once the port expander is defined, everything else works just like any other normal I/O pin.
      Now the really challenging part (for me) is creating that PCB! Thanks for commenting.

  • @mr.bianchirider8126
    @mr.bianchirider8126 7 หลายเดือนก่อน +1

    I used a TCA9548A I2C multiplexer board to connect four BME280 sensors to a Wemos ESP8266. I nearly went cross eyed doing the Arduino IDE code and wiring. I cannot imagine doing this to a clock. Yet again, thank you for a great video.

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน

      Yeah... it was a "challenge"! I go into just a bit more detail in the written blog article, but those Dupont jumpers didn't want to stay put on the thin wires from the LEDs. Every time I tried to add a wire, I'd knock two or three others loose. I had to result to adding a little hot glue to each connection to keep it in place.
      Then there were multiple times, I'd get the pins reversed or just one breadboard hole off and the LEDs would light up in the wrong order. And reaching into that rat's nest of wires to move a jumper was no easy feat! Definitely not the optimal way to build a clock.
      But once I got the wiring correct, the Arduino code wasn't too bad in my case (it is actually Arduino code running the demo at the end). I skipped the A0/0 pin on each board and used pins 1-15 (from the Arduino side), so that lined up perfectly with minutes 1-15 in each of the four 15-minute segments. That made it easy to just loop from 1-15 in each segment to turn the LEDs on in order (or to calculate which LEDs to light up for minutes). Again, there's a bit more detail in the blog article.
      Thanks for watching... and as always, I appreciate the comment!

  • @MaultierKojote
    @MaultierKojote 7 หลายเดือนก่อน +1

    love your videos and the whole frankenstein approach to this clock. looking forward to your pcb. cheers mate

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +2

      Thanks! I had actually hoped I would have the PCB done and could show the completely built clock. But between actually doing the design and bench test, plus learning to use the PCB design software, I simply didn't have time. I had no idea going into it how much of a wiring mess it would turn out to be in the end!
      I hope to maybe do a follow up video down the road when I do get a PCB and finish off the 'real' clock. Thanks for watching and taking the time to leave a comment.

  • @WndSks
    @WndSks 7 หลายเดือนก่อน +1

    These projects are nothing like the other smart home channels are doing, keep up the great work and electrical details!

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +1

      Thanks! I do like to focus on DIY smart home devices that don't need to rely on the Internet/cloud. And occasionally I run into a component like this one that might be useful for others that are doing their own DIY projects, so I try to show some examples of how it might be implemented, then the details on how to actually wire and use it.
      I rarely review any sort of commercial product (there are plenty of other channels that do that already)... unless I take a commercial product and try to find a way to make my own DIY version that is either lower cost or has more features.
      Thanks for watching... and taking time to leave a comment. I appreciate it!

  • @santosh5290
    @santosh5290 3 หลายเดือนก่อน

    Excellent tutorial and smart project...

    • @ResinChemTech
      @ResinChemTech  3 หลายเดือนก่อน

      Thank you! I appreciate it.

  • @Sekir80
    @Sekir80 7 หลายเดือนก่อน +2

    What a nicely timed (see? :D) video! I'm about to build a clock which has 60 LEDs, very similar to yours! I'm not using port expanders, though, but I'm glad I learned something interesting today. Thank you!

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +1

      You are most welcome! As I mentioned, this isn't necessarily the best design for a clock! I've built other clocks that use WS2812b LED strips (and therefore don't require the extra pins), but the goal here was to use individual LEDs as an example of using multiple port expanders. I like the look and function of this 'analog' version (other than my rushed and not-so-great paint job). If I ever get around to creating a PCB version, I'll probably start over with a new clock face.
      Good luck with your project and let me know how it turns out. And have a good 'time' building it!

    • @Sekir80
      @Sekir80 7 หลายเดือนก่อน

      @@ResinChemTech For a tech demo using these expanders is quite well done! Of course it's easier to use WS2812, everything is just code, you can choose colors after building the clock, you can dim it easily, tons of advantages there. That's why I chose them. I found the same form factor as standard LEDs, 5mm, diffused.
      Good luck for the PCB version, that will look awesome! Good 'time', hehe, well done!

    • @rodneysmith1750
      @rodneysmith1750 7 หลายเดือนก่อน

      @@ResinChemTech I am looking forward to the video about learning how to design and create your very own PCB, I might suggest PCBWay. I would also consider making a board for the clock back and connecting it with one or more IDC ribbon cables. the connectors are fairly easy with a vise or parallel jaw pliers.

  • @stevenbeebe35
    @stevenbeebe35 6 หลายเดือนก่อน

    THANK YOU!!! Finally someone show an MCP23017 with an external power supply!!! THANK YOU. Yes, people show the typical 1 LED and switch powered off off the Raspberry or Arduino... Guess what happens one day when the student plugs in 8 or 9 LEDs and wonders why his Arduino or Raspberry fry like Kentucky Fried Chicken. THANK YOU.

    • @ResinChemTech
      @ResinChemTech  6 หลายเดือนก่อน

      You are welcome! Yeah... I have heard of a lot of situations where people try to power external devices (most notably 5V LED strips) off the 5V pin of an MCU, particularly ESPs. They simply don't take into account the current draw and what the GPIO or other pin on the MCU or dev board is rated for. And yep... it might not happen right away... but eventually they end up damaging or destroying the board.
      That's why I try to stress in my videos when it is appropriate... or more importantly NOT appropriate... to provide power to an external component via the 5V or 3.3V pin from the MCU/dev board. And how to run power in parallel when necessary. But, alas, not everyone watches that portion of the video or opts to ignore it... then they post a comment or issue that their ESP8266/ESP32 quit working!
      Thanks for watching... and I greatly appreciate the kind comment.

  • @electronical_matrix
    @electronical_matrix 5 หลายเดือนก่อน

    Great explenation

    • @ResinChemTech
      @ResinChemTech  5 หลายเดือนก่อน

      Thanks! I appreciate the comment.

  • @wagnerfontes2
    @wagnerfontes2 หลายเดือนก่อน

    Thank you for the video!
    That's the first time I found a good explanation on how to expand ESP GPIOs and program them in ESPHome.
    Would you consider making a video on multiplexing the analog inputs of an ESP and using that info in ESPHome?
    You mentioned that possibility and I got quite interested.

    • @ResinChemTech
      @ResinChemTech  หลายเดือนก่อน

      You are welcome. I'm glad you found the video helpful. I can certainly consider doing a video on an analog multiplexer, I'm just not sure when I might get around to it. I like to have a project or goal where I can demonstrate the use, so I'll have to find a good use case for myself.
      Thanks for watching!

  • @samk2630
    @samk2630 4 หลายเดือนก่อน

    Just stumbled upon your channel from the algorithm and I’m very pleased. Great content, clear and concise. Thank you for this.
    You’ve given me an idea for a clock using WS2812 LEDs. Would only need 3 lines (GND 5v and data) to do something similar!

    • @ResinChemTech
      @ResinChemTech  4 หลายเดือนก่อน

      Glad you found me! Yeah.. as I mentioned in the video, this isn't necessarily the best way to build a clock, but it was really just an example of how to use the port expanders. Funny thing, though... once I created a PCB and got rid of the breadboard, I really liked how the clock worked and have kept it on my desk.
      I have also built a couple of matrix clocks using WS2812b LED strips. These can also act as a scoreboard, countdown timer and a text display. I have a couple of videos covering them if you are interested.

  • @rodneysmith1750
    @rodneysmith1750 7 หลายเดือนก่อน

    Wow! I love the name Frankenclock, which looks like a lot of my projects. I have never used or so far needed a port expansion, but I may find a use case now that I have watched the video. As always, a great video was very well presented and produced.
    My kitchen upper cabinet interior lighting (so far) consists of seven cabinets and I did use the Aqara Zigbee door switches, but they are all dimmable (PWM) and currently running at about 80% max brightness.

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +2

      Thanks... as always, I appreciate it!
      If you didn't catch it, when I showed the cabinet example and said it was "inspired" by a subscriber... that was you! I knew you were doing your project in a different manner, but it was your project that got me originally thinking about an example where a port expander might be used. So thanks for the inspiration on that. :)
      I do mention PWM briefly in the written version/blog article for this project. While I didn't test it, I suspect using these particular port expanders might have issues with PWM just do to the precise timing required. But maybe someone else has tried or used these (or similar) port expanders with PWM and can either confirm or deny that they cause issues.

    • @rodneysmith1750
      @rodneysmith1750 7 หลายเดือนก่อน

      @@ResinChemTech That cabinet is done including power supplies, control, and wiring. I will be adding some RGB to the same setup for accents on the countertop and along the ceiling, the controller already has the D1 for the RGB controls mounted. That was my first with two D1s in the same box, kinda crowded...

  • @MrBobtwang
    @MrBobtwang 7 หลายเดือนก่อน

    Thanks for the video - very comprehensive. I've just spent several hours 'debugging' my code on a similar project only to casually glance at the pinout diagram of the MCP23017 in the top RH corner of your video. And there was me thinking that port A would be on pins 1 - 8 and port B would be on pins 21 - 28 .... I don't suppose I'm the only person who knew better than to RTFM. Doh!

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +1

      You are welcome... and I'm glad if my video helped out, even if just a little. But don't feel bad. I don't know how many things I've fried due to not paying close enough attention to the pinout and doing something bone headed like reversing the polarity on the voltage leads.
      In fact, I'm working on a PCB version for this same clock and port expanders. The video will probably be released in a couple of weeks (still building) and I made a bone head move with this as well. I'll cover that in the video... but sneak peak, the LEDs are wired in backwards order from the way I intended.
      Thanks for watching and taking the time to leave a comment!

    • @santosh5290
      @santosh5290 3 หลายเดือนก่อน

      Excellent video and explanation too

  • @PersonXes
    @PersonXes 5 หลายเดือนก่อน

    Very clear! Do you happen to know about any solution that allows to connect an extra UART based sensor?

    • @ResinChemTech
      @ResinChemTech  5 หลายเดือนก่อน +1

      There are certainly options out there for expanding the number of UARTs on a device. A simple Google search for UART Port Expander will turn up multiple possibilities based on your particular MCU and needs.

  • @hybrid.domotic
    @hybrid.domotic 3 หลายเดือนก่อน

    Excellent tutorial Sir, but i have a question: i tried to expand Gpio pins using 74HC595 and i got noise problem, once switching on and off my roller shutter or my hair cutter !!! if use low voltage machines (12v ) no problem or no load also, and I found on the internet an article about noise problems using 220 v load on relays (the problem comes only with 74HC595
    if I use the same relays with the main Gpio of my esp32 Gpio exp (13 or 14) everything is ok
    so the question is: won't we get the same noise problem using the MCP23017? thank you Sir for replying .

  • @Tntdruid
    @Tntdruid 7 หลายเดือนก่อน +2

    The Amazon link is sold out, any AliExpress links?

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +1

      Are you referring to the link for the MCP23017? I appreciate the heads-up but I did just recheck the link and I do show them in stock (at least in the US Amazon store). Of course you can do a simple search for 'MCP23017' on Amazon and see if other sellers might have them in stock. Or as you mentioned, check another site such as AliExpress. You might be able to find better pricing there, but with potentially longer shipping time.
      If you are seeing some other part that is sold out, please let me know. I try to check all my links the day before the video is published, but it is not unusual for an item to sell out after I publish (or simply become unavailable). Usually you can find the same item from other sellers listed on the same Amazon page that shows the sold out or discontinued item.
      But I appreciate the heads up. I try to update links if needed, but to be honest, it's nearly impossible to keep up with all the changes and sellers on Amazon.

    • @Tntdruid
      @Tntdruid 7 หลายเดือนก่อน +1

      @@ResinChemTech yes the MCP,-

  • @don_cc123
    @don_cc123 7 หลายเดือนก่อน

    Nice job explaining this chip. Any chance of publishing an STL file for the LCD bezel you created? I'm not a CAD guy and have been unable to find suitable bezels for my projects using both 2.8" and the larger 3.2" ILI9341 displays.

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน

      Thanks. My thoughts on the .stl files was that if/when I get a PCB created, I'd create a Thingiverse project of for all the parts: bezel, stand, LED covers, etc. These might end up changing in the final version so I don't really want to put them out there now, as no one is going to build this particular "Franken-clock".
      But for the bezel, you definitely don't need anything as fancy as a CAD application. I just quickly did this in (free) Tinkercad: It is just a 2mm tall rectangle that measures 82 x 64 mm. Then a rectangular 'hole' that is 66 x 48 mm is centered over the initial rectangle and the two objects are "grouped" using the Tinkercad function. That leaves you with the frame you see in the video. It really is that easy and there is nothing fancy or difficult about creating it. I then simply super glued it to the front face of the clock. You could easily adapt this to both size displays by just altering the dimensions of the initial rectangle and the 'hole' that you insert into it. If you haven't tried Tinkercad, I'd highly recommend it as it is an easy to learn and easy to use solution for creating basic shapes for things like this or simple geometric shapes for controller enclosures, etc. without the steep learning curve of more sophisticated CAD-like applications.

    • @don_cc123
      @don_cc123 7 หลายเดือนก่อน

      Thanks so much for the details, I will try to give it a go with Tinkercad!
      @@ResinChemTech

  • @MisterkeTube
    @MisterkeTube 2 หลายเดือนก่อน

    Just wondering: can these things do PWM at a decent frequency? Ex. if you wanted to dim those minute-LEDs without changing the resistors ...

    • @ResinChemTech
      @ResinChemTech  2 หลายเดือนก่อน +1

      I don't believe I mentioned in the video, but I do talk about PWM in the related written guide for this project ( resinchemtech.blogspot.com/2023/10/IO-expander.html ):
      "While PWM (pulse width modulation) is technically digital and is commonly used for things like controlling brightness of a light by quickly switching the signal on/off, it is unlikely that the MCP23017 would work well for PWM due to the precise nature of the timing required. But your mileage may vary."

  • @danman32
    @danman32 7 หลายเดือนก่อน +1

    There are lots of models of port expanders. The APC old style display board for their PDUs use 9555. The relay boards use an 8 port expander.
    It's a shame they all use 0x20 base addresses

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +1

      Yep... as I mentioned near the start of the video, there are many, many different options for adding pins or expanding ports. But I just selected the MCP23017 as the one to show in this video... with the idea that if someone just beginning their journey with DIY electronics understood the concept of how to use an expander, then adopting to another IC or expander might be a bit easier.
      But I agree with you about the base address. There has been more than one occasion where I've wanted to use multiple I2C devices with the same controller (like a ToF sensor), but they don't have a way ( or at least not an easy straight-forward way without constructing some sort of interface and sending special commands) to change the I2C address. That was one thing I liked about the MCP23017... the three address pins made it very easy to change to any one of eight I2C addresses. But again, it is not the only option for something like this.
      Thanks for watching and taking time to leave a comment. I appreciate it.

    • @danman32
      @danman32 7 หลายเดือนก่อน +1

      @@ResinChemTech the 9555 and the one on the relay board also have pins to change the address to one of possible 8, but all of them start at 0x20 so you're limited to 8 of any of them.
      I suppose one trick to go beyond 8 is to not use one of the addresses and use the A0-2 address pins as chip select pins.
      For example, tie A1,A2 to ground, and use A0 as chip select, never use 0x20 as that would always be in conflict when A0 is at ground (not selected) and vcc on specific chip to select as 0x21.

  • @joshuaobelenusable
    @joshuaobelenusable 7 หลายเดือนก่อน

    So for an ESP32, can this technique use both i2c busses for a total of 16 port expanders with 256 IO?

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +1

      Theoretically, yes I believe you can. I think how well it works will depend on the types of input/outputs you are using. For example, while PWM is technically an binary signal, I don't think these expanders would work very well for PWM output due to the precise timing required (although I have not tried a PWM signal with them).
      But yes, each I2C bus can have its own devices/addresses, so you could use the 8 available I2C addresses of the port expander on each of the two I2C busses on the ESP32 for a total of 16.

  • @Gitbizy
    @Gitbizy 2 หลายเดือนก่อน

    How do I add multiple A/D ports to the ESP32? I want to be able to read ~5-10 analog voltages. Thanks in advance!

    • @ResinChemTech
      @ResinChemTech  2 หลายเดือนก่อน +1

      Search for analog multiplexer. You should be able to find your answer there.

  • @plazmax
    @plazmax 5 หลายเดือนก่อน

    Hello, I came across it while doing an internet search while working on a similar project. Your explanation is very nice and informative. I am trying to do it with a 5v 16 channel relay card and esp32 via the blynk application. If I add MCP23017 to the project, it seems like it will work. Thank you very much, it is appreciated.

    • @ResinChemTech
      @ResinChemTech  5 หลายเดือนก่อน +1

      You are very welcome! In case you didn't catch it in the video description, I have a related blog article with a bit more information than I could present in the video. You may or may not find this helpful: resinchemtech.blogspot.com/2023/10/IO-expander.html
      As I mentioned in the video, it isn't necessarily the best way to build a clock but for me it was a good way to experiment with the port expanders. In addition, this project led me to developing my first custom PCB board (shown in a separate video) so that I could keep the clock without the breadboard mess. I actually really like the clock now that I have it mounted on a PCB, and it sits nicely on my desk.
      Thanks for watching. And best of luck with your project!

  • @deepdodiya1483
    @deepdodiya1483 7 หลายเดือนก่อน

    great and very useful but i have one question why SCL and SDA pins are not pull up its require to pull up this pins ?

    • @ResinChemTech
      @ResinChemTech  7 หลายเดือนก่อน +1

      MCP23017 has internal pull up resistors that are enabled by default when initially setting up the devices.

    • @deepdodiya1483
      @deepdodiya1483 7 หลายเดือนก่อน

      can any issue when i connect pull up SCL and SDA with 10K ? Also I want to use all 16 GPIO as a Input pins with esp32 its right to connect directly or use any current limit resistor for each pins? @@ResinChemTech

  • @higorrezende59
    @higorrezende59 หลายเดือนก่อน

    How to teach how to create 32 in and 32 output with mcp 23017 on esphome.
    I copy your code and put it in Esphome plus any changes to the name of the problem and it doesn't work. does not compile

  • @northstar5405
    @northstar5405 7 หลายเดือนก่อน

    Hello Mr.
    In the last couple of weeks I had an opportunity to purchase esp32 development board and w2812b LEDs and made it works per your basis instructions (I'm not techies guy) however, how do I able to use multiple LEDs strips on single esp32?, thank you

  • @hybrid.domotic
    @hybrid.domotic 2 หลายเดือนก่อน

    Excellent tutorial Sir, but i have a question: i tried to expand Gpio pins using 74HC595 and i got noise problem, once switching on and off my roller shutter or my hair cutter !!! if use low voltage machines (12v ) no problem or no load also, and I found on the internet an article about noise problems using 220 v load on relays (the problem comes only with 74HC595
    if I use the same relays with the main Gpio of my esp32 Gpio exp (13 or 14) everything is ok
    so the question is: won't we get the same noise problem using the MCP23017? thank you Sir for replying .

    • @ResinChemTech
      @ResinChemTech  2 หลายเดือนก่อน

      I haven't tried using the 74HC595 as a port expander. Nor have I tried using the MCP23017 for controlling relays with high voltage AC. So I really can't tell you if you would experience the same issue with the MCP23017 or not.