Expand your GPIO! PCF8574 & MCP23008

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 มี.ค. 2022
  • High quality PCB Services pcbway.com Welcome to another Voltlog, in this video we're going to take a look at an easy way of adding more GPIOs to your project because if you’ve been tinkering with electronics at some point sooner or later you’re going to need more GPIOS than what’s available from your microcontroller.
    →Checkout my Tindie store voltlog.com/y/tindie
    →PCF8574 Datasheet voltlog.com/y/489mb
    →MCP23008 Datasheet voltlog.com/y/v7rbx
    →Evaluation Board Source [Github] voltlog.com/y/lumxj
    →ESP32 Tasmota Valve Controller [Tindie] voltlog.com/y/s7rc4
    →Support the channel via Patreon, Paypal or Bitcoin
    www.voltlog.com/donations
    →Support the channel by clicking these links (CommissionsEarned)
    Aliexpress voltlog.com/y/kr0sa
    Ebay voltlog.com/y/jzkfp
    Amazon.com voltlog.com/y/qw4d3
    Banggood.com voltlog.com/y/o4025
    →Blog Post
    www.voltlog.com/
    #PCF8574 #MCP23008 #GPIO
    Luckily this problem is not new, it has been around since the introduction of digital processors so there is a very convenient solution to our problem in the form of GPIO expanders. They can come in many shapes and sizes but the key feature is that they usually take a serial input which means a low pin count for the input and they provide a number of different outputs depending on the package. So here is for example the datasheet for a very popular GPIO expander chip, this is the PCF8574, the datasheet is from NXP but this is manufactured by different companies and this is a big plus because there is a higher chance of finding these in stock.
    If we take a look at the block diagram we notice, there is an I2C interface, there are 3 pins for settings the address on the I2C bus, this way we could have up to 8 of these chips on the same I2C bus each with its own address, there are 8 GPIOS at our disposal and we have some bonus features like the interrupt pin which could signal to our controller when there is a state change so we don’t have to keep polling the chip, because this chip provides input and output capability. So by using just 2 pins for the I2C bus, we get 8 GPIOs in return, which is pretty neat. This particular device can drive up to 10mA per port with a max total of 80mA per package, but you can also parallel output ports together to drive more current to a single load if that is needed. So it’s pretty comparable to what you would get with a typical microcontroller.
    There are also variants of this chip that have a higher current drive capability up to 200mA per package and they repurpose the INT pin as an address pin which expands the total number of devices on a single bus up to 64. So you will certainly find something that suits your needs.
    Another popular option is the MCP23008, this has similar functionality I2C or SPI input interface, 8 GPIOs, 3 address pins so up to 8 devices on the same bus, interrupt capability, up to 125mA total per package with up to 25mA per pin. Fairly similar specs and I could be using any one of these chips for my application, the decision will probably come down to cost and availability for the particular package that I will end up using.
    With these two options in mind, I went ahead and designed an evaluation board in Kicad, because first of all I would like to evaluate how the firmware support is like for these chips and I also would like to confirm that there is no unexpected behavior because I will be using these to drive triacs that control some mains powered load, I want to make sure everything works as expected.
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @avejst
    @avejst 2 ปีที่แล้ว

    Great walkthrough of the process 👍
    Thanks for sharing your experience with all of us 👍😀

  • @bertoid
    @bertoid 2 ปีที่แล้ว +1

    I just use serial to/from parallel shift registers with latches:-
    74HCT595 for output, CD4021 for input.
    The 595 doesn't have high drive capability, but that is often not needed.

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

    Thanks for this help full tutorial. It's very good! Thanks for all your work!

  • @danekmartin45
    @danekmartin45 2 ปีที่แล้ว +1

    I think that the reason why the LEDs driven by the PCF8574 are so dim is that the PCF doesn't have classical push-pull output, but a weird one where it's either in low state (which can drive up to 25 mA typically, the 10 mA is minimum spec), or in high state, which has only a 100 uA current source. So if my guess is correct, you are driving the LEDs against ground, so you are driving them with 100 uA. See the datasheet, page 12.

    • @voltlog
      @voltlog  2 ปีที่แล้ว +1

      Your guess is correct. It is indeed a trap for those like myself which don't read deep enough into the datasheet 😂

  • @DustinWill
    @DustinWill 2 ปีที่แล้ว

    Very interesting!

  • @user-ml1jx3oi8r
    @user-ml1jx3oi8r ปีที่แล้ว

    Is it possible to use audio input (e.g. inmp441 i2s) or audio output (e.g. max98357A i2s) via these port expanders? If yes how is it done, especially the pin config? Thanks for any advice. I only got buttons, leds, encoders to work.

  • @sanjikaneki6226
    @sanjikaneki6226 2 ปีที่แล้ว

    Florin , this might be a bit of but when do you think it is worth using these kinds of IC since at some point getting another MCU or larger package would be cheaper (and i assume better due to lower latency ) .
    Also in this case i assume you are using them as DC signals wouldn't some multiplexed flip plops be better? (maybe the IC is this inside , not sure).
    Also relating the LEDs , i saw your video but i am still not sure how to find high efficiency ones. Or rather what would be some good filters in order to find some or , lets say mouser/farnell . More cnd /mA is the goal BUT what would a good ratio be ? and/or what would be a good way to find them ?

    • @voltlog
      @voltlog  2 ปีที่แล้ว

      There are multiple factors to consider so it's not a matter of which option is best in general but which option is best for your specific application: I have to consider cost, current drive capability, control gpio usage and firmware support. So for this application an I2C GPIO expander is the best solution.

    • @sanjikaneki6226
      @sanjikaneki6226 2 ปีที่แล้ว

      @@voltlog THX , but that about the LEDs?

    • @voltlog
      @voltlog  2 ปีที่แล้ว

      I prefer to use LEDs rated for ~500mcd @ 10mA.

  • @danedwards_ee
    @danedwards_ee 2 ปีที่แล้ว

    Hey Florin! I've used the MCP23017 (16 I/O) on a project of mine. On unexpected behavior I've had ocasionally intermittent issues where on first powerup, it will not react to the first command. Weird. maybe? a library issue. I should test again sometime, but seemed worrying at the time for my project.
    Also, do you have any chatroom where you chat outside of YT? maybe considered making a Discord channel?

    • @dennisfahey2379
      @dennisfahey2379 2 ปีที่แล้ว +4

      I2C is a serial bus of course and any noise during power up / initialization can be seen as bit clocking. Once any bit is clocked you are now out of sequence with your intended framing. Send a reset command or two - be sure and wait for it to serialize - and you should be okay. Also if you are initializing for high speed mode be sure and delay before you send the first commands thereafter. These parts are very primitive (I2C dates back to the 1970's) and today's high end microcontrollers are way faster than the original microcontroller specs (2Mhz or below) supported. Code must be written to tolerate turnaround times and to prevent bashing a transaction in progress.

    • @danedwards_ee
      @danedwards_ee 2 ปีที่แล้ว

      @@dennisfahey2379 Ah, thanks. That might be just it, that actually explains a lot tbh.. I'll keep that in mind when I go back to the project. Pretty sure it wasn't a hardware issue.

    • @dennisfahey2379
      @dennisfahey2379 2 ปีที่แล้ว +1

      @@danedwards_ee - No problem. The thing you get into is if every IO is across that serial bus you are bashing it quite a lot. And of course it is by far the slowest thing in the system. So its imperative to have an I2C service routine that runs that interface intelligently. At the driver level it sort of needs to be abstracted like PCI-E. You post your command and watch for a driver flag that indicates it is completed and if a read cycle - data is available. (Semaphore) You don't want to have the processor waiting for each transaction to complete - doing nothing else. The driver can buffer the commands and handle the actual interface. A common error I've seen is when people add a ton of IO and add I2C muxes to flip between device "groups". The muxes, too, must be locked in state when a serialization and response occurs. Then they are in "IDLE" and free to change the mux and start a new command on an alternate group. Ideally the CPU should be watching a bulletin board in memory of transaction and state with the driver reconciling from the other side. Finally, IF you must for some reason support hot insertion/extraction of an I2C device - that driver better know to timeout and retry a transaction that get corrupted. Sadly I2C has no parity or error checking - whatever gets manifested by the corruption will be executed as a valid command. It was never intended for this mode.

  • @rahulkushwaha9500
    @rahulkushwaha9500 2 ปีที่แล้ว

    how do you make those texts labels in kicad, i mean the inverted ones. dont know what they are called. shown at 4:25 on the left side of baord.

    • @danedwards_ee
      @danedwards_ee 2 ปีที่แล้ว +2

      It's the KiBuzzard plugin for KiCad!

  • @lezbriddon
    @lezbriddon ปีที่แล้ว

    pay extra for the 23008, the 8574 is a nightmare for input, and useless for (+) output as its limited to 100ua .this makes it fine for say keyboard scanning (theres a library/sketch for that) but for driving leds / 7 segment displays or switching transistors for relays i would avoid it

  • @browaruspierogus2182
    @browaruspierogus2182 2 ปีที่แล้ว

    can you make web interface for those devices?

    • @voltlog
      @voltlog  2 ปีที่แล้ว

      Checkout Tasmota.

  • @karabrandsen4200
    @karabrandsen4200 2 ปีที่แล้ว +5

    This is a classic trap with the PCF8574 for which I have fallen my self. The chip has a high rated SINK current (IE current into the pin) where as it only has a 300uA SOURCE current (Current out of the pin). Which makes it not very good at driving loads.

    • @ohmschool
      @ohmschool 2 ปีที่แล้ว

      I fell into this trap too with PCF8574 and its bigger brother 16-bit PCF8575. I solved the problem by adding Darlington drivers like the 8-bit ULN2803 which can sink approx. 60ma per channel, enough to drive mechanical relays.

    • @voltlog
      @voltlog  2 ปีที่แล้ว

      It is indeed a trap for those like myself which don't read deep enough into the datasheet 😂

    • @GnuReligion
      @GnuReligion 2 ปีที่แล้ว

      Yes, the weak source ability of the 8574 surprised me as well. A 595 shift register does not have this problem. Another unexpected quality is the power consumption -- the 8574 can get quite hot.

    • @lezbriddon
      @lezbriddon 2 ปีที่แล้ว +1

      trouble i am having is when i set them to input and apply +v, they show in the code a logic 1 and logic 0 with no volts, but the pin is drawing like 60ma!!! the only 'guess' I have is that the library is only setting them for input while doing the read then they are reverting to output or some other weird thing

    • @GnuReligion
      @GnuReligion 2 ปีที่แล้ว

      @@lezbriddon You set a register mask for reading. There are really only two states though: High resistance with high voltage (read), and Low resistance with low voltage. I have been able to put a button and indicator LED safely on the same pin by rapidly polling. Tie one end of the LED high, through a resistor.

  • @electronic7979
    @electronic7979 2 ปีที่แล้ว +1

    👍