User avatar
owatnext
Posts: 16
Joined: Thu Sep 08, 2016 1:33 pm

How Many Inputs? (GPIO/I₂C)

Wed Oct 05, 2016 2:03 pm

Hello.
I am attempting to get many inputs with (hopefully) just the standard GPIO.

I need 17 buttons and a TFT screen to be hooked up to my Pi 3. Would I have enough room on the header for all of this, or would I need to set up I₂C? I'm trying to avoid I₂C, because it seems to be a bit confusing.

Thank you! :)
um i like it tha best wen ur nice to me

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How Many Inputs? (GPIO/I₂C)

Wed Oct 05, 2016 2:17 pm

The Pis with the 40 pin expansion header have 26 available GPIO.

User avatar
owatnext
Posts: 16
Joined: Thu Sep 08, 2016 1:33 pm

Re: How Many Inputs? (GPIO/I₂C)

Wed Oct 05, 2016 7:27 pm

joan wrote:The Pis with the 40 pin expansion header have 26 available GPIO.
I hope that's a yes, lol.

See, I have no prior experience with GPIO at all.

How many pins are required by a display and how many for each button?
If I designed and ordered a PCB, would that bring down my pin usage at all?
Is there a way to enable use of all 40 pins on the header itself?

Sorry for all of the questions, I just want to know as much as I possibly can. :)
Thank you.
um i like it tha best wen ur nice to me

User avatar
joan
Posts: 14935
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How Many Inputs? (GPIO/I₂C)

Wed Oct 05, 2016 7:39 pm

owatnext wrote: ...
How many pins are required by a display and how many for each button?
If I designed and ordered a PCB, would that bring down my pin usage at all?
Is there a way to enable use of all 40 pins on the header itself?

Sorry for all of the questions, I just want to know as much as I possibly can. :)
Thank you.
The number of GPIO required by a display depends on how the display interfaces to the Pi. A SPI display would probably need 4-6 GPIO.

You need one GPIO per button.

I have no real idea if a custom PCB would help, I suspect not much.

There are 28 GPIO routed to pins on the expansion header. 2 GPIO are reserved for system use. The remaining pins are connected to the 5V, 3V3, and ground rails.

User avatar
mikronauts
Posts: 2783
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How Many Inputs? (GPIO/I₂C)

Wed Oct 05, 2016 7:41 pm

owatnext wrote:See, I have no prior experience with GPIO at all.
We can see that :)
owatnext wrote:How many pins are required by a display and how many for each button?
Totally depends on the display.

If you use an HDMI display, without a touch screen, no GPIO pins are needed.

If you use an SPI display, a minimum of four pins will be used.

If the SPI display has an SPI touch controller, it will use another pin.

If you use an I2C based touch controller, you will need to leave the two I2C GPIO's alone.

You can connect one button per pin the simplest connection, or in a 4x5 matrix that would only need 9 gpio's to handle 20 buttons.
owatnext wrote: If I designed and ordered a PCB, would that bring down my pin usage at all?
No.

Based on the level of electronics knowledge you demonstrated, it is unlikely that you could successfully design a PCB in any reasonable time frame as it requires a lot of prerequisite knowledge.

Note, you could design one after you spend a year or two learning about electronics, the Pi, and gpio, so I am not discouraging you.

As a matter of fact, I hope you will take the above as constructive criticism, and dive in!

Electronics is a great hobby.
owatnext wrote: Is there a way to enable use of all 40 pins on the header itself?
Again, demonstrating you don't understand the Pi and GPIO header.

There are 26 usable GPIO's as joan said, the rest are power, ground and reserved pins.

What you should consider doing is adding an MCP23017 (I2C GPIO expander) which would handle 16 of the keys trivially, or as many as 64 keys if they are wired as an 8x8 key matrix.

I have an article on my site showing how to do a 4x4 keypad that would be trivial to expand to a 4x5 matrix that would allow for 20 push buttons.

http://www.mikronauts.com/raspberry-pi/ ... nd-python/


owatnext wrote: Sorry for all of the questions, I just want to know as much as I possibly can. :)
Thank you.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
owatnext
Posts: 16
Joined: Thu Sep 08, 2016 1:33 pm

Re: How Many Inputs? (GPIO/I₂C)

Wed Oct 05, 2016 9:35 pm

