Arduino Array.. How to ?

Hello All,

First, I am newbie with Arduino & electronics staff , So excuse me for my question.

I Need to use Arduino with a project i am building, simply i want to control a number of solenoids valves, But the problem is that the number of those solenoids are not fixed, I may use 10 this timer, after while maybe be 100.

Here's my vision :
User one Arduino as a master controller, this one receive commands via telnet, i already finish this step.
The next step is passing the commands to the slaves Arduino boards .
The commands will be 0 & one for each port. so if i want to open 10 solenoids I send "1111111111" via telnet. and if they are 100 solenoids i send 100 number (0 or 1).
The problem is how i can make the master Arduino board send the received command to the first slave board, this slave board will only use the first 10 numbers from the command, and pass the other 90 numbers to the next slave board .. extra extra ..

Can i connect them using SPI ? or there's another way ?

Thanks all in advanced
Regards,

Think you should check I2C for this, check - http://www.arduino.cc/en/Tutorial/MasterReader - I2X allows 100+ slave devices so that will be quite enough I think

The master distributes the command to the appropiate slaves. so every slave just gets it's own 10 bits. The slaves can hold state (e.g. in EEPROM?) which can be requested by the master if needed.

Because it is logically a star the master stays in control and the master will know if a slave fails (e.g. not responding) so it knows when to retry /alarm etc.

If you make a chain in which slaves forward the commands, a failing slave cause a failing (sub) chain.

Disadvantage: master is slightly more complex,

Another option is the centipede shield - see: http://shieldlist.org (?) - which allows 64 digital IO's and if I am correct these may be stacked.

Robtillaart,

Thanks for your fast replay.

I already checked with I2C, It great but i only have one question i didn't found a solution for it online.
When I initialize a slave board I setup the slave address (e.g. Wire.begin(2); for address #2).
How i setup every slave board address without change the software everytime, I need to develop this boards as a plug-n-play modules.
i though about using DIP Switches on every slave to config the board number, but I am sure that there's a better solution for this, Right ?

And, Thanks again Robtillaart : )

The real problem is a level deeper. How does the master knows which slave (nr) controls which solenoids (nrs)?

There must be some relation between these two. This can be a lookup table, or hardcoded but it needs to be configured.

An hardcoded way could be to let slave N control solenoids N10 .. N10 +9 Such a direct mapping makes coding quite easy and you don't need a lookup table - 100 solenoids that could mean a 200 bytes for the LUT { slaveID, solenoidID }*. This is replaced by slaveID = solenoidID %10;

One way to handle this is to put the I2C ID in EEPROM, and include a command to overwrite the ID from the master

"change 23 14" would send a I2C message from the master to device 23 to change its address to 14.

If you default give a new slave the address 100, you can add it to the I2C bus and then "change 100 newnr" to

HOpes this helps

Can't we find another way to connect them than the I2C method ?
Cant we connect Master to first slave, then first slave to second slave.. etc, so every time the command pass's on a slave board it cuts the needed bits and send the rest to the next board ?

Thanks for helping me

Can be done easily.

MASTER --> serial --> SLAVE1 --> serial --> SLAVE2 --> serial --> SLAVE3 etc --> SLAVE10

connect the TX of the master to the RX of the slave, the TX of the slave to the RX of the next slave etc. If you want it bidirectional (to get status back) , you must add NewSoftSerial to instantiate a second serial port. Or you make a full ring in which the last slave connects to the master again

But the core problem will still be the same, how does the MASTER knows which solenoids are attached to which slave?

In this pipeline architecture every slave has to pass through all messages that are not intended for him. The responsetime of the slave depends on its position in the pipeline in case of bidirectional. A ring would have more or less the same responsetime as a message passes through the complete ring every time.

Drawback of these chains is imho that there is more communication overhead and the slaves need to do some parsing to see what is meant for them. Not very difficult but not needed in the star topology of I2C. BUt maybe the biggest is that if one slave fails all slaves after it are not reachable anymore.

Better?

robtillart mentions the most obvious weakness of the dasy-chained UARTs scenario, IE if one fails all those "downstream" fail as well. But I think it's fair to say that this is unlikely and unless your solenoids are controlling some heart-lung machines it probably doesn't require worrying about.

That said I like the chained idea, sure the master has to know what solenoid is connected to to what slave Arduino pin, but I think that (or some similar hardcoding) will always be the case for the master code. Meanwhile all slaves can easily be loaded with exactly the same code to handle their own solenoids and the system is easily scalable.

All the master has to do is determine the number of slaves. On reset you send 0 to the first slave, it records that number as its place in the chain, increments it and sends it to the next one. This continues until the master gets a number back, that number is the number of slaves in the chain.

