4
\$\begingroup\$

This is a fundamental question about the Arduino system. I've been trying to find answers all day, but keep getting answers either unrelated to the Arduino or completely off topic.

I'm building a robot that consumes most of the pins on the Arduino for motor and IR sensor modules. The robot works great (Robot Starter Kit by OSEPP). Now I want to get on with adding several more sensors and an LED output module, but I've run out of pins. I've seen prototyping boards and shields that seem to extend the pin count, and I've read several articles on the address bus helping to uniquely ID all the components, but I'm lost at step one...

How does one address various input / output connectors or pins on prototyping boards?

Sorry for the noob question, but as with all tech, the simplest first steps are always the least documented. Any links to great tutorials would be greatly appreciated.

\$\endgroup\$
3
  • \$\begingroup\$ Depending on how you set up the motor, you may be able to reduce pin count for them to two. stop/start, reverse/forward using logic gates. This can also help prevent your motor being in unwanted states. \$\endgroup\$
    – R.Joshi
    Commented Apr 23, 2018 at 7:51
  • 1
    \$\begingroup\$ Try searching for I2C IO expanders. You could also get an Arduino with more IO. \$\endgroup\$
    – Daniel
    Commented Apr 23, 2018 at 7:52
  • \$\begingroup\$ @Daniel -good point. Modules based on the PCF8254 chip are readily available, cheap, and you can hang up to 8 of them off a single I2C bus, which is handy. \$\endgroup\$
    – Jules
    Commented Apr 23, 2018 at 13:52

3 Answers 3

5
\$\begingroup\$

There is no true way to expand pins, but there are techniques you can use to exchange processing power and data for more effective pins.

Using just 3 pins and 1 chip select (slave select) pin per device you can talk to many devices over SPI (serial peripheral interface).SPI with 3 slaves]1

If the devices you want to talk to do not support SPI you can use other ICs such as a shift register that talks to over SPI and give you more effective digital IO. Daisy chained shift registers

The above picture shows an example of two 8-bit shift registers daisy chained together. Using 3 pins from the microcontroller you are able to control 16 LEDs.

You can multiply this effect even higher using a technique called multiplexing. Instead of using shift register outputs directly, you can attach components into a grid and "select" a column and row.

8x8 multiplex grid

In this case an arduino using 3 pins is able to drive two 16 shift register outputs which can drive 64 devices. This is essentially how a keyboard works.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Why did you stop at multiplexing? The next step is Charlieplexing. \$\endgroup\$ Commented Apr 23, 2018 at 10:33
3
\$\begingroup\$

You first sacrifice some pins to talk to an I/O expander. e.g. you use the two I2C pins to connect to a MC23017. There are lots of tutorials how to do that, including software. That gives you 16 pins so now you have 14 pins more then before. In fact you can connect up to 8 of those giving you 128 pins.

But at a cost: you need to write some I2C software to control those pins, read and write them. That will be much slower that the other Arduino pins. Thus you use those MCP3017 pins for 'slower' signals.

The MCP3017 also has in interrupt out pin but to use that you have to sacrifice a third I/O pin of your Arduino. The software for that is again a bit complex. Howevere it allows you to 'respond' to evens on the MCP3017 inputs.

The trick is to just 'play' with the I/O expander alone, until you understand how it works and have some code how to control it. Then add that to your robotics hardware and software.

\$\endgroup\$
0
\$\begingroup\$

If you have a set of sensors that don't need to be running at the same time (or all the time) you could use a multiplexer to enable them when needed

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.