Need to control 12 Stepper motors on Arduino UNO

I’m building a robot which uses a total of 12 stepper motors, and, since each one needs 2 pins (dir, step), I’m running out of ports on my Arduino UNO.
I’m looking for suggestions on how to circumvent this limit; for instance, 6 of the 12 steppers are always activated at the same time, rotating by the same absolute degrees, only in opposite directions (e.g., 90,-90); can I somehow use the same output pins to control both?
In general, is there a way to somehow “multiply” available ports?

Thanks!

In general, is there a way to somehow "multiply" available ports?

The most popular way is by using a shift register http://www.arduino.cc/en/Tutorial/ShiftOut Although I prefer to use port a expander like the 23016.

You can also do what you said but it is not so flexible. You can use an inverter like a transistor or 74LS04 to make two signals one high and the other low from the same pin to drive your direction lines.

Thanks for the information; that's exactly what I was looking for!

Hi again,

I have now built my circuit with an MCP23016, so now I have access to 8 ports using just 2 analog ports on my Arduino UNO. Since I ultimately need to be able to control 12, or even 14 ports (that is, 6 or 7 steppers), how can I connect 2 MCP23016? Should I connect the second one to one of the 8 ports coming out of the first one, or should I instead connect it to the Arduino using different ports?

Thanks, Giacomo

If you're using the 23016 that is interfaced with I2C, all you need to do is to connect the SDA and SCL (AN5 and 4) to the same pins of the second 23016 and define a different address for them. If you are using SPI, you'll need to use another pin as a chip select for your second 23016.

Easy?

Thanks for your reply, however my experience with this chip is very limited, so I have a follow-up question: How would you go about changing the address of the second mcp? I can see from the datasheet mcp23016 has three pins (A0-A2) to be used or that purpose, but... I have no idea how to do that (i.e., should I connect A2 to another analog pin on arduino, then send some kind of code to that pin?

Thanks, G.

How did you connect those pins now? All to GND?

those pins serve to differentiate the least significant bits of the ICs address. So, if you connected all of them to ground the address of your device now is

0 1 0 0 0 0 0 (the first bit will serve to differentiate between write and read I think). So this ammounts to 32.

If you connect pin A0 to VCC, the address will then be 0100001 = 33. If you connect pin A1 to VCC, the address will then be 0100010 = 34. ... And so on, and so on.

So you can connect 8 of these devices in your bus. Although for that you need to have some care with the pull ups on the I2C lines.

All those pins are simply NOT connected. With only 1 mcp, that worked fine. If I try to connect any of the address pins (A0,A1,A2) to vcc, nothing more works (seems like Arduino itself shorts and cuts out). What am I missing, here?!

Can you post your code?

Maybe you are actually being lucky? Have you tried connecting the pins to GND?

All those pins are simply NOT connected. With only 1 mcp, that worked fine.

No it is not fine, they should not be no connects. Wire them to ground otherwise you will suffer from unreliability.

If I try to connect any of the address pins (A0,A1,A2) to vcc, nothing more works (seems like Arduino itself shorts and cuts out). What am I missing, here?!

You are missing that you have to change the address of the device. Also have you got pull up resistors 4K7 on the data and clock lines? You need them.

connecting any combinatiion of a0,a1,a2 pins on mcp2 to gnd does not make any difference: Every LED connected to mcp2 lights up when the corresponding LED connected to mcp1 does. As for setting the mcp address, my code sets the second as #0x21, so I think I should connect A0 to Vcc. However, when I try to do so directly, Arduino shuts off, while putting a 4k7 resistor between A0 and vcc takes me back to the first scenario (i.e., the one where all the pins on mcp2 are in sync with mcp1). I'm (almost) lost, here...

AAAHHH! I rebuilt the breadboard from scratch, and just realized I had A0 of the second pin also touching the ground! (That also explains Arduino was shorting out when trying to connect A0 to ground…) Now everything works perfectly. Thanks everyone for helping out!

gcaglion: If I try to connect any of the address pins (A0,A1,A2) to vcc, nothing more works (seems like Arduino itself shorts and cuts out). What am I missing, here?!

Glad to know you found the answer.

gcaglion: AAAHHH! I rebuilt the breadboard from scratch, and just realized I had A0 of the second pin also touching the ground! (That also explains Arduino was shorting out when trying to connect A0 to ground…) Now everything works perfectly. Thanks everyone for helping out!