The EtherCard library has static variables inside, which are not declared inside the class. That is only one of the problems. So you would have to rewrite large parts of it.
If you have enough 3.3V power available (I think the Nano can not supply that), the hardware should be no problem.
If each one runs (without the other), the hardware should be okay.
How do you call the EtherCard with pin 9 ? It is the third parameter for ether.begin().
Changing the library for dual use is not simple. The best way is to move the variables as static into the class, so you can create multiple classes. I scrolled through all the code, and it should be possible, but it's not easy. If you forget one small thing it won't work. And I don't know if the Arduino Nano has enough memory.
I think you could do it by changing the slave select pin in the library. I've been looking into this since another user brought up this question about the w5100 ethernet shield.
You would need to add another function to the library. I thought Ethernet.select() would be a good function name.
// this for D10 as the slave select
Ethernet.select(10);
// this for D9
Ethernet.select(9);
Here is the code that selects the slave select for the w5100 in w5100.h. You would need to replace the constant in each _BV() call with a variable that you could change. This way it would require almost no more memory that the original ethernet library code.
thanks to karma,
I note the suggestions for modify the library.
I call Enc28J60 by ether.begin(... ,9)
For the future, of course I will move to a Mega 2560, so that Ram is available for one or two full Tcp packet (1500 bytes each)
Note that at this time I am not using the two adapters simultanously.
My test program runs fine for ech one (changing 10 to 9 of course),
I note that if I unplug the "pluggable with fixed pin 10 inside" the wired Enc28J60 is OK.
If I insert the Pluggable betwen Arduino Nano and my base, the wired one does'nt answer,
more exactly the function readop return always 0, and initialize is in an infinite loop.
I dont have fast tool for watch the signals, but I suspect that the "pluggable" conflict on some pin.
Now, I have to buy a lot of "Dupont" wires and test more.
Regards.
PO.
I just tested this theory with my w5100, and it works fine. It took a few library mods, but I can change the ethernet slave select with my new function "Ethernet.select()". I did a pin bend of D10 on the ethernet shield, and jumpered to D9, and I can change the slave select to match.
I know the 'normal' W5100 based internet shield can share the SPI bus with others.
I assume that the ENC28J60 can do that too. You still have to set the 'SS' pin as output. The ATmega328p chip only works if the 'SS' pin is set as output, regardless of which chip-select pin is eventually used. If that is not the problem, I have no other ideas.
Thanks for all answers,
my work is not finished but I am a bit more clear on what happens.
Following your links, I read a lot of pages and discover the SS register and how to share SPI bus.
Now I am moving to Arduino Mega 2560 with two wired Enc28J60 .
I will come back here when I found a solution.
Regards.
We forgot to ask why you need two ethernet links. There could be many other ways to achieve your goal.
You have two physical seperated ethernets ? (There must be other ways to do that).
Or you want to have two webpages ? (one Arduino can support thousand webpages from an SD card).
here is why I plan to use TWO ethernet plugs.
I suppose that my (remote) brewery contains some TcpIp machine, in true life: an Usb Over Ethernet bridge (by Belkin, like: http://www.belkin.com/networkusbhub/ )
my device is for local LAN, so I need a tunnel from home to my brewery.
Of course, I know how to build it, using OpenVpn and two routers as DdWrt.
I am searching for a lighter solution.
I plan a "gadget" based on Arduino.
If the gadget and Usb-bridge are connected to local remote router, the Dhcp request from Usb-Bridge will be served faster by local box than by tunnel and my Home network.
So, I hope a solution is to have an Arduino with TWO rj45:
first one connected to the remote Box/Lan used to access to Internet and my home
second will be a remote-plug for my Home-Lan.
Program on the Duino, will send ALL packets seen on the second interface to peer machine at home via the first one;
and by the way, write on the second all packet received from peer on the first.
(Of course, packets (header and data) on Internet will be embedded in Udp packet)
I know a bypass with ONE interface, using Fixed Ip, to avoid Dhcp dialog, but it is boring.
I suppose that using "ethernet tagged" is an alternative, but no information about it.
Best regards.
PO.
My first thought would be the two routers option. I would consider that already as 'light'.
I think the Arduino might be too slow for the usb over ethernet. I don't know if the driver will be happy with the delay.
I have also doubts about the reliability, even a good router can get stuck, and with the Arduino extra unknown things are added.
Or perhaps a Raspberry Pi with two ethernet connections would be better, but I don't know if that exists.
I hope others will reply, perhaps someone has a few good pointers.
Hello,
I leave this thread ; I mov to Arduino Mega 2560 with two wired Enc28J60.
(However I needed more Ram than available on Nano)
Now I cope with my skech and libraries.
Here is my new sandbox: