A Simple Method for Expanding Arduino IO Capacity

Although there are other ways to do this, [Rod] has decided to write up his method of using two Arduinos and the I2C protocol to expand an Arduino’s IO capacity. As seen in the picture above, you’ll sacrifice 2 analog pins, but if you happen to need IO and have an extra Arduino lying around, this could really help. [Rod] also notes that this method could be used with many Arduino’s in parallel if the situation called for it. The code for this simple hack is included as well, so be sure to check out his site if you want to try this idea.

Some other solutions for extra IO would be to buy an Arduino Mega with 54 digital IO pins or the Muxshield which gives you 48 IO (and is stackable for other shields). An advantage of using the two Arduinos, is that if they are needed to be split in the future for different projects, this could be done. It’s good to have options for your IO needs as every hack is different.

Check out the video after the break to see everything being hooked up.


Comments

  1. Stevie says:

    Shift registers

  2. Ben Ryves says:

    According to Farnell an Arduino Uno is £19.50. For that I could buy 33 MCP23S08s (58p each), each providing an extra 8 digital GPIO lines. I still don’t see the attraction of throwing an Arduino at every problem!

    • Daid says:

      That’s kinda mean. The Arduino already has a socket and a board. Just the ATMega328 is 5,65 euro.
      For 21 IO pins, that’s 0.26 euro per IO.

      The MCP23S08 is 1,32 euro, so 0.17 euro per IO.

      But, the ATMega8A-PU is 2,98 euro, also has 21 IO pins left after using 2 for SPI communication. And brings the cost to 0.14 euro per IO.

      (I’ve used farnell, single item, DIP package prices. I can do better with other shops, as I buy the ATMega8 at 2,65 inc VAT)

      I agree, don’t throw an Arduino at every problem. Don’t throw an Arduino at ANY problem really. But throwing micro-controllers at every problem seems like a valid option.

    • ScottInNH says:

      Your straw man argument is not good. No one advocated using a second, expensive Arduino at 20 pounds. But you knew that before you posted, since the second image on the HAD article -clearly- shows the author using a bare Atmel chip on a breadboard, which is a few pounds, tops.

      Until one can realistically program the MCP23S08s from the Arduino IDE, it’s also pointless to suggest it as a substitute.

      Please stop with the senseless Arduino bashing, it is -not- going to grow the user base of /your/ preferred micro. In fact you may have the opposite intended effect.

      • Ben Ryves says:

        You wouldn’t program the MCP23S08 with an IDE as it’s a GPIO expander, not a microcontroller. It gives you eight additional GPIO pins easily controlled over SPI.
        I’m a big fan of AVR’s microcontrollers. I’m also a big fan of trying to find the appropriate tool for the job and maybe learning something in the process.

      • ScottInNH says:

        Fair enough Ben. For some reason, I mis-read your suggestion as “MSP430″ (the tiny TI board).

        That chip looks neat… like an SPI 595. Thanks, I just requested a free sample of the MCP23S08, and will check it out.

    • ftorama says:

      I love those “better-choice-men” as far as it’s Microchip components

      You could look at 74hc164, 74hc165, 74HC595, MIC5891 for power needs, etc….

      No need to try to place some Microchip stuff everywhere it’s written Arduino or AVR

      • Ben Ryves says:

        I am a big fan of AVR microcontrollers, so this isn’t rampant Microchip fanboyism – I just named that particular part as I had good experience with it in the past. I don’t care who makes the part as long as it works well – and for what it’s worth, I used those MCP23S08s to add 32 GPIO lines to an ATMega644P.

  3. steaky says:

    Nice to see that I’m not the only one shouting shift register, or SPI io expander.

    I guess this is a case of “when all you’ve got is a hammer, everything looks like a nail”

    • Steve Hoefer says:

      Arduino is mostly a beginner platform so people do weird, funny, illogical things with them.

      This should be encouraged.

      This is how people learn. Chaining two microcontrollers via I2C is a valuable skill, and this guy bothered to do it and then share how he did it. That’s useful in general. (If maybe dubious in the specific.)

    • ScottInNH says:

      If all the author was doing was driving more LEDs, I would be inclined to agree with you.

      The headline is misleading though – this method is not limited to simply “expanding IO”.

      There are plenty of cases where you want the slave micro doing something more complex than shifting serial to parallel and so the 595 would not do.

      I’d certainly do this to expand a platform, than set aside my Arduino and buy a Mega version. This is also cheaper.

      Micros are getting cheap enough that TTL chips are going to the wayside. Sure, you could do a “Larson scanner” using logic chips, but the ATTiny version is both fewer parts and lower cost vs the original.

  4. Denbo says:

    This was in the O’Reilly “Arduino Cookbook” in Chapter 13 along with code. There are many cheaper ways (i2c port expander) to accomplish this without the hassle and expense of another Arduino and the hassle of hooking up an extra power supply.

    Also you don’t completely lose two pins because i2c runs in a bus configuration. You could hook up additional i2c devices to those two pins.

  5. Ptolom says:

    Not enough IO pins on an arduino? Use /more/ arduino!
    It could be useful if you’re in a hurry and have arduinos to spare but no shift registers.

  6. Matthieu says:

    Regarding the previous comments: “if you happen to need IO and have an extra Arduino lying around”.

    Thank you HaD for presenting an alternative solution.

  7. Rod says:

    I couldn’t agree more with the “Everything looks like a nail” comment. But that’s exactly what Arduino is all about for an amateur like myself in the end: a sometimes overkill but simple way of getting simple things done. This really saved me a couple of times where I needed my ports: Bottom line, this is for when you don’t have anything better on your workbench, which happens quite frequently to beginners.

  8. justDIY says:

    One day, I needed more USB ports on my computer so I could plug in another printer. I was in a pinch, so I went to Best Buy and bought another computer, and connected it to my first one with the ethernet cable. Now I have 10 more USB ports, and it only cost the price of a new computer!

    • jjshortcut says:

      Yes!

    • Very nicely phrased.

    • ScottInNH says:

      Oh bam, in your haste to mock the Arduino with a “USB” analogy, you just demonstrated you have NO idea how USB works.

      Chaining micros by the way is EXACTLY how many low-cost circuits gain capabilities. The Arduino Uno actually has two micro chips: the ATMega offloads USB services to a tiny ATMega8U2.

      … but you can not “chain computers” to gain additional virtual USB ports. Certainly not off of Ethernet.

      At least you did not fill out your website name, and embarrass yourself. If you are going to troll, I suggest spending some time first doing your homework. :-)

      • Except I2C is precisely a “networking” protocol, so his analogy is perfect. A better solution than adding a whole other “computer” “networked” to the first “computer” is to use a “USB” hub (here a port expander, a shift register, a [de]mux, you name it.

      • Dissy says:

        @ … but you can not “chain computers” to gain additional virtual USB ports. Certainly not off of Ethernet.

        Erm, actually yes you can.
        http://usbip.sourceforge.net/
        Or google “USB over IP”

        The point was there is a widely used and supported method for this already, be it a USB hub or a shift register.

        While there may be cases where the simpler methods would not do, none were mentioned.

        Once you chain 4 or 8 shift registers together on 3 or 4 IO pins to get 32-64 bits of IO (With built in commands to handle it for you, just the same)

        Now if it was a massive PWM output array, this method would be very useful.

  9. AbsoluteZero says:

    I don’t know if you’re really “sacrificing 2 analog pins”. Even if you only have two atmega328p’s on the i2c bus, you have a net gain of 2 analog pins (4 on each mcu), and for each mcu after that, you gain another 4 without losing any additional pins.

    Cmon guys, the second board is obviously homebuilt. All this “arduino is his only tool” stuff, give it a rest. Granted there are other ways to get more GPIO capabilities, this is a great excuse to learn how to string together devices on an i2c bus. Given that he can add more devices at $2-3 per mcu, its not such an outrageous idea.

  10. Rod says:

    @AbsoluteZero Good point on the sacrifice of pins. home-made instances is what I use for projects. One of the “extras” you can obtain from this setup is the ability to isolate or divide tasks between the two Atmels. Mine are even capable of “watchdog” each other over the bus and reset each other if any of them freezes. I still think trollers here have good and valid points especially if you use full Arduino boards, but with some creativity you may find one or two more benefits from this setup.

  11. nanomonkey says:

    IO, IO, its off to work I go.

  12. egasimus says:

    This is hilarious.

  13. macegr says:

    This is a better solution. 64 true I/O, handy breakout accessories, and delicious black/gold manufacturing. Plus it helps a fellow hacker ;) http://macetech.com/store/index.php?main_page=product_info&cPath=4&products_id=23

    • Rod says:

      Indeed! Nice one. Looks like the MuxShield, even better. Price is not bad either!

    • Troll_Dragon says:

      Nice Board!

      The next time I need a few extra GPIO and I got $40 and 2 Weeks to wait, I’ll order one. :)

      • macegr says:

        You can actually get the chip this is based on, the MCP23017, quite cheaply and in DIP. Digikey has it for $1.44USD qty 1. It’s a great chip, lots of features, works on fast I2C frequencies. All you need is a breadboard or piece of perfboard, a decoupling cap, source of 5V, and a couple of pullup resistors. If you’re using an Arduino, the Centipede Library I made for the Centipede Shield still works great with bare MCP23017 chips.

        I don’t mind if you don’t buy my product, as long as you’re aware of the awesomeness of the MCP23017. :) More I/O for everyone!

      • Troll_Dragon says:

        Didn’t mean to come across nasty… You’ve got a sweet board there and it’s well worth the money.
        I was just thinking of an “at the moment need” and ordering a board wasn’t a solution.

        Thanks for the info on the chip and library, that will come in handy to a lot people for sure. I’m gonna get a few MCP23017’s to have on hand. :)

  14. Tech B. says:

    Yo dawg, I heard u liked arduinos….

  15. anyone says:

    when your solution to a problem is to simply “add ardunios”, it’s probably time you look in the mirror and reevaluate your life in the world of fixing things.

  16. AnarKIT says:

    Wow… such vitriol over the use of a dev board!

    Sure there may be more efficient and cost effective ways to do what’s being done in the video, but if you’re working on something that needs to get done and you happen to have two Arduinos and no port expanders, this makes a lot of sense. Also, once you find out that you can control one Arduino with another in this way, someone might take that and run with it to make something very neat.

    I imagine anyone who says that this person is a fool for doing this is probably just trying to show everyone else how smart and superior they are, which is not really the point of DIY.

  17. demacus says:

    Hmm, this makes me thinking about a MAC – I’m not sure about the cause.

    I think this is not worth a post on HAD since its an absolutely waste of money caused by a lack of knowledge imo.

    Who on earth has laying around an additional Arduino but no sregs/line decoders or else?! Even a clever zener diode/transistor array would do… guess there are a million ways which are more “hacky” than this.

    I’m starting dislike this Arduino hype, first ppl came up with clever ideas, now its kinda annoying to rewrite those arduino sketches into “real code”.

    • Eirinn says:

      I do and it actually does have a use thank you. I’ve done a few projects that required two uC’s and linking them together like this is a cool solution. Just use the bare bones chip and you’re flying.

      Unless of course you’re an electrical engineer, then you get to pay a little less to get the same solution (add a few hours extra work though).

    • Bill says:

      Lots of people who do Arduino development have a spare ATmega328 or 168 chip around. One of the common things that you play with after making LEDs blink, motors spin, and sensors sense is use the Arduino board to program another 328 so you can deploy it in your application without tying up the whole Arduino.

      The “Barebones Arduino” he’s using is just a 168 or 328 chip and a timer crystal stuck on a piece of PC board – it doesn’t have the power supplies or fancy FTDI USB input stuff on it.

      If you’re building your project on breadboard, you don’t even need that much, just stick the Arduino and crystal on the board, and the pins are right there waiting to have LEDs plugged in to them. And yes, if you were building these things in production it would be cheaper to use a $1 I2C port expander chip than a $3-4 328 chip, but as a hobbyist it’s convenient to use whatever’s around.

  18. marcus says:

    can any one answer why 2 resistors are needed on the slave?

    I am a newbie …^^

  19. Eirinn says:

    While it DOES expand the I/O’s it also expands the computing ability which people seem to be completely oblivious of.

    • ScottInNH says:

      Yep. Pair the slave with a cheap 6 pin LCD, and bam you have a SPI or i2c slave that can use 2 wires for I/o instead of 6 pins wasted on the master.

      The complainers will complain, but when do they ever actually make anything, lol.

      Plus the slave can loop or animate while using zero resources on the master.

      That’s exactly why the ThingM rgb led is so cool… Has a tiny on board atmel.

  20. wardy says:

    Hackaday – Sponsored by Arduino.

    On a serious note though, this technique is a waste of time and money if you ONLY plan to use the second arduino as more IO pins. The only way this would be sensible is if you were using the other resources as well such as additional CPU resources, more interrupts, different clock speeds or whatever.

    Chaining together two fully utilised arduinos is probably very useful for certain applications. Although most people would just save £50 and go buy a more capable platform to start with (Propeller perhaps, or maybe a huge pin-count PIC chip).

  21. The Hungarian says:

    I agree with the TROLL comment, there are people who argue for the sake of it, yes its an expensive and wasteful way of adding IO’s, but who cares, its not about adding IO’s, there is a bigger picture here, its about learning, and there are countless things that can be achieved through connecting 2 Arduino’s, but hey ! some of these TROLLS have tunnel vision

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 92,158 other followers