Hi folks,
I've given myself quite a challenge, I want to have multiple Arduino's talk to as much as 3 other Arduino's, at the same time, both ways, over 1 cable.
The 1 cable issn't an issue, when you switch the tx port to input mode when it's not transmitting everything seems to work as usual, without requiring extra hardware components.
Most people will say the multiple simultaneous communication is not possible, because an Atmega only has hardware support for one, but it's actually coming along quite well using SoftwareSerial, it's just slow. A big part of why it's slow is because of a problem I can't figure out, so I need some fresh input.
The reason why I'm trying to do this with simple Arduino's is because of costs, I want to build a big network.
Concept
I'll briefly try to explain what I'm doing at the moment. As you probably know there can only be one SoftwareSerial listening at the same time, so I switch the listening connection at a slightly random interval. This makes sure that all the connections overlap from time to time, because I can't predict the timing of the other Arduino's.
This means a arduino is talking to a "wall" from time to time, so I wrote a little library class that handles a connection, kind of a layer on top of SoftwareSerial. Just like SoftwareSerial keeps a buffer for incoming messages, this class keeps a buffer (queue) for outgoing messages. When a message is send it will wait for a confirmation message before it's removed from the buffer, until then it will try to resend it at a random interval.
Every cycle an update method is called, this will try to send a message and check if there are incoming messages. When there is a new message and it's not a confirmation it will send a confirmation back. These confirmations contain the checksum of the original message so that they can be checked.
There are a few extra tricks, but this is the gist. An Arduino will for example "wait" after sending a message (which means not sending other messages and not switching to another connections) until there is a confirmation or the max waiting time expires. A message, containing a type, value and checksum is translated into one byte.
Main problem
The main problem at the moment is that sometimes the confirmation message isn't received or transmitted properly. When I hook up two computers I can see the main message is transmitted, it's received, the confirmation message is send, but it's not received. And I'm pretty sure both parties have enough time to send or receive this confirmation. This would be normal for the normal messages, but the confirmation messages should almost always arrive because the sender waits for the confirmation.
Test setup
I've tried to simplify the setup for testing purposes. Two Arduino's are connected to potmeters, when you turn this it will send a message and the other Arduino's led's brightness should change. I simplified the potmeter's positions to 4 positions.
I did a test and counted the amount of times arduino a send a message and the amount of times arduino b received the message. The first column is the value that was send.
A sending:
1 25x
2 1x
3 1x
2 1x
3 1x
2 42x
1 1x
0 10x
1 50x
B receiving:
1 9x
2 1x
3 1x
2 1x
3 1x
2 12x
1 1x
0 1x
1 20x
I've added the code. Below is a illustration of my simple hardware setup.
(I'm actually using Ottantotto's instead of Arduino's)
More information on this project:
http://peteruithoven.nl/resilient-network
Thanks in advance for your input!
Please let me know if something is unclear.
attachment.zip (302 KB)