Now the master sends N bytes with bits set or reset according to the solenoid state (let's assume 8 solenoids per Arduino for the moment), slave #0 uses the first byte, #1 the second etc etc.


Rob

Using serial is a good idea, but the master arduino have a Ethernet shield attached to it, so there's no more serial pins available, and i dont know if the virtual serial pins will work good with my project or not, I may send a new command every 10 ms , is it will be fast enough ? i also saw some other limitations for this method.
And about the slaves problem, as Graynomad said, every slave board will handle own solenoids, so i think that this is not a problem.

Graynomad, Your chained idea is really great.. but using the virtual serial method fast enough with my conduction or not ?

Also, I'll use a 12v 5ma solenoids, which better driving them with a Mosfet or a transistor .

Thanks All,

I may send a new command every 10 ms

New soft serial will be fast enough depending on the length of the chain. As the chain gets longer the data stream also gets longer and at some point you won't have enough time for all the transmissions.

At 115200 that's about 11,000 bytes a sec or 110 bytes (or 880 solenoids) every 10mS, so you should be good for quite a few slaves.

I'll use a 12v 5ma solenoids, which better driving them with a Mosfet or a transistor .

Either, I see no practical difference between the two in this application.


Rob

Graynomad,

I got a better idea better then using many Arduinos.
I'll use only 1 arduino and Interfacing it with shift registers (74HC595), Easier & faster ( I Think!! ).

Now Could you help me choosing the right transistor for this project, and what resistor value that needed between the shift register and this transistor ?
If I used the 74HC595 what transistor can handle up to 5 mA with 12 volts ?
Also is it possible to use a NPN Transistor Array IC, Like ULN2804 ?

Thanks for your efforts
Regards

Are you sure the solenoids only take 5mA? That's very low for a solenoid.

Sorry, its 0.5 A
Sorry again ( :

something like this should work:

or its PNP equivalent, if you want to implement the transistor high-side:

might be nice if you can find a big IC with a bunch of them though, but something like that will do the trick. handles 40V, up to 1.5A, base easily driven by the arduino pin or a 74HC595 pin.

although come to think of it, I'm not sure you should try the PNP version since that would expose the arduino/74HC595 pin to +12VDC I think...

for that transistor I just posted, the hFE is around 100 so to drive 500mA you'll need at least 5mA going through the base... 5VDC/5mA = 1000 ohm resistor, probably use 500ohm between the arduino pin or 74HC595 pin and the base just to be safe (to make sure you fully saturate it so it switches "on" with commitment).
note I'm not an expert on this, still learning myself, but I think that's right :slight_smile:

also don't forget the shunt diode across each load, to dissipate backvoltage from the solenoid when it gets turned off. where you wire that I am not sure.

spirilis,

Thanks for your updates.

The bad news is this transistor is not available in local market here.
What is available here is 2N Series, 2SA Series, 2SC Series, BC Series And TIP Series .. if you helped me choosing the right one this will be great, I am also still learning myself, And i still can't understand the datasheets well : (

What about this one http://www.ram-e-shop.info/ds/ic/ULN2803.pdf ? can it do the jop ?

And thanks again spirilis ( :

Yeah that looks nice, and it already has resistors built into the inputs (base) so you don't have to supply your own. Sounds good!

That's mean I can connect this ULN2803 directly to the shift register and it do the job well and supply enough current to solenoids ?

Thanks

If I'm not mistaken, yes.
Just be sure you order the ULN2803A model, not the 2801 or 2802 or 2804 or 2805 :slight_smile:

I really don't think the ULN2003A is adequate for this job. The absolute maximum collector current is 500mA, which is the current you want to switch - so no margin there. At 350mA the saturation voltage is 1.3v typical. It will be worse at 500mA. So expect it to dissipate about 750mW per solenoid that is turned on. The limit for the total p[ackage is 2.2W, therefore you can turn on at most 3 solenoids at once with this device before it overheats.

If you were to use 2 elements of the ULN2003A connected in parallel per solenoid, that would be better, however you would still be limited to 3 or just possibly 4 solenoids per device.

I'd suggest using one BC337 transistor per solenoid, each with a 180 ohm base resistor, and a flyback diode (e.g. 1N4001) across each solenoid. Each BC337 will dissipate about 350mW when it is on, which is well within its limits provided you have good airflow around them.

dc42,

Thanks for your post.

I found on google a page talking about using arduino with 74HC595 ICs, They wrote that the most current I can get through each output pin is 35 milliamps, (source : http://tronixstuff.wordpress.com/2010/04/30/getting-started-with-arduino-–-chapter-four/ ).

Can this currant with a 180 ohms resistor drive the BC337 transistor ?

Thank you
Thanks all