Pages: [1]   Go Down
Author Topic: One Ethernetshield for two (or even more) ATMega's?!  (Read 388 times)
0 Members and 1 Guest are viewing this topic.
Berlin
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

i just wondered if it would be possible to use one Ethernet Shield for Multiple Arduinos.
So for example connect the Shield via an Breadboard to (lets say) two Unos or Standalone ATMegas,
and speak to them seperately by giving them differnt IPs in there sketches.

Looking forward to your answers.

Jewe
Logged

Rio de Janeiro, Brazil
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
Software developer, free software activist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i just wondered if it would be possible to use one Ethernet Shield for Multiple Arduinos.
So for example connect the Shield via an Breadboard to (lets say) two Unos or Standalone ATMegas,
and speak to them seperately by giving them differnt IPs in there sketches.

Hello Jewe,
I don't know if Wiznet W5100 controller can interface with multiple devices using SPI (maybe it can be projected to communicate if only one device) and probably it don't have support to multiple IPs -- my opinion is the same to the Microchip ENC28J60 controller, but we need to read the datasheets to confirm.

One thing you could do is make an Arduino as a "router" (the Arduino that will be connected to Ethernet Shield), it can do NAT and communicate to other Arduinos using I²C or other protocol - but in this case you'll need to implement all the software stuff.
Logged

Blog pt_BR: http://blog.justen.eng.br/
Curso de Arduino (Arduino Course, in Brazil) - http://www.CursoDeArduino.com.br/

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


In theory it can be done, but in practice it will be quite difficult. This is a typical resource sharing problem, which boils down to. How does MEGA 1 knows that MEGA 2 is using the device?

First attempt would be to check the SS pin of the other MEGA and if low the Ethershield is free , however consider the following scenario:


MEGA 1                         MEGA2
------------------------------------------------------
if (SSmega2 == low)       if (SSmega1 == low)
  SSmega1 = HIGH          ssmega2 = HIGH


If the tests are run on the same moment both if statements will be true, and they will both set their SS high => COLLISION !!

Google for interprocess communication sollutions, but be aware that this is not for the faint of heart smiley

A good place to start is - http://en.wikipedia.org/wiki/Dekker%27s_algorithm - but it is written for a different situation ..

==
The solution proposed by alvarojusten, to have one Master dedicated to communication would work quite well. Think that is the way to get started.

Another way to solve it is a "token ring" approach:  all the arduino's that want to use the resource, share ONE token that gives the right to use the resource. If you don't want to use the resource you give the token to the arduino next to you. Furthermore you may only use the resource for a limited time. This prevents starvation and deadlock - all arduinos will eventually get their turn. The price of this solution is you need to implement a token passing system between all participating nodes - you need at least 2 pins for this token passing. e.g. you might pass the char 42 over serial line to the next arduino.

Both solutions have their strengths and their weaknesses, if you want a dynamic system with an adaptive number of nodes you need something more intelligent e.g. a master that controls the list of arduinos that want to use a resource. The master takes care that every arduino gets the token, (star iso ring)

Succes.














Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: