Basic question about Ethernet Shield

I purchased an Ethernet Shield, and I haven't used it yet.

I notice it plugs onto the top of all the pins on the Arduino, does this mean it uses all of them? Can I no longer use them for my own use? I presume it isn't using them all, only some of them. Which pins can I no longer use?

Here's a link to the schematic.


More info at adafruit.com

Ok, presume I can't read that...

Actually I'm not sure I have that shield, I have this one:
http://store.fungizmos.com/index.php?main_page=product_info&cPath=65&products_id=229

Those pins are passthrough. this means that you can connect to any pin and plug other shields on top but you need to check the documentation to see which pins are used by the board.

massimo

It came with no documentation, just a link to the arduino.cc site that talks about the ethernet shield (and has a picture of it).

Duh, nevermind. I found it: Arduino uses digital pins 11, 12, and 13 (SPI) to communicate with the W5100 on the ethernet shield. These pins cannot be used for general i/o.

For anyone else.
The information can be found under /hardware in the shields section of the page.

This is what you want to look at:

Has the pin information on the page.

As well as the library info:

Gordon

I can't use pin 8 and 9 for normal I/O, like digitalWrite ??
Pin 2 to 7 works fine, any idea? :frowning:

According to the schematic, those go to pins on the SD card socket. If you don't have an SD card in the socket, there should be no electrical connections to those at all.

-j

When I set digital pin8 (or pin9) to HIGH it will be in High status until I do a Client.print, se code:

if (i == '7') {
digitalWrite(8, HIGH);
delay(9000); // high status until delay ends ???
client.print("Relay 7 ON");
client.println("
");
} :cry:

strange. wild guess here: glancing at the library code, they seem to access the port directly. Is your pinMode for pins 8 and 9 set before the Ethernet library setup? if so, move it to after.

-j

It's already after, like this:

void setup()
{
Ethernet.begin(mac, ip, gw);
server.begin();

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);

}

Just to remind you, I don't actually have an ethernet shield. you have been warned. :slight_smile:

Looking in utility/spi.h, I find:

#define SPI0_Init()          DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT;\
                      PORTB = SPI0_SS_BIT;\
                      SPCR  = 0x50

The troubling bit is PORTB = SPI0_SS_BIT. I think this is the problem.

Perusing the rest of the code, it appears that this gets executed every time the library talks to the chip. So, I'm gonna take a wild guess that the pin does get turned on, but gets turned off the next time you make pretty much any Ethernet library call.

If I'm right, this is a bug. SPIO_Init() should not set those two lower bits that are not in use by the device.

-j

Your findings seems to be the problem. Who can fix it? Are there some owner of the code to send the "bug" to ?

This may not be the whole problem, as those PORTB pins may be misued in other places (e.g. setting DDRB, more instances of setting PORTB, etc).

In the mean time, you can try this fix: go to your arduino software install directory. Edit hardware/libraries/Ethernet/utility/spi.h and change the line

                      PORTB = SPI0_SS_BIT;\

to look like

                      PORTB |= SPI0_SS_BIT;\

note the change is the operator, |= instead of =. Once you make the change, remove all the .o files in hardware/libraries/Ethernet/utility and hardware/libraries/Ethernet to force a recompile of the Ethernet software.

Try that and get back to us. If one of the developers hasn't noticed and jumped in pretty soon, I'll log a bug in the software "bugs" forum.

-j

I have now done the update to spi.h
Unfortunately I am not familiar with this type of software, how do I recompile the Ethernet software? Force ?

Remove all the .o files in all subdirectories. To do it on unix (mac os x/linux):

bash$ cd [wherever arduino is installed]/hardware/libraries/Ethernet
bash$ rm *.o */*.o

The next time you compile a sketch the library will be recompiled.

-j

Unbelievable !!
Now it's works ;D.
Thank you very much

Thomas in Stockholm

Glad it worked.

I've already logged a bug report, and the developers are aware of the problem.

-j