Hi,
I have a project in which I need to connect at least 2 ethernet shields to one arduino uno board. I have read a lot of similar topics, but there was no clear answer to this question.
I know that I need to connect the first eth shield to pin 10, cause it's by deafult SS pin, and the second one to another not used pin for example to pin 9. Then I need to set pin 9 in the following way:
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
but what then? How to select shield connected to pin 10, when I want to do some action using it, and how to select pin 9 afterwards?
I already tried modyfyng Ethernet and w5100 libraries, so I could use
Ethernet.select(pin);
as it was said on other topic:
SurferTim:
OK. It works now. The new files are attached. I tried most of the sketches I have and all are running ok.It should be compatible with older sketches now. If you do not call Ethernet.select(), it uses D10 by default.
Here is the DhcpAddressPrinter sketch from the ethernet library examples modified for D9 as the w5100 slave select. I bent D10 on the shield so it wouldn't insert into my Mega, then jumpered D10 and D9 on the shield.
/*
DHCP-based IP printer
This sketch uses the DHCP extensions to the Ethernet library
to get an IP address via DHCP and print the address obtained.
using an Arduino Wiznet Ethernet shield.
Circuit:
- Ethernet shield attached to pins 10, 11, 12, 13
created 12 April 2011
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
int freeRam() {
extern int __heap_start,*__brkval;
int v;
return (int)&v - (__brkval == 0 ? (int)&__heap_start : (int) __brkval);
}
void setup() {
// start the serial library:
Serial.begin(115200);
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
Serial.print(F("SRAM left: "));
Serial.println(freeRam());
// start the Ethernet connection:
Ethernet.select(9);
Serial.println("Starting ethernet");
while (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
delay(5000);
Serial.print(F("SRAM left: "));
Serial.println(freeRam());
Serial.println("trying DHCP again");
}
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
}
void loop() {
byte updateVal = Ethernet.maintain();
if(updateVal) {
Serial.print(F("DHCP maintain..."));
switch(updateVal) {
case 0: Serial.println(F("no action"));
break;
case 1: Serial.println(F("renew failed"));
break;
case 2: Serial.println(F("renew success"));
break;
case 3: Serial.println(F("rebind failed"));
break;
case 4: Serial.println(F("rebind success"));
break;
default: Serial.println(F("unknown"));
}
}
delay(1000);
}
edit: Use the files in reply #21.
this is from topic: Change SS pin on Ethernet Shield
I'm using Arduino 1.0.6 IDE, and I have arduino uno rev. 3 board and arduino ethernet shields rev. 3