Arduino with 12 encoders and 32 buttons

Hello,

I would like to implement a PC gaming device with 12 encoders (each with its own press switch) and 20 additional buttons (for a total of 32), but I wonder if it is even possible to do with Arduino.

I don't have any hardware yet, but I was thinking on using this kind of encoders:
https://es.aliexpress.com/item/10-unids-codificador-rotatorio-c-digo-interruptor-EC11-de-audio-potenci-metro-digital-con-interruptor-5Pin/32839106848.html?spm=a2g0s.13010208.99999999.271.2c1a3c001WcZ81

As for the Arduino, I have found a library for the PC gaming device implementation for the ATmega32U4, so was leaning to that chip:

As I understand, each encoder needs two pins and not even all of them in the 32U4 are interrupt capable.
About the buttons, I was planning on using the Keypad library to generate a matrix and thus reduce the number of input pins needed.

All of the controls will be hand used and only one at a time due to the type of features that they will manage. :slight_smile:

Obviously a single 32U4 does not have enough input pins. An option would be to use two Arduino Micro where each would use 12 pins for 6 encoders and the other 8 pins for a 4x4 matrix with 16 buttons. Still this does not fix the problem with the interruptions for the encoders and then I found that pin 13 has an associated LED and resistor that will not allow the use of that pin as input.

I would appreciate some help with this as my approach probably is not very good.
Thanks a lot!

Obviously a single 32U4 does not have enough input pins. An option would be to use two Arduino Micro where each would use 12 pins for 6 encoders and the other 8 pins for a 4x4 matrix with 16 buttons. Still this does not fix the problem with the interruptions for the encoders and then I found that pin 13 has an associated LED and resistor that will not allow the use of that pin as input.

You don't need an interrupt to read a hand operated encoder. Standard polling is more than fast enough for this purpose.

You could even read all devices with one Arduino, just attach one or more I/O expanders (p.e. MCP23517). Some even have interrupt outputs that notfifies the MCU if one of the pins change.

then I found that pin 13 has an associated LED and resistor that will not allow the use of that pin as input.

No, what makes you think that?

An option would be to use two Arduino Micro

No their is no need to use two Arduinos. That is normally more trouble than it is worth. Use shift registers or port expanders to get more I/O.

pylon:
You could even read all devices with one Arduino, just attach one or more I/O expanders (p.e. MCP23517). Some even have interrupt outputs that notfifies the MCU if one of the pins change.

Thanks for the reply, Pylon.

I have looked for your recommended chip and yes, it seems what I need. (MCP23S17, right? The 517 I cannot find, only another 017 which is I2C instead of SPI).
Just another doubt here: the Arduino micro 32U4 is clocked at 16MHz while the MCP23S17 clock limit is 10MHz. Is that a problem or it is possible to divide the clock? Maybe it would be easier to use the I2C chip version?

The clock limit for the MCP23S17 is for the SPI SCK signal. You can control that clock rate in software.

Grumpy_Mike:
No, what makes you think that?

I found the first reference to the pin 13 digital input LED/resistor problem here, and then further looking it seemed a pretty spread problem. Looking at the Micro schematics it seems to have that resistor and LED attached to that pin.

groundFungus:
The clock limit for the MCP23S17 is for the SPI SCK signal. You can control that clock rate in software.

Awesome, thank you! :slight_smile:

escaner:
I found the first reference to the pin 13 digital input LED/resistor problem here, and then further looking it seemed a pretty spread problem. Looking at the Micro schematics it seems to have that resistor and LED attached to that pin.

https://youtu.be/yh1j_XJyUeA?t=196

He says "well I won't give anymore detail" so a helpful sole isn't he?

The Arduino has an op amp buffer to drive the on board LED and so should not affect anything. Even the few cheap models that have a direct connection to the to the resistor and LED will not affect the use as an input for 99% of the ways you use an input. The resistor is 1K to the LED to ground with the connection going straight to the input pin. So that means any output signal you connect to the input would have to have an output impedance of 1K5, or greater, before you had any trouble. Sure if you haven't a clue what you are doing this could give you a problem but not if you actually understand things, unlike the idiot in that video.

pylon:
You don't need an interrupt to read a hand operated encoder. Standard polling is more than fast enough for this purpose.

As long as the code is non-blocking. Stick a delay in there can screw the whole thing up.

Hi,
This may be of help, I have two of them, but haven't tried them yet.
Encoder units with I2C comms.

https://forum.arduino.cc/index.php?topic=555711.0

Tom... :slight_smile:

As long as the code is non-blocking. Stick a delay in there can screw the whole thing up.

Sure, you can ruin any code if you switch off the brain during programming.

A Teensy 3.5 or 3.6 will have enough pins to hook them all up. It also has interrupts on every pin if you are worried about that.

Looking for those MCP23S17 chips, I have found these with extra components on the board, but no special description:

https://www.ebay.com/itm/MCP23S17-Bidirectional-16-Bit-I-O-Expander-SPI-Serial-Interface-Shield-Module/122680286508?hash=item1c90509d2c:g:Pl4AAOSwE9RZw4SX:rk:11:pf:0

What would be the difference with the standard solo chip?
EDIT: I mean, the chip datasheet does not specify all those extra components for the different packaging, that I see.

https://www.ebay.com/itm/28Sdip-MCP23S17-D-Sp-I-O-Erweiterung-Spi-16B-Neu-Ic-yl/232848187371?hash=item3636d55feb:g:oD4AAOSw7P5bP4zD:rk:1:pf:0

@MorganS: thanks, will look into it too.

pylon:
Sure, you can ruin any code if you switch off the brain during programming.

We spend a LOT of time here trying to teach new people what it's about, and they do read posts.

The extra parts on the carrier module are there to make using the chip a bit easier. There are pullup (or down) resistors on the address lines, pullup on reset and power supply bypass. The board shown is a MCP23017 chip so the 2 other resistors are for the I2C pullup (my best guess). Those resistors may not be on the 23S17 board.

If you are using a solderless breadboard, get the bare chip. The double row of headers on the module will not work in a breadboard.

If you use the bare chip, be aware that the address lines must be held HIGH or LOW, they cannot be left to float.

I mean, the chip datasheet does not specify all those extra components for the different packaging, that I see.

That is because data sheets are not written for beginners. Everyone in electronics knows you need a ceramic decoupling capacitor on the power lines and that I2C needs pull up resistors.

It is a bit like a book on learning to swim, it never says don't try and breathe underwater or don't take your electric toaster into the pool with you while it is plugged in.

Application notes would have those details. Use Google.