Ethernet Shield for Arduino Mega.

I'm developing a project where I need use 3 serial conections at the same time, so mi Duemillanove is a little "small".

I've been looking for a Ethernet Shield for Arduino Mega, but all I've found are only compatible with Duemillanove. Does it exists????

Thanks!

Yes, please! I too need an Ethernet shield for the Mega! For now, I'm using the very inelegant and complicated solution of using a Duemilanove with the Ethernet shield, connected to the Mega via serial. It's expensive, complicated and error-prone.

Are there plans to develop a Mega Ethernet shield?

Someone has put instructions on the web that tell you which pins must be connected. SPI on the mega is not on pins 11/12/13 as on the ATmega8 series arduinos, so there must be some rewiring.

I think the software is compatible once the physical connection is made.

-j

I have the ethernet shield working on my MEGA. You don't have to re-solder or anything:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1239058804/0

It says to wire:

MEGA pin 50 (MISO) to Arduino Ethernet Shield pin 12.
MEGA pin 51 (MOSI) to Arduino Ethernet Shield pin 11.
MEGA pin 52 (SCK) to Arduino Ethernet Shield pin 13.
MEGA pin 53 (SS) to Arduino Ethernet Shield pin 10.

Locate the file spi.h in the hardware/libraries/Ethernet/utility directory, under your Arduino 0015 installation.

Find and replace the following 5 lines:

#define SPI0_SS_BIT BIT2
...
#define SPI0_SCLK_BIT BIT5
...
#define SPI0_MOSI_BIT BIT3
...
#define SPI0_MISO_BIT BIT4
...
#define IINCHIP_CS_BIT BIT2

and replace them with this code:

#define SPI0_SS_BIT BIT0
...
#define SPI0_SCLK_BIT BIT1
...
#define SPI0_MOSI_BIT BIT2
...
#define SPI0_MISO_BIT BIT3
...
#define IINCHIP_CS_BIT BIT0

These 5 lines are in a non-consecutive order in the spi.h file.

After you save the edited spi.h file, remove all .o files in the utility and Ethernet directory.

Thanks! I had already found this information, too.

I hope they find a way to automatically swtich the spi.h file when we choose the board on the Arduino IDE. I don't mind the rewiring... much.

I'll be trying this out tommorow.

Thanks again!

Here's how I changed spi.h to automatically detect the board type.

//-----------------------------------------------------------------------------
//AVR Mega168 SPI HAL
// MODIFIED by Roy Kniskern to handle the Mega pins 7/19/09

#define BIT0              0x01
#define BIT1              0x02
#define BIT2              0x04
#define BIT3              0x08
#define BIT4              0x10
#define BIT5              0x20
#define BIT6              0x40
#define BIT7              0x80


// __AVR_ATmega1280__ will be automatically #defined if the Arduino Mega board is selected
// the ATmega1280 is the chip used in the Mega
#ifdef __AVR_ATmega1280__
      // use this to use Ethernet Shield with Arduino Mega
    #define SPI0_SS_BIT           BIT4  
    #define SPI0_SCLK_BIT         BIT1
    #define SPI0_MOSI_BIT         BIT2
    #define SPI0_MISO_BIT         BIT3
#else
      // use this for smaller Arduinos (Original version)
    #define SPI0_SS_BIT           BIT2  
    #define SPI0_SCLK_BIT         BIT5
    #define SPI0_MOSI_BIT         BIT3
    #define SPI0_MISO_BIT         BIT4
#endif

#define SPI0_SS_DDR           DDRB
#define SPI0_SS_PORT          PORTB

#define SPI0_SCLK_DDR         DDRB
#define SPI0_SCLK_PORT        PORTB

#define SPI0_MOSI_DDR         DDRB
#define SPI0_MOSI_PORT        PORTB

#define SPI0_MISO_DDR         DDRB
#define SPI0_MISO_PORT        PORTB


#define SPI0_WaitForReceive()       
#define SPI0_RxData()         (SPDR)

#define SPI0_TxData(Data)     (SPDR = Data)
#define SPI0_WaitForSend()    while( (SPSR & 0x80)==0x00 )

#define SPI0_SendByte(Data)   SPI0_TxData(Data);SPI0_WaitForSend()
#define SPI0_RecvBute()       SPI0_RxData()

#ifdef __AVR_ATmega1280__
      // use this to use Ethernet Shield with Arduino Mega

  #define SPI0_Init()     DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT;\
                        PORTB |= SPI0_SS_BIT | BIT0; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\
                        SPCR  = 0x50  
#else
      // use this for smaller Arduinos (Original version)
  #define SPI0_Init()     DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT;\
                        PORTB |= SPI0_SS_BIT; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\
                        SPCR  = 0x50  
#endif                        
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//IInChip SPI HAL
#define IINCHIP_SpiInit         SPI0_Init
#define IINCHIP_SpiSendData     SPI0_SendByte 
#define IINCHIP_SpiRecvData     SPI0_RxData

#ifdef __AVR_ATmega1280__
      // use this to use Ethernet Shield with Arduino Mega
  #define IINCHIP_CS_BIT          BIT4
      // use this for smaller Arduinos (Original version)
#else
  #define IINCHIP_CS_BIT          BIT2
#endif

#define IINCHIP_CS_DDR          DDRB
#define IINCHIP_CS_PORT         PORTB

#define IINCHIP_CSInit()        (IINCHIP_CS_DDR |= IINCHIP_CS_BIT)
#define IINCHIP_CSon()          (IINCHIP_CS_PORT |= IINCHIP_CS_BIT)
#define IINCHIP_CSoff()         (IINCHIP_CS_PORT &= ~IINCHIP_CS_BIT)
//-----------------------------------------------------------------------------

I made the above code changes to the spi.h -- but still doesn't work. What do I need to delete? I'm using v18. Also, do I need to use any jumpers or is this just a code change and the MEGA works.

Got it working... in case anyone else needs this in the future... follow the instructions and, yes, you need to connect jumper wires from MEGA (50,51,52) for it to work.

I'm new to the Arduino and have a Mega 1280 version and was working with the ethernet shield. It is working without any wiring changes and I'm using the 021 version with the above chip/board selected. I did have some problems but they come from the default assumptions in the library for gateway being at your private ip addess .001 (eg 192.168.100.1) and I found the pin assignments in the file pins_ardinuo.h beginning at line 52. This include file is included by STI.h.

Thanks for the notes and documentation they help understand what is going on.

You really got it to work by just putting it on the Mega and not changing any wiring or any files under 0021? I cannot seem to get mine to work just putting the shield on the Mega. I have a wiznet shield.

Hey AZ... The ethernet shield I am using is labeled Arduino EtherShield SD from Sparkfun Oct 2010 and near the microSD connector is 'MEGA compatible'. It works with the simple server software for a while and then I get a connection refused error. Studying this problem shows the Max connections on the EtherShield is 4 and when they are all used up then new connections are refused. This happens easily since from what I can tell the EtherShield sends data one byte at a time inside a 60 byte packet. I started looking at packets with wireshark and was surprised at all the activity I'm seeing so I started reading about socket programming and it's taking some hours of time so far. I turned on the auto notification of replies for this topic

I have the Ethernet shield and Mega 1280 on Arduino version 21 and the above hacks did not work for me.
Instead I used the recommendation of davekw7x to redirect pins 11, 12 and 13 but leave 10 as-is. And no modification to the sources required. See the good discussion thread at cgi-bin/yabb2/YaBB.pl?num=1284605439/6 for why pin 10 is left as-is.