Thanks for all of the answers, guys. I think I have a much better grasp on this whole thing now. My programming and software side of knowledge is so much higher than the hardware side. Whoops lol. (The only PCBs that I have ever made have been for indicator lights. :oops: )

I don't need touch, just a display but I want to avoid using HDMI because I'd like to have an HDMI out option for the project I'm on.
This might be redundant but I just want to clarify, I will need seventeen pins for the seventeen required buttons plus four to six for the display. That means that I would have to use anywhere from 21 to 23 pins for the buttons and display together.
um i like it tha best wen ur nice to me

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: How Many Inputs? (GPIO/I₂C)

Wed Oct 05, 2016 9:44 pm

If you wanted a 7" display the 7" official touchscreen won't use any gpio pins and leaves the HDMI unused.
Doug.
Building Management Systems Engineer.

User avatar
mikronauts
Posts: 2783
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How Many Inputs? (GPIO/I₂C)

Wed Oct 05, 2016 10:38 pm

You are most welcome!

You only need 9 gpio pins for up to 20 buttons using a 4x5 matrix, check the article I linked to.

Instead of using the MCP23017 I2C expander to connect to the button matrix, use Pi GPIO's, avoiding SDA/SCL/CE0/CE1/SCLK/MISO/MOSI (the I2C and SPI ports)

As Doug said, the official Raspberry Pi 7" display does need to use HDMI or GPIO, and as such, may be a very good choice for you.
owatnext wrote:Thanks for all of the answers, guys. I think I have a much better grasp on this whole thing now. My programming and software side of knowledge is so much higher than the hardware side. Whoops lol. (The only PCBs that I have ever made have been for indicator lights. :oops: )

I don't need touch, just a display but I want to avoid using HDMI because I'd like to have an HDMI out option for the project I'm on.
This might be redundant but I just want to clarify, I will need seventeen pins for the seventeen required buttons plus four to six for the display. That means that I would have to use anywhere from 21 to 23 pins for the buttons and display together.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
owatnext
Posts: 16
Joined: Thu Sep 08, 2016 1:33 pm

Re: How Many Inputs? (GPIO/I₂C)

Wed Oct 05, 2016 10:59 pm

mikronauts wrote:You only need 9 gpio pins for up to 20 buttons using a 4x5 matrix, check the article I linked to.
Sorry, I originally missed reading through the link you posted. I've read it now, but could I apply this to a custom button layout? To make it more handheld friendly.
The design of the 5x4 matrix doesn't fit into the project I'm on. But it really is a good article! Thank you.
um i like it tha best wen ur nice to me

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: How Many Inputs? (GPIO/I₂C)

Thu Oct 06, 2016 8:25 am

owatnext wrote:
Sorry, I originally missed reading through the link you posted. I've read it now, but could I apply this to a custom button layout? To make it more handheld friendly.
The design of the 5x4 matrix doesn't fit into the project I'm on. But it really is a good article! Thank you.
The physical layout of the 4x5 matrix is irrelevant, you can create a 4x5 matrix for the buttons you want to use.

one warning: matrix solutions aren't compatible with having two buttons pressed simultaneously.
Last edited by BMS Doug on Thu Oct 06, 2016 6:40 pm, edited 1 time in total.
Doug.
Building Management Systems Engineer.

User avatar
owatnext
Posts: 16
Joined: Thu Sep 08, 2016 1:33 pm

Re: How Many Inputs? (GPIO/I₂C)

Thu Oct 06, 2016 2:45 pm

BMS Doug wrote: one warning: matrix solutions aren't compatible with having two buttons pressed simultaneously.
Ah, that's incompatible with my project. I need between two or three to be pressed at one time.
Thank you for the information; it saved me from a lot of errors. Lol.
um i like it tha best wen ur nice to me

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: How Many Inputs? (GPIO/I₂C)

Thu Oct 06, 2016 6:40 pm

owatnext wrote:
BMS Doug wrote: one warning: matrix solutions aren't compatible with having two buttons pressed simultaneously.
Ah, that's incompatible with my project. I need between two or three to be pressed at one time.
Thank you for the information; it saved me from a lot of errors. Lol.
I wasn't thinking it through correctly, multi-touch is possible by scanning each line seperately.
Doug.
Building Management Systems Engineer.

Return to “Gaming”