# How to increase number of micro-controller inputs?

I have relatively little experience with electronics, but do have a basic understanding. I am attempting to build a measuring device, which will measure 100 points in 0.1 seconds. These will all produce a digital number which will need to be stored on a micro controller.

If I were to use the raspberry pi model b, it only has 17 input GPIO pins. My question is that is there a relatively simple way of taking more inputs than the micro controller has pins?

Currently the way I am looking at doing it is having an output which sends a number to choose which input to read, that sensor would then send its current value back to the micro controller. The disadvantage of this method is obviously that it takes up time. I want 100 inputs in the order of 10^-3 seconds and I assume that this has to be a fairly common feature of circuit design given most systems have a large numbers of sensors.

So, is there an easy way of doing it? Is the way I have detailed above at all sensible? Is this a common problem, if so how is it normally overcome?

• What are these "points" that you need to measure? I suspect the answer to your question is a "Multiplexer" but you must fill in more detail. Why do you need to measure the points 'near instantaneously'? Jan 25, 2016 at 22:02
• Sorry for my vagueness! What I am creating is small moving rover, which measures the height of the nearest ceiling above it. There are 100 lasers pointed up, which reflect back and using a time of flight measurement system measures that distance. The reason this information needs to come in quickly is that the rover needs to be on the move as it measures and needs to measure to 1mm accuracy. It is therefore nearly constantly taking readings. Jan 25, 2016 at 22:17
• What does 'simultaneously' and 'as near to instantaneously' mean? To a human it might be $10^-2$ seconds, to a physicist $10^-21$seconds. Jan 25, 2016 at 22:21
• Please update your question with extra information; please don't leave it in comments. That helps the community 'be on the same page', and save having to read all of the comments. How long does it need to capture all 100 readings? Taking a 100 measurements on a vehicle travelling at $1m^s$ with 1mm accuracy sounds like a fraction of a millisecond/reading is good enough. Jan 25, 2016 at 22:25
• @JackSchofield thanks. Are these are laser range finders? What sort of interface do they have? Jan 25, 2016 at 22:27

If you want a large number of sensors to record simultaneuosly, then one way is to have sensors that can be strobed, record their own value internally, then be polled by the central controller at leisure later. But that takes some degree of an intelligent sensor.

At the other end of the spectrum is a central controller with enough I/O to record them all at once. As you say, you will need very many pins.

An intermediate position is some sort of latchable storage, parallel to serial registers for instance, that can latch your sensors, and then be interrogated later by the controller. Easiest to regard this as input width expansion for your controller.

How simultaneous is needed? You could use a controller with DMA to execute a very fast poll.

• I need something of the order of 100 readings in 0.1 of a second, but something that I should have added is that it needs to do this continuously for around five minutes. The problem that I imagine would rise with strobing and then not storing the information gained until later is that there would then have to be a pause between these grabs of readings to then interrogate and store the data? Or am I overestimating the times involved? Jan 25, 2016 at 22:13
• 'At leisure' means microseconds. 100 readings in 0.1 seconds is not a problem, any Arduino or PIC would not break a sweat doing this. Buy one sensor, have your PI read it, and see how fast it goes. Then recheck your design. Jan 25, 2016 at 22:16
• @JackSchofield Please update your question with extra information; please don't leave it in comments. That helps the community 'be on the same page', and save everyone having to read all of the comments. Jan 25, 2016 at 22:28
• @jack 100 milliseconds? 1 millisecond a reading? That's easy peasy. Any common microcontroller could do that in microseconds. Fraction of a millisecond per reading. Jan 25, 2016 at 23:00
• Also, I/O expanders are a thing... Jan 26, 2016 at 0:27

The ST Micro VL6180X you have identified as the sensor doesn't work the way you might imagine.

First, as Steve G wrote, it only works upto 100mm, which may be a 'show-stopper'. However, even if the maximum sensing distance of 100mm is not a problem, for example the robot is navigating through a tube, with the walls less than 100mm away, there is another issue.

The datasheet, "VL6180X Proximity and ambient light sensing (ALS) module" says in 1.1 "Technical specification" on Note 5 "Assumes 10 Hz sampling rate,"

So it only produces an answer 10 times/second, i.e. a measurement every 0.1 seconds. That may sound fine, but there is more to it.

While the product page says "the VL6180X precisely measures the time the light takes to travel to the nearest object and reflect back to the sensor (Time-of-Flight)." It is not measuring one photon, or one brief pulse of light.

Light travels at $3\times10^8$ metres/second. So to to determine distance to 1mm, it'd have to work at time resolution around $1mm/3\times10^{11}mm/second$ , i.e. $3.3\times10^{-12}seconds$. It doesn't work that way.

It generates many pulses, at varying times, with varying durations, and does some clever processing on many samples to derive a distance measurement. AFAIK, it generates pulses for much of that 0.1 seconds. Hence the stream of pulses from each active sensor may interfere with other active sensors in its neighbourhood.

Worst case, only one sensor can be active at any time, and it needs the entire 0.1 second to measure distance. It's unlikely to be that bad, but it may be that the number of simultaneously active sensors is a small fraction of the 100 hundred total.

Summary: the practical sample rate for all 100 sensors might be several seconds.

There are many ways in which this particular problem could be handled. Since you are asking for "near-instantaneous" sampling of all 100 inputs, how about something like this:

• 1 main microcontroller <--> serial bus <--> Raspberry Pi
• Qty 10 of 26-pin sub-microcontrollers --> 10-bit data bus --> main micro

Most microcontrollers have "interrupt" pins. So if your 10 sub-micros are all programmed to "read" 10 inputs the moment an interrupt pin toggles, then wiring that interrupt line to each of the ten and toggling it will sample 100 inputs simultaneously. Clock them all from one clock source for best accuracy.

Then it's just a matter of having each of the ten send their data on the 10-bit bus to the main micro. Can be done with timing, individual select pins, etc. Once the main micro has all of the data, send this to the Rpi over serial.

If its inputs and timing you need go with an FPGA, some devices have 500 inputs. The nice thing about an FPGA is you can build timers for each input, keep in mind there would be a big learning curve but a fun one if your up for it. A faster way would be to use a beagle bone or other dev board. Would you rather spend time buying break out boards and wiring? Or learning a new toolchain? It's up to you. https://www.arrow.com/en/research-and-events/articles/top-ten-dev-boards-of-2016