# 512 Switches to an Arduino?

Hey all. Just recieved my first Arduino. I have a project that requires ALOT of switches. My goal is to have 256 or 512 switches available. (512 is HIGHLY prefered...then I only have to use one board vs two.) I am looking at using daisy chained shift registers (What is the operational limit there as far as the processor on the Arduino?) and a matrix based off that, however my requirement is also that I need to allow any combo of switches to be "On" simultaneously.

Any ideas or directions? Just figured I would make a quick post because if I don't have to completely reinvent the wheel I would appreciate it!

I forgot to mention that these switches will be a mix of momentary and non-momentary (ie toggles and rotary switches.)

Question 1&2 I assume are the same thing: 1/10th of a second, or some other human imperceptable amount...all these switches will be output to interfacing software on Windows. I have been reading the C# communications stuff, which is my preferred language.

Question 3: Again, some human imperceptable amount of less than half or 1/10th a second.

Ideally I would like to create on the fly grounds, and not be tied to a matrix scheme, as when I am using these, there will be some significant cabling runs, and I would hate to waste inputs when a certain panel only has say 5 switches, and it wastes 8 on that ground. (If this makes sense?)

You can search the board for "multiplex" to get an idea of how to deal with a lot of inputs. Hope you are good at soldering.

The issue with Multiplexing (if multiplex = matrix) is the requirement for more than one switch to be activated at a time. (It could be 300 of the switches on at the same time.)

multiplex does not = matrix. With multiplexing you would sample the input from each switch one at a time, repeating the cycle thru the 512 switches in a loop. Parallel and shift multiplexing chips probably could be used.

How big is the mechanical system that these will be built into? Will the switches be in many small groups, or one huge blob?

Depending on the arrangement, it might be smartest to do something like an RS-485 network of PICs, ATTinys, or somesuch.

It will be between 30 and 50 small groups, however, I do want to keep the electronics well centralized. This whole contraption will end up on a homebrew motion platform, and so I don't want to distribute the electronics because it will make maintainence harder.

Its not a large device, it will all be in a 70 by 60 inch footprint. However, Arduino is my first play with a microcontroller project, so I really dont feel comfortable going into the realm of PICs and such yet.

Its not a large device, it will all be in a 70 by 60 inch footprint.

I would say anything measuring almost 6 foot by 5 foot qualifies as "large", especially if mounted to a motion platform. Homebrewing your own 747 cockpit, are we?

;D

However, Arduino is my first play with a microcontroller project, so I really dont feel comfortable going into the realm of PICs and such yet.

Then set it up as a series of ATMega328s (each interfacing with a group of switches) as slaves on an I2C bus...

Matrix switch schemes can contend with multiple closures if you incorporate diodes at each switch.

See...

http://www.dribin.org/dave/keyboard/one_html/

Five computer keyboards? With that number of inputs, it starts to make sense to distribute some intelligence so that each group of 100 switches or so says "switch#65 on" or something. Very much like a computer keyboard. (I don't know if you can get keyboard controller chips very easily. It might be worthwhile to take apart real keyboards for the controllers, even if you aren't using the switches. Or at least read up on how such keyboards work...)

you can only easily connect one keyboard to a single arduino though.

You could use i2c port expanders but although you can get 127(?) devices on an i2c bus, I doubt you can get i2c port expanders with 127 available addresses. Normally they seem to come with 7 or 8.

Can some of the switches be pressed at the same time then?

I forgot to mention that these switches will be a mix of momentary and non-momentary (ie toggles and rotary switches.)

I presume from this that they can.

Are they all set up the same? ie, are momentary and non-momentary mixed in the same place?

Perhaps you want to take a look at:
http://mayhewlabs.com/arduino-mux-shield
and

to see how they have done it and give you ideas.

Mowcius

I'm looking at this IC Expander: PCA9555N

It will require 32 of them to work, however, I am unsure if I will have enough available I2C addresses.

I did find an interesting device, though I don't know if my soldering skills are up to a 100 pin TQFP job.

It is the Cypress CY8C9560A-24AXI, which is a combo of a 60 device I/O, (or bidirectional, or pwm) i2c I/O expander, and a eeprom module (which can be disabled) piggybacked on.

It seems to be FULLY addressable (see page 4 of the datasheet at the link below.)

I do think that programming it to interface with the Arduino would be waaaaay above my current skill level though.

http://www.cypress.com/?docID=20242

Now why couldn't one just simply daisy chain 64 shift registers together?

Now why couldn't one just simply daisy chain 64 shift registers together?

You can, but do the shift registers multiplex inputs to the arduino input? You can use the shift registers to control multiplexing chips that select the desired input. Just as a reality check, look at the below project (four pages) to get an idea of how your project will probably look. The link is for controlling strings of christmas lights via a parallel port, but the same type principal would apply to multiplexing inputs using multiplexing chips like the 4051.

I don't want to distribute the electronics because it will make maintainence harder.

It can also make maintenance easier: fewer wires to break (and fewer to check in the event of a malfunction), and the possibility of setting up standardized sub-assemblies that can be easier to build, test, and swap in the event of a failure.

That I2C expander might turn out to work well for you, if you stick with "centralization". But not if you distribute the electronics, because I2C is very limited in wire length: it was designed to work within a PC board or a backplane.

why couldn't one just simply daisy chain 64 shift registers together?

One could, but one needs to be careful about it: you need to avoid making the latch and clock lines too long to be reliably driven by the CMOS outputs of the Arduino.

Since those lines are unidirectional, you could add buffers along the way to keep the lengths of the driven lines short.

One possibility is to do standardized modules with 1-3 shift registers (depending on the physical layout of the switches) and a buffer chip. That would make it fairly easy to daisy-chain them reliably, and to keep the amount of wiring down.

This is actually a really good idea about extendable modules. Especially because it would contain cost quite well.

Hmm...what sort of wiring scheme would that take? I can't seem to find anything relevant under "Serial Buffer".

mowcius already mentioned the Centipede Shield / MCP23017, but there's another advantage to the approach if you're using matrix scanning. Of course the Centipede is only good for up to 128 raw individual inputs, but you can easily set the ports up as matrices since they are general purpose I/O.

Four 8x8 matrices for 256 switches per shield. Or set up two 16x16 matrices for 512 switches. Dare I suggest a 32x32 for 1024 switches? Nah...probably run into loading or speed issues there. But just keep in mind the I/O expander chips can be very useful for button matrix setups, not just pulling in one button per pin.

They also have hardware pin change interrupts, so you don't actually need to scan all the time. Microchip's MCP23017 even has specific examples for using it as a keypad input.