sGerli
Posts: 14
Joined: Wed Jan 27, 2016 12:11 am

Connecting More GPIO

Sun Apr 03, 2016 10:51 pm

How can I connect 46 push buttons and a joystick to gpio with adafruit tft lcd connected if there are only 40 GPIO pins?

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Connecting More GPIO

Sun Apr 03, 2016 11:11 pm

port expanders

rzusman
Posts: 347
Joined: Fri Jan 01, 2016 10:27 pm

Re: Connecting More GPIO

Mon Apr 04, 2016 12:20 am

46 pushbuttons only takes 14 I/O to scan.
That leaves 26 for your joystick and everything else.
Last edited by rzusman on Mon Apr 04, 2016 12:38 am, edited 1 time in total.

klricks
Posts: 7430
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Connecting More GPIO

Mon Apr 04, 2016 12:35 am

sGerli wrote:How can I connect 46 push buttons and a joystick to gpio with adafruit tft lcd connected if there are only 40 GPIO pins?
Note there are 40 pins on the header but not all of them are GPIO. There are some ground pins and power pins etc leaving you with 26 actual GPIO pin of which the screen will use several. A simple switch actuated joystick will use at least 4 (for 8 directions).
You will need to think through details before deciding on how to proceed.
Will there be only 1 button press at a time or multiple? What type of joystick? etc etc.....
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

sGerli
Posts: 14
Joined: Wed Jan 27, 2016 12:11 am

Re: Connecting More GPIO

Mon Apr 04, 2016 1:11 am

I am going to make a scientific calculator with 46 push buttons, 1 5 direction joystick and 1 Adafruit pi screen which uses GPIO pins: SCK, MOSI, MISO, CE0, CE1 and #25 and #24.
I am thinking to use multiplexers but I don't know if that's the best option. And buttons don't need to be used at the same time.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Connecting More GPIO

Mon Apr 04, 2016 1:26 am

sGerli wrote:I am going to make a scientific calculator with 46 push buttons, 1 5 direction joystick and 1 Adafruit pi screen which uses GPIO pins: SCK, MOSI, MISO, CE0, CE1 and #25 and #24.
I am thinking to use multiplexers but I don't know if that's the best option. And buttons don't need to be used at the same time.
As stated earlier, 46 keys can be done with 7 x 7 matrix using 14 gpio, 64 with 16.

sGerli
Posts: 14
Joined: Wed Jan 27, 2016 12:11 am

Re: Connecting More GPIO

Mon Apr 04, 2016 1:32 am

asandford wrote:
sGerli wrote:I am going to make a scientific calculator with 46 push buttons, 1 5 direction joystick and 1 Adafruit pi screen which uses GPIO pins: SCK, MOSI, MISO, CE0, CE1 and #25 and #24.
I am thinking to use multiplexers but I don't know if that's the best option. And buttons don't need to be used at the same time.
As stated earlier, 46 keys can be done with 7 x 7 matrix using 14 gpio, 64 with 16.
Ok, any guide or explanation about what is and how to do a 7x7 matrix?


sGerli
Posts: 14
Joined: Wed Jan 27, 2016 12:11 am

Re: Connecting More GPIO

Wed Apr 06, 2016 10:59 pm

Thanks to all for your help, doing a 7X7 matrix works perfectly.

sGerli
Posts: 14
Joined: Wed Jan 27, 2016 12:11 am

Re: Connecting More GPIO

Sat May 21, 2016 11:05 pm

sGerli wrote:
Thanks to all for your help, doing a 7X7 matrix works perfectly.
But for some reason they aren't working all, I can only get to work

Code: Select all

1, 2, 8, 9, 15, 16, 17, 22, 23, 24
(ID Numbers)
Code: https://github.com/sGerli/piCalc

I/O Table
Image

Im only getting those numbers and sometimes 3 or 4 more. Also sometimes my pi freezes or turns off when I click a button for a long time or many buttons in a short period of time. Any idea?

Schematic
http://content.igerli.com//2016/05/butt ... _schem.pdf

rzusman
Posts: 347
Joined: Fri Jan 01, 2016 10:27 pm

Re: Connecting More GPIO

Sat May 21, 2016 11:51 pm

Sorry, but that schematic is too confusing for me to follow.

Make sure all your pullups / pulldowns are set correctly.

Test the matrix by setting one row at a time, and then pressing all the buttons to see what columns react (or vice-versa). That will help isolate any construction or wiring issues.

User avatar
Burngate
Posts: 6401
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Connecting More GPIO

Sun May 22, 2016 2:19 pm

I've taken the liberty of redrawing this to make it clearer to myself.
Note, the standard way of numbering the pins of the header is in the order they appear on a ribbon cable, so top-left = 1, top-right = 2 and so on. (There's nowt wrong with your order, or any other, but standards are useful!)
screen0001,b60.png
screen0001,b60.png (20.19 KiB) Viewed 2273 times
As the previous poster says, check the settings of the pull-ups.
At start-up, GPIOs 2 & 3 (pins 1 & 3) have strong pull-ups, GPIOs 4 - 8 (pins 7, 29, 31, 26, 24) have weak pull-ups, but most of the rest have weak pull-downs

sGerli
Posts: 14
Joined: Wed Jan 27, 2016 12:11 am

Re: Connecting More GPIO

Thu Jun 16, 2016 7:35 pm

Burngate wrote:I've taken the liberty of redrawing this to make it clearer to myself.
Note, the standard way of numbering the pins of the header is in the order they appear on a ribbon cable, so top-left = 1, top-right = 2 and so on. (There's nowt wrong with your order, or any other, but standards are useful!)
screen0001,b60.png
As the previous poster says, check the settings of the pull-ups.
At start-up, GPIOs 2 & 3 (pins 1 & 3) have strong pull-ups, GPIOs 4 - 8 (pins 7, 29, 31, 26, 24) have weak pull-ups, but most of the rest have weak pull-downs
I am new at electronics and I don't know what that means for my matrix. Can you recommend me a way of connecting it, for it to work?

medicdude
Posts: 11
Joined: Sun Jun 19, 2016 4:35 am

Re: Connecting More GPIO

Sun Jun 19, 2016 5:46 am

Pull-ups and pull-downs are used to introduce an inherent high or low state to a bus, otherwise it would be 'floating' and have unknown high/low state. "pull-ups" connect the bus to Vcc and result in a 'normally high' state, signals on the bus should tie to ground to force a low condition. "pull-downs" do the opposite connect the bus to ground so it's normally low, and signals on the bus would tie it to +Vcc to a high condition.

Pullups used to be actual wired-up resistors tied to +Vcc or ground, but on most ICs they are included internally and can be turned on/off through configuring the IC.

If you read the state on a pin that is pullup configured, you will see a high state unless something else is pulling it low. Vice versa for pulldown configured pins.

You could also use an actual resistor network to encode each button as a unique analog voltage and use a single analog pin to read the whole network at once, but this requires an obnoxious amount of configuration and is unreliable for multiple button presses at once without a high quality ADC and resistors.

Return to “Interfacing (DSI, CSI, I2C, etc.)”