Goodmorning,
I’m starting with a new arduino project and I’m a little bit confused about the communication protocol between modules. As you can see from the attached picture, I’ve a pc that sends data to an arduino mega that forward the data to all others devices (arduino Uno) connected in daisy chain that does other stuff extracting the right data from string and using just digital pins (5 or 6).
The system is quite easy and must be scalable; a string is sent to the master, and the same untouched string in sent to other devices. I’m trying to find the best communication protocol. I removed i2c from my list, due to the addressing (communication is 1 to 1), so the remaining ones are SPI and UART.
Here there’s a list of specs that the system has to have:
Scalable;
Short distance, at least 2 meters;
Fast (string has a fixed length, at least 150/200 chars);
Full duplex (read the bottom lines);
In the first implementation, I will work just in half-duplex M->S, but when I will end with tests, I will need to implement the full duplex (maybe managed via interrupt) for some byte data (eg. Int value, Boolean value). Already i've all hardware i need (1 mega and 2/3 uno), and this is not my first project.
The system is quite easy and must be scalable; a string is sent to the master, and the same untouched string in sent to other devices
So, to clarify this: a data packet, be it string or otherwise is sent from from a node to the master, while, as you say, at the very same time a data packet is sent to other slaves. Does this mean the master is sending the data packet to the other slaves while receiving the data packet from a slave ?
If so, why would you make it so that the master sends a data packet to other slaves while receiving a data packet from a slave that was not yet decoded ?
Normally as part of data communications in such systems, the master receives and decodes a data packet and then sends and acknowledgement back to the source before sending out any other data packet communications on the network to other slaves.
Apart from this, why are you sending string of ASCII character data packets when a better method such as tokens for string messages would be better ? The tokens can be simple integers.
For the distances you are wanting, I would look at simple asynchronous communications, possibly using RS-422 electrical specification.
It might be that you can use TIA-485 electrical specification and use a data protocol such as Modbus.
You do not define 'Fast' as it should be time related, as in data information rate.
rockwallaby:
cental63 writes: So, to clarify this: a data packet, be it string or otherwise is sent from from a node to the master, while, as you say, at the very same time a data packet is sent to other slaves. Does this mean the master is sending the data packet to the other slaves while receiving the data packet from a slave ?
the master recieve a string from pc with this format: /fvalue/gvalue/xvalue; after recieved all the string, the master forward the string to clients and each clients (/"letter") read his value and do some stuff. i think that without processing the data into master, it would has less work to do, and in the meanwhile clients process the string, the master can recieve a new string from pc or (in the next step of the project, recieve some data from clients, but just once the master has sent the data. i know i'm not so clear, sorry
rockwallaby:
If so, why would you make it so that the master sends a data packet to other slaves while receiving a data packet from a slave that was not yet decoded ?
send/recieve data not in the same time. when the master will recieve data from a slave, it has to send to pc. but as i wrote in 1st post, this will come into next level of project. i wrote just to let you know what are my intents and so choose the right protocol
Based on the limited information you have provided I reckon the simplest thing is for the Mega to send the data (using Serial1) to all of the Unos at the same time. In other words all of the Unos are listening to the Tx line from the Mega.
If the Unos need to respond to the master it is a little more complex - but not much. You can't directly connect several Tx lines to a single Rx line. The way round that is to connect the Mega's Rx line with a 4700 ohm resistor to Vcc (5v) and place a diode on each of the Unos' Tx lines so that the Uno can pull the Mega's Rx line low but the diode prevents it from driving the Rx line high.
Of course you also need to arrange things so that only one Uno tries to talk at any one time. An easy way to acccomplish that would be to get the Mega to send a message addressed to each Uno in turn and when an Uno receive a message with its address it knows it has permission to send a reply.
You could also create a similar system using wireless with nRF24L01+ modules.
cental63:
each uno has a role, like move a stepper into a specified position, read from string sent from master
Isn't it a lot easier to have the "master" handle those tasks by itself? Instead of a communication wire to an Uno you just have a wire going directly to that stepper. A single Arduino can handle lots of tasks at the same time.
about 5-10 cm.
i read something about rockwallaby said. i think that modbus would be the best choise (even not the simple one). as i understand, i need to buy a shield like the sparkfun one or something similar.
this means waste of time
what you think about modbus choise?
wvmarle:
Isn't it a lot easier to have the "master" handle those tasks by itself? Instead of a communication wire to an Uno you just have a wire going directly to that stepper. A single Arduino can handle lots of tasks at the same time.
i know that, but in this way i could not have scalability.
i'm building a cockpit that simulate an airplane, so there are lots of stepper (like x27, 1 per instrument). already i build a small one with just few motor, 1 arduino and it works fine.
consider that there are also yoke, rudder pedals, switch and other things; in fact i tought to use a raspberry as master and write a parallel software (1 for send and 1 for recieve). thats what i study (comp. eng.)
How about this - Have the Mega talk to PC on serial via USB, and talk to up to 3 Unos on Seria1, Serial2, and Serial3?
Pass along the serial message received to all the slave one at a time. It the message is short, it won't take long at 115200 or 230400.
That leaves you 62 IO on the Mega, and 18 IO on each Uno.
Could always exchange the Unos for Megas, and then have 68 IO available on each slave.
I don't know many IO are used to control a stepper, likely depends on the control board being used to drive the stepper motor. Might be as little as two - step and direction to step. Or step CW, step CCW.
CrossRoads:
How about this - Have the Mega talk to PC on serial via USB, and talk to up to 3 Unos on Seria1, Serial2, and Serial3?
it could be done, except for the fact that the arduinos (i'll just use the atmega, not all the board) would be 15 or more. than, in this case i would have not scalability.
i try to explain: once all the system is done, if i want to add a simulated instrument, i just need to connect the output of last arduino in chain, to the input of the one that becomes the last (see picture). in this way, i have just to "add data" on the string sent from pc to master arduino (mega). this last thing is made via software on pc, so it would be easy to connect new instrument.
i viewed a complete system into a website, but i don't know if i can publish website link
I would go with 1284Ps then. Dual hardware serial, can keep up the fast speeds. No worries about needing up speed or concerns about devices farther down the chain having enough drive for the capacitance of all the wiring.
void loop(){
if (Serial.available() >0){
incomingByte = Serial.read();
Serial.1write (incomingByte);
}
// do something with the byte that was just read, decode it as an address, handle it as data, etc.
}
wvmarle:
Then you have to use SoftwareSerial as the Uno has only one Serial port.
no, because the master is a mega; Uno has just to read the data and, for example, move a stepper motor or do some other stuff
wvmarle:
Why not using I2C? Then you can easily add up to 128 Unos. Just give them all a unique address to listen to.
this would be the best solution for me, because i know this protocol and i use it from some years (but just between modules on same pcb). i read on the web that i2c is more sensible to noise, and is preferred for short distance instead of serial like rsXXX or spi
Robin2:
Based on the limited information you have provided I reckon the simplest thing is for the Mega to send the data (using Serial1) to all of the Unos at the same time. In other words all of the Unos are listening to the Tx line from the Mega.
If the Unos need to respond to the master it is a little more complex - but not much. You can't directly connect several Tx lines to a single Rx line. The way round that is to connect the Mega's Rx line with a 4700 ohm resistor to Vcc (5v) and place a diode on each of the Unos' Tx lines so that the Uno can pull the Mega's Rx line low but the diode prevents it from driving the Rx line high.
Of course you also need to arrange things so that only one Uno tries to talk at any one time. An easy way to acccomplish that would be to get the Mega to send a message addressed to each Uno in turn and when an Uno receive a message with its address it knows it has permission to send a reply.
i understand the phase of tx from mega to UNOs, just 1 wire. the answer of UNOs comes just when a button, pot or encoder are used. i don't understand how use 1 line for all UNOs tx.
however i think that this is the easyest way instead of mobus, what you think about?
Robin2:
You could also create a similar system using wireless with nRF24L01+ modules.
IMHO what I wrote in the second paragraph of that Reply provides a very simple wired solution to your problem.
I reckon the simplest thing is for the Mega to send the data (using Serial1) to all of the Unos at the same time. In other words all of the Unos are listening to the Tx line from the Mega.
Robin2:
IMHO what I wrote in the second paragraph of that Reply provides a very simple wired solution to your problem.
...R
thats ok, and in post 16 i said that everything was understood, except the tx from single slave to master (i understood that all tx UNOs are in the same line). i'm sorry if there's some misunderstanding, but english is my 2nd language