I successfully completed my hardware "hello world" using this guide:


Now I'd like to move on to bigger and brighter things, more individually controlled LEDs that is! Obviously, the next step is to move the voltage source off of the Raspberry Pi and to add more LEDs, but eventually I am going to run out of GPIO pins, so I guess what I need now is to control a circuit which will somehow know, based on GPIO "coded signals", what LEDs to turn on and off. What sort of circuit examples should I be looking for? And more importantly vis-a-vis the Raspberry Pi, could it or rpi.gpio cause any problems, perhaps regarding signal timing?

  • Muliplexing will radically reduce the number of GPIO that need to be used, in conjunction with Persitance of Vision by using PWM to further reduce GPIO or create large arrays with minimal GPIO. This has already been answered here.
    – Piotr Kula
    May 8, 2015 at 22:42

2 Answers 2


What you are looking for in that case is a LED matrix. You could control this matrix from the GPIO pins, but that still limits the amount of LEDs you can connect (the size of the matrix) and it might also start to draw too much current if you're not careful.

A better option is to connect a LED matrix to the I2C bus, using one or multiple I2C I/O extenders. That way you can create a matrix of a huge size (64 LEDs for example can be done with ONE 16 bit I/O extender). Another reason to use these I/O extenders is that they are a little more robust, can provide a little more current, and keeping your main CPU out of harms way.

On this site these I/O extenders are discussed multiple times, so you should be able to find info about these quite easy. This Link provides some info about these extenders and a matrix (although used for input, but basically it is the same idea but you don't use the matrix to scan but to steer the LEDs)

Only extra requirement for making a smooth working matrix is that you need to make the matrix not bigger then the RPi is able to update each individual LED at least 20 times every second, otherwise you'll start to see flickering, but this is also explained in the first link (paragraph "Multiplexing and Persistence of Vision").

  • This is very interesting. Thanks for the read! I might try this in small scale using the GPIO pins before I am ready to move onto extenders. I have done some tests with the GPIO pins and so far I have been able to get satisfactory Multiplexing. I am not to worried about the current since I will only be using the Pi to switch an external current. Will this scale well? Probably not, but I'm here mostly for the lesson anyways!
    – SkyNT
    Jan 31, 2013 at 5:33

I've used the MCP23017 I²C port expander to do this type of thing. Follow this link to find some sample code for the raspberry pi. You can drive 16 LEDS per chip and 8 chips without needing to do any multiplexing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.