3

I recently started using rasperry pi. I am trying to do some home automation and controlling toy car motors. I am able to control the motors and 2 plug points.

I wanted to control more servo motors. I see, I am going to run out of GPIO pins available on raspberry pi and not sure about the load on the raspberry pi if I use all GPIO pins.

What is the better way to extend the GPIO pins?

I see some I2C extension boards, but raspberry pi has only 1 I2C port. Is it possible connect multiple boards?

1

Recent Raspberry Pi's have 21 accessible gpios, 17 on the P1 connector and 4 on the P5 connector.

As you say, you could use the I2C bus to expand the number of gpios. You can have multiple port expanders on the bus, each must have a unique address. Common I2C port expanders provide 16 additional gpios each. This example allows for eight devices to be used on the bus for a total of 128 additional gpios.

  • Hi, Thanks for the quick reply. I have one question power requirements from raspberry pi. If I use 128 GPIOs using the extension boards. Can Raspberry pi supply the power? Is there any way to add external power supply to these boards? – venu May 8 '14 at 21:50
  • Depends on how many are active, what they are driving, whether they are inputs or outputs etc. You'd need to clarify. If you power the Pi via the microUSB you could assume you have a ballpark figure of 300mA to play with from the 5V rail. If, like me, you power the Pi via a Pi 5V pin you can use several amps. – joan May 8 '14 at 21:59
  • Hi Joan, I am not fully sure about how much current i need. I am planning to drive few(around 6-7) motors (dc/servo) and few GPIOs driving base transistor. For dc motors i am using L298n board, i am not sure how much this draw from raspberry pi. – venu May 8 '14 at 22:26
  • 2
    Unless they are tiny motors they really need their own power supply. Servos and ordinary DC motors can draw a lot of power when starting or stalled. You probably need to assume a separate supply. – joan May 8 '14 at 22:40
1

You have quite a few options to expand your GPIO pins.

  1. As Joan mentioned that you can use newer version of Raspberry Pi (Model B+ or Model A+)
  2. You can definitely use I2C to expand your GPIO limit.
  3. In addition to I2C bus you can also use SPI bus (available on GPIO) port

I2C:

I2C is not limited by number of ports. I2C bus is only limited by "Bus Capacitance", max SCL frequency and a few other factors. You can connect multiple "IO Expanders" to single I2C bus. "IO Expanders" are available with different slave addresses so you can mix various types. For example TCA6424A can support 24 IOs per device and two devices can be connected on the same I2C bus to provide 48 IO lines. In addition you can use other IO expanders parts to expand your IO capability further

SPI:

In addition to I2C IO expansion, you can use simple shift registers to expand your IO capabilities. You can connect multiple shift registers (as many as your software can allow) and drive them via the SPI bus. You will only limited by your software and refresh latency. IO Expansion using SPI

Conclusion:

Finally you are only limited to the GPIOs that you can think of and the number that Pi can drive (IO latency). I believe if you exceed that number, you have better options than the Pi itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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