GPIO Input Question

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Sigma_San
 
Posts: 7
Joined: Wed Dec 30, 2020 4:33 pm

GPIO Input Question

Post by Sigma_San »

I'm working on a project that involves a lot of buttons. Would it be possible to map multiple buttons to one M4 Express GPIO pin using CircuitPython?

User avatar
danhalbert
 
Posts: 4687
Joined: Tue Aug 08, 2017 12:37 pm

Re: GPIO Input Question

Post by danhalbert »

There's several ways to do this. You use an external device that can support many pins and then ask it for their values:

I2C GPIO expanders: Look at the first few hits on this: https://www.adafruit.com/?q=expander&sort=BestMatch. We have CircuitPython drivers for these devices, and there are Learn Guides:
https://learn.adafruit.com/adafruit-aw9 ... led-driver
https://learn.adafruit.com/using-mcp230 ... cuitpython

shift registers: https://www.adafruit.com/?q=shift+regis ... =BestMatch. Also have libraries and Learn Guides:
https://learn.adafruit.com/74hc595

User avatar
Sigma_San
 
Posts: 7
Joined: Wed Dec 30, 2020 4:33 pm

Re: GPIO Input Question

Post by Sigma_San »

Is there a method that doesn't involve additional hardware?

User avatar
danhalbert
 
Posts: 4687
Joined: Tue Aug 08, 2017 12:37 pm

Re: GPIO Input Question

Post by danhalbert »

You need a way to distinguish one button being pushed from another. Another trickier way is to add a chain of resistors to the buttons, and measure the voltage, which will vary based on which buttons are pressed. But that's still extra hardware

User avatar
danhalbert
 
Posts: 4687
Joined: Tue Aug 08, 2017 12:37 pm

Re: GPIO Input Question

Post by danhalbert »

Or you can use a grid and devote multiple pins to multiple buttons. See
https://electronics.stackexchange.com/q ... ton-inputs
https://electronics.stackexchange.com/q ... th-arduino

User avatar
Sigma_San
 
Posts: 7
Joined: Wed Dec 30, 2020 4:33 pm

Re: GPIO Input Question

Post by Sigma_San »

So will the method with the resistors still work on GPIO pins?

User avatar
danhalbert
 
Posts: 4687
Joined: Tue Aug 08, 2017 12:37 pm

Re: GPIO Input Question

Post by danhalbert »

With resistors you'd need a pin that can be analog, so you might want to use the button grids with or without diodes.

User avatar
Sigma_San
 
Posts: 7
Joined: Wed Dec 30, 2020 4:33 pm

Re: GPIO Input Question

Post by Sigma_San »

OK. Thanks!

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”