I read this tutorial on how to controlling four stepper motors with shift register using 74HC595 shift register. I got a (maybe) stupid question. Does this give me individual control of every steppermotor so I basically just can loop throught the steppers and give them individual instructions or am I running them in parallell? I guess this gives me individual controll since if not it wouldnt make any sense making the effort but just want to make sure.
Well, the stepper control outputs are separate outputs on the shift registers, so they can be controlled separately.
The "trick" is that in your code, you have a variable whose value you shift out into the registers. To control each particular stepper, you alter only the bits in that variable which correspond to the particular stepper without altering any other bits. Then you shift the variable out to the registers.
Said tutorial is however doing it the hard way!
Easier to use a ready-built port expander module.
One or more of these connects to your I2C interface.
Thanks! That is a great tip! Is it possible to chain these to get even more ouputs?
I saw this for example.
But it says that you can chain 8 of them. I need lots of outputs
Can you technically chain the one you linked to?
At the moment I am actually already using the i2c, connecting multiple arduinos as slaves to an raspberry pi. Is it possible to continue connecting portexpander through the i2c to the arduino i2c slaves?
As the example below giving me lots of IO:
Well the port expander you cited physically "chains", but they are actually parallel on the I2C bus, each one must have a different address set and there are 8 addresses (three jumpers) available, so eight devices with 8 I/O each.
The module I cited above using the PCF8575 has 16 I/O and while this chip also has 8 addresses available, that particular module only allows four to be selected - I believe other versions of the module make all eight available. You again connect them all in parallel, each having a different address selected, you just have to perform the parallel wiring differently.
As long as the I2C addresses of these devices differ from those you are presently using, you can connect them all together. You will however have to remove the pull-up resistors from all but two or three of the modules, leaving them on those at the ends of the wiring.
@acroscene, I'm not sure your idea will work. The Arduino would have to be an i2c slave to the pi but an i2c master to the I/o expanders. I have read that multiple masters on the same bus is allowed with i2c, but I never heard of Arduino being used this way.
I also do not see the need for the Arduinos in your plan. The pi could control all the I/o expanders directly. Up to 8 pcf8575 can be attached to the same bus, giving 128 outputs. If more are needed, you could add a tca9548 i2c multiplexer, allowing up to 64 pcf chips with 1024 outputs.
Controlling a large number of stepper motors this way might be limiting. I2c bus is relatively slow, and this could limit the maximum speed at which the steppers can be instructed to turn.
Another option would be to use dedicated stepper controller chips. These can generate the signals to turn stepper motors at a given speed and direction without constant updates from a central processor, so the slow speed of i2c would not be a problem.
Ok. Thanks for the answer. I run into another possible solution using TCA9548A 1-to-8 I2C multiplexer. Im not sure but would that allow me to connect multiple parallell port expanders. For example like this:
8 (outputs from TCA9548A) × 8 (number of parallell portexpanders) × 8 (outputs from each portexpander) = 512 outputs
Since my plan is to use the cheap stepper 28BYJ-48 with the driver ULN2003 it will let me connect 512/4=128 steppers using this configuration. It is fine but ideal would be to be able to connect over 200 steppers. Dont know if there are expansions for this number of channels only through one i2c bus ....
Would you say that my assumption above is correct?
You will however have to remove the pull-up resistors from all but two or three of the modules, leaving them on those at the ends of the wiring.
sorry didnt got that? why do I need to do that? and how can I do that?
Paul__B:
How do you plan to determine the reference position of each stepper?
My plan is to use a reset switch to reset the position every now and then
PaulRB:
I also do not see the need for the Arduinos in your plan. The pi could control all the I/o expanders directly. Up to 8 pcf8575 can be attached to the same bus, giving 128 outputs. If more are needed, you could add a tca9548 i2c multiplexer, allowing up to 64 pcf chips with 1024 outputs.
Posted the same time Seems similliar to the solution I was thinking of in post #5. But how did you got 1024 outputs? As I understood it there are 8 outputs from the PCF875 with the possibility to use 8 in parallell = 64 outputs ... * 8 using TCA9548 = 512 ?
hm. not 100% sure yet how to connect everything but the reset switch is just a switch that gives an input to the code for resetting the position of the stepper to 0.
I got this working using multiple arduino mega connected to i2c but using TCA9548 and PCF875 seems like a cheaper solution
acroscene:
As I understood it there are 8 outputs from the PCF875 with the possibility to use 8 in parallell = 64 outputs ... * 8 using TCA9548 = 512 ?
No such chip as pcf875. There is pcf8574 with 8 outputs and pcf8575 with 16 outputs.
Perfect. Thanks for answer. I also found this chip MCP23017 which seems to be recommended. I dont know how it differ from PCF875. However it seems to be widely availible so if it works the same it would be a perfect solution
Yes, mcp23017 is very similar to pcf8575, but often a little more expensive, a little more complex to use, a few more features, but those features probably no benefit to your particular project.
Another possible option to drive your steppers could be tpic6b595. Each chip is similar to 74hc595 + uln2803, so might be able to drive 2 steppers directly with no need for uln2003. But you need to check the current required by your chosen steppers is below 150mA per coil. They can be chained to give any number of outputs, although some signal buffer chips will be needed for a large chain, such as 74hc14 or similar. They can be driven with the pi's spi pins.
Im about to order the mcp23017 anyway for trying. I got a bit confused. At the place where I order there multiple models of mcp23017. I guess they are about the same, just different manufactures. Or are there any difference between these two:
I think they are the same. Same manufacturer, one has a more detailed part number. The "-E/SP" is explained on page 38 of the data sheet. "E" is the temperature range of the chip (-20C to 125C) and the "SP" means a dip chip which is what you need for using with breadboards, strip board etc.
Well, although there are some concerns about the quality of things direct from China (and I doubt Mouser obtains them from anywhere else! ) I would favour an assembled module like this one
Another Aliexpress link
which correctly brings out all three address selection pins.