10 Replies Latest reply: Jul 2, 2012 11:14 AM by Grumpy_Mike RSS

Simple+cheap I/O expansion with MCP23017

morgaine Level 15

I stumbled across this simple little Pi project at SK Pang in the UK, one step up from blinking a single LED --- blinking a large row of them with patterns of your choice, aided by Microchip's MCP23017 I/O expander  --- http://www.skpang.co.uk/blog/archives/454

 

Although very simple, I think it might be worth highlighting as another step on the learning path for budding hardware engineers, particularly given that the MCP23017 costs under one pound from Farnell --- http://uk.farnell.com/microchip/mcp23017-e-sp/16bit-expander-i-o-i2c-i-f-dip28/dp/1332088 .  SK Pang are bundling that chip in a "Starter Kit for Pi" together with their Pi cover, breadboard, LEDs etc, which may be convenient if you need a breadboard or cover anyway --- http://www.skpang.co.uk/catalog/starter-kit-for-raspberry-pi-b-p-1107.html

 

See Nathan Chantrell's site --- http://nathan.chantrell.net/ --- for full details of software and hardware aspects of the project, including variations such as building on top of the well known Slice of Pi expansion board.  Direct article links ---  http://nathan.chantrell.net/20120519/raspberry-pi-and-the-mcp23017-i2c-io-expander/ , http://nathan.chantrell.net/20120524/python-tools-for-the-mcp23017-io-expander/ , http://nathan.chantrell.net/20120602/raspberry-pi-io-expander-board/ .  And finally, Nathan's article about interfacing the Pi's 3.3V I/Os with the 5V MCP23017 device is important educational reading --- http://nathan.chantrell.net/20120610/raspberry-pi-and-i2c-devices-of-different-voltage/ .

 

At the MCP23017's very low price, this project can be expanded a lot further easily, as 3 address pins allow you to directly address up to 8 of these devices on the I2C bus.  There is also a version of the chip for the SPI bus, MCP23S17 --- http://uk.farnell.com/microchip/mcp23s17-e-sp/ic-16bit-i-o-expander-spi-23s17/dp/1292238 , and you could in principle use 8 devices on each I/O bus if you have a truly demonic project.

 

The datasheet for MCP23017/MCP23S17 is available at http://www.farnell.com/datasheets/12170.pdf .

 

The Pi certainly has rather limited hardware I/O capability, but that's no deterrant for those who want more simple I/Os.

 

Morgaine.

  • 1. Re: Simple+cheap I/O expansion with MCP23017
    GreenYamo Level 4

    That is very interesting, thank you.

     

    Could something similar be done with a shift register, or am I completely woofing up the incorrect deciduous ?

     

    Steve

     

    Edit: what an extremely interesting web site :-)

  • 2. Re: Simple+cheap I/O expansion with MCP23017
    Level 15

    Did you bother to read the datasheet ?  The MCP23071 is not a 5v device, it's a 1.8v - 5.5v device. It's right there in the datasheet on page one, you don't even need to go lookup the electrical characteristics. Just run it at 3.3v and be done with it.

    What does become quickly obvious though is that you're unlikely to have much current available from either the 3.3v or 5v pins on the gpio header. The polyfuse thing has been done to death everywhere, but I think it's going to be worth it for anyone trying to use the gpio connector to think about alternatives to the micro-usb power supply and to skip the polyfuses completely.

     

    While that starter kit will likely be interesting to people it's way over priced, even on their own site you can get essentially the same stuff (and more of it) for less. The clue is that the cover + breadboard is 11.40, so 17.40 for some LEDs and a few bits of wire. Hmm, cashing in on the R-Pi hype, surely not...

    So try buying the equivalent parts from farnell, you quickly run into the min qty's for resistors etc. being 50+ but as that works out at something like 50p who cares.. I think I got to something like 150 LEDs, two mcp23017's and double the size of breadboard before I managed to equal the cost.

     

    For the 23s17 you get to use 8 per SPI chip select line. By default there's two chip selects on the Pi, but it should quickly be obvious how to increase that to ridiculous levels by just using some gpios as additional chip selects.

     

    There's even a linux driver for these chips that will let you bring them into the standard linux gpio infrastructure, unfortunately it needs some extra stuff added to the kernel and a re-compile to do it - code is available if anyone wants it.

     

    Do follow through and read all of the comments on Nathan's blog on why you'd want the level shifters, and don't try those level shifter circuits with a MCP23S17 running at 5V.

     

    So yes, the MCP23x17, and 23x08, are interesting devices for experimenting with - I have several   I'd also suggest having a look through the other Microchip stuff, they seem to have been producing various interesting things recently at quite competitive prices - mcp2200 was the first one I stumbled across.

     

    Oh, and for anyone looking at skpang, there are several similar places in the UK - coolcomponents and proto-pic spring to mind, but essentially they're mostly reselling stuff from sparkfun and the likes.

  • 3. Re: Simple+cheap I/O expansion with MCP23017
    Level 15

    Steve, 74hc595 on spi seems to be quite popular as a shift register. But if you want something more than very simple stuff yu really want to use something like these - there's a bit more intelligence in the device so you can offload some of the work.

     

    As an aside, there's some evidence to suggest that at least the mcp2200 is just a pic with some firmware pre-programmed. I'd expect the 23x17's are the same.

  • 4. Re: Simple+cheap I/O expansion with MCP23017
    Roger Wolff Level 6

    Although that would be interesting, I don't think that's the case. If you do everything in software, the response of the chip will be much slower than what you can achieve in hardware.

     

    The reason I can think of that a bunch of pins are in the place you'd expect them to be if the chip were a reprogrammed PIC is that they worked on applications and testing BEFORE they had working silicon. Exactly: By programming a PIC to do what this chip does now.

     

    These chips are cheap because they are almost "empty". I mean: A few 8bit shift registers a state machine and a way to write into the different registers inside the device.

     

    This chip may be tricky in practise: "D002" states that if you don't drop VDD down to VSS (ground) alltogether the chip typically won't reset. The 5V powerline of the raspberry pi will not drop below 1.7V if you have an HDMI monitor connected... This might lead to surprises.

     

    On the other hand I haven't measured the 3.3V, but I doubt that the 3.3V regulator will have more than 1V dropout at less than 1mA usage and 1.7V input. Can't be sure though.

  • 5. Re: Simple+cheap I/O expansion with MCP23017
    Level 15

    http://hackaday.com/2011/01/18/mcp2200-usb-to-serial-chip-hacked-to-do-your-bidding/

    Ok, so that was some time ago now and it's always possible they have moved to custom silicon now.  So would be interesting to hook up a programmer to one today and see.

    Even so, economics of scale are a strong motivator, if they're already making millions of the die for the pic and it's cheap enough then why go to the expense of producing a new mask for a new chip ?

     

    I think there may be a bit more that a fer 8 bit shift registers involved in the usb side too.

     

    Life is full of surprises, I'd try to follow the spec and do what's requested for D002, but as has been observed here and elsewhere a lot of these things operate happily outside of the official spec.  Not that we should be using that as an excuse or encouraging that sort of design

  • 6. Re: Simple+cheap I/O expansion with MCP23017
    Level 15

    Roger,

      The HDMI power backfeed is reportedly coming on pins 15 and 16,

    according to ianwill on Sun Jun 17, 2012 11:45 am

    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=24&t=5830&p=102159

     

    But Gert van Loo said on Wed Jun 06, 2012 9:32 pm

    "The Raspberry-Pi can not source current from the TV.

    If you check the schematics you will find a diode in the HDMI 5V line which prevent this."

    http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=7650&p=95518

  • 7. Re: Simple+cheap I/O expansion with MCP23017
    Level 15

    Some simple tests with a multimeter reveals the following, both with the screen turned off and the cable disconnected from the Pi.

     

    Dell 2001FP - DVI via passive DVI to HDMI adapter, hdmi pins, referenced to connector shield

    19, 0v

    18, 0v

    17, 3.3v - suspect, this should be Gnd, but use it as the ref and get -3.3v on pin 18 which shoule be 5v

    16, 3v

    15, 3v

    14, 0v

    13, 0v

     

    Samsung LH40MRPMBF

    19, 0.1v

    18, 0v

    17, 0.1v

    16, 5v

    15, 5v

    14, 0v

    13, 0.1v

     

    It seems clear then. Displays are providing pullups on the DDC I2C bus. From what little info I could find, a 12K pullup in the display is recommended for DDC/CI designs. So we can expect there to be a path from the display's 5v over the DDC SCL/SDA through R13 & R14 on the Pi to 5v.

     

    Since R13 & R14 are directly onto 5v and not 5V0_HDMI then the diode Gert talks about (D1) is irrelevant.  Design flaw ?  Especially when D15 & D16 go to 5V0_HDMI and so don't contribute.

  • 8. Re: Simple+cheap I/O expansion with MCP23017
    jamodio Level 13

    I had a great experience using the Microchip GPIO extenders, they work really well, you can chose a part with I2C or SPI support, and on SPI mode

    you can even share the SPI bus with multiple GPIO extenders sharing also the CS signal for all of them.

     

    I've a pair of boards, one has a PIC32MX with four 8-bit GPIO extenders (shown in the picture) and the other one is an expansion to this one with

    another four 16 bit GPIO extenders. Highly recommendable part, requires a little bit of programming but the work really well.

     

    DSCN1535.JPG

    -J

  • 9. Re: Simple+cheap I/O expansion with MCP23017
    morgaine Level 15

    There is now an article on the RPF blog about using that SK Pang kit that comes with the MCP23017 expander -- http://www.raspberrypi.org/archives/1488  .  Gordon's project doesn't use the expander for his game though.

  • 10. Re: Simple+cheap I/O expansion with MCP23017
    Grumpy_Mike Level 2

    Just run it at 3.3v and be done with it.

    The point is that it acts as a good bridge between the 3V3 world and the 5V world.

    Sure run it at 3V3 if you want but there is a lot of 5V stuff out there in peripherial world.

    Also the 3V3 regulator is limited to 50mA where as the 5V comes straight off the Pi side of the poy fuse so given a decent power supply you should be able to get a decent current from the 5V. There are even people using the GPIO connector's 5V pin to power the whole Pi and bypass the poly fuse.