Which to use: Shift register, Multiplexer, Bus transceiver, Port expander, ...

Hi community,

Please help me decide on what component to use for my project.

Imagine a button, that when pressed twice, sends two signals to the MCU to measure the time between the two presses.
Now imagine a 100 buttons that can be pressed simultaneously and imagine further that the time measured can vary from 1 millisec up to a couple of seconds (obviously the buttons are not physical, I use CNY70 with a comparator).

What's the most efficient way to read all the inputs such that all time measurements are accurate (no delay) ?

What do you mean by "efficient"? Cost, simplicity, MCU processor usage?

You could chain 13 x 74hc165 shift registers to the Arduino's SPI pins. Shifting in 13 bytes would be very quick and could be done at 1ms intervals. Compare the bytes with the previous readings. Where a byte is different, figure out which bits have changed and so on.

You could use 7 x pcf8575 I/o expanders. These have interrupt output pins which are triggered if any inputs change. The 7th chip would have some free pins, so connect the interrupt pins of the other 6 chips to inputs on the 7th and have the interrupt pin from the 7th connect to the Arduino. When the Arduino detects an interrupt, it can read the 7th chip and figure out which of the 4 inputs or which if the 6 other chips caused the interrupt, then go read that chip to see which input on that chip changed.

Exactly what is is that you are wanting to do?

I'd like to build a midi controller for a piano. The optical sensors are placed for each key and should measure the velocity of the hammer. Each sensor is combined with a comparator and will give me 2 signals corresponding to two points in space (about 1mm apart and close to the sensor), with which I can calculate the velocity. That velocity is used to determine if a note should be played loud or quietly.

I want to read all keys in such a manner that no velocity calculations are compromised (delays) because of slow processing.

maybe SPI is still to slow ? Can it be done with shift registers. I could try to make an array with them to have interrupts available? not sure if needed though...

OK, now we can begin to figure out how to do this. :grinning:

I'm off to work, but in general and brief, this needs to be arranged as a matrix, 8 by 16. It actually should be possible to do this with the opto-sensors. You would arrange this so that the "top" and "bottom" sensors are in adjacent pairs to facilitate the processing. Interrupts are of no real value as you simply need to be continuously polling.

I'll get back to it sometime ...

Thank you, Paul.

I wanted to use only one opto-sensor per key, not two.

The sensor will be placed above the hammer. Whenever the hammer approaches the sensor, it will read 2 digital(?) values because of the comparator that is connected to 2 resistors. Each resistor defines a different point in space with a threshold voltage.