Menu

MCP23018 library (+ keypad function)

Peter
2017-11-19
2018-03-19
  • Peter

    Peter - 2017-11-19

    Library attached for using the MCP23018 16 bit I2C I/O expander chip. It's similar to the MCP23017, but the pinout is different and it has open drain outputs (not push-pull).
    The I2C bus address is set by cahnging the voltage on the address pin. The default address in the library is 0 (address pin connected to Vss) but this can be overriden by defining MCP23018_Addr in the program code. At present, only 1 device on the bus is supported.

    I built this chip onto a board to use with a keypad so there are functions included for reading the value of a 4x4 keypad. The schematic is below - if you have something different then you will need to alter the library to suit, and also the keypad map.

    I am waiting for some similar I/O expanders which I will add into the library in due course.

     

    Last edit: Peter 2017-11-19
  • Peter

    Peter - 2017-11-19

    Keypad demo video here:

    And an image of the BodgeBoard™ used to add in the pullup resistors which were omitted from the PCB design!

     
  • Peter

    Peter - 2017-11-19

    And here's a simple LED chaser demonstration, showing how to use the port as an output.

     

    Last edit: Peter 2017-11-19
    • Anobium

      Anobium - 2017-12-06

      @Peter. May I lift the library (from here? or, do you have a later version?) and demos etc and include in the next distribution?

      Let me know please.

       
  • stan cartwright

    stan cartwright - 2017-11-19

    Interesting Peter. I just remembered I got five mcp23017 chips that I haven't used and I'll ckeck your code as first post I've seen for similar. I thought of many uses including driving a glcd with lots of pins.
    Thanks for sharing. Nice one.

     
    • Chris Roper

      Chris Roper - 2017-11-19

      Strange that it is the first you have seen Stan.
      The .../GreatCowBasic/Include folder has:
      MCP23008.h
      MCP23017.h
      and
      PCF8574.h

      So the three most common port expanders have built in support alraedy.
      The MCP23018 will be a nice addition.

       
  • stan cartwright

    stan cartwright - 2017-11-19

    True Chris. I hadn't noticed. I forgot I had the chips to until I saw Peter's post. Thanks for the update.
    They look fast-
    • High-Speed I2C Interface (MCP23017):
    - 100 kHz
    - 400 kHz
    - 1.7 MHz
    • High-Speed SPI Interface (MCP23S17):
    - 10 MHz (maximum)

    from uchip

     
  • bed

    bed - 2017-12-02

    Excuse me, if that comes across as a schoolmaster.
    The new homepage has a search function, which spits out the following when searching for 23017:

    HARDWARE ACCESSORIES
    
    mcp23017 i2c to serial a library that supports the i2c to serial functions.
    mcp4xxxdigitalpot digital pot a library that supports the mcpxxxx 
    range of digital potentiometers. mcp7940n clock
    

    The description of all Libraries are available online, one have to find only ;-)

     

    Last edit: bed 2017-12-02
  • stan cartwright

    stan cartwright - 2017-12-05

    I could not find a mcp23017 demo. I can find how the mcp23017 works but not how to use the include without examining it.

     
    • Anobium

      Anobium - 2017-12-06

      We must have missed this device.

      @Stan. Are you up to writing a simple example that we can publish?

       
  • stan cartwright

    stan cartwright - 2017-12-06

    I have mcp23017 chips if they are similar enough. I thought about using the 23017 to drive 2 stepper motors

     
  • renzo zorzi

    renzo zorzi - 2018-03-15

    Sorry if I'm intruding, I have a pair of MCP23S17 expander but I do not know how to use them. On the pinout I see that it uses an SPI interface with commands on CS, SCK, SO, RESET.
    Is there a simple demo where to learn?

     
    • Anobium

      Anobium - 2018-03-15

      I do not see a demo for these chips - but, I am sure one of the guys in this thread will create some demos - I can then pick up and put in the GitHub library.

       
  • renzo zorzi

    renzo zorzi - 2018-03-15

    thank you so much. I will follow the topics.

     
  • stan cartwright

    stan cartwright - 2018-03-15

    You could try changing the mcp23017 includes..there a new one in projects, i2c to spi. See demos/spi. Are they the same operation ie setting address tieing pins?

     
    • Peter

      Peter - 2018-03-19

      The MCP23S17 has the same pinout except the NC/I2C pins are swapped for a CS and the SPI connections.
      Registers are the same, but obviously it sends SPI packets instead of I2C. Figure 3-3 of the datasheet is great for explaining how the I2C interface works but I can't see a corresponding one for SPI.

      I've only tried SPI devices a few times and failed to get them to work on every occasion so stick to I2C.

       
  • stan cartwright

    stan cartwright - 2018-03-19

    I'll have a go at converting existing code from the forum to spi. 5 minute job :)
    The spi stuff I use with gcb works fine if I wire it correct. Any problems have been 3.3V or 5V logic levels.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.