etherShield icon indicating copy to clipboard operation
etherShield copied to clipboard

Library with example code for the nuelectronics Arduino EtherShield (ethernet shield)

etherShield Library for Arduino

This library provides Arduino support for the EtherShield from nuelectronics as well as other boards based on the same design.

Compatible boards include:

  • nuelectronics Ethernet Shield http://www.nuelectronics.com/estore/index.php?main_page=product_info&cPath=1&products_id=4

  • Seeed Studios Ethernet Adaptor http://www.seeedstudio.com/depot/ethernet-adapter-for-mcu-projects-p-160.html

Installation

The etherShield library can be downloaded from:

http://www.nuelectronics.com/download/projects/etherShield.zip

Updated versions of the library can also be obtained from github:

http://github.com/jonoxer/etherShield/tree/master

Unzip the library in your Arduino IDE library directory inside the hardware directory of your Arduino installation. For example:

arduino-0015/hardware/libraries/

There are six examples in the etherShield library. You may need to change the IP address in the example sketch (.pde) files to an available address within your network range. Each example sketch begins with network configuration values similar to:

static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24}; static uint8_t myip[4] = {192,168,1,15}; static char baseurl[] = "http://192.168.1.15/";

You may also like to change the webpage contents in the print_webpage function. Note that webpage contents are stored in the PROGMEM (using the PSTR declaration) to save precious SRAM space.

Library Structure

The library is based on tuxgraphics.org's TCP/IP stack for the Atmega88 and ENC28J60. The main files in the library are:

etherShield.cpp Wrapper cpp file, as an Arduino library interface for tuxgraphic's code

ip_arp_udp_tcp.c Simplified TCP/IP stack implementation

enc28j60.c ENC28J60 SPI routines

net.h Network protocol definitions

TCP/IP Implementation

The TCP standard is a protocol to establish a connection. To do this, a number of packets needs to be exchaged between two sides first to establish the connection; then data packets can be exchanged. Usually a complicated state-machine is needed to implement the full TCP protocol.

For Arduino's ATMEGA168, an 8-bit AVR microcontroller with only 1K SRAM, it is impossible to implement the full TCP stack. However, a webpage to control a relay or read a temperature sensor etc, is very simple. Therefore, instead of implementing the full TCP protocol a single data packet TCP protocol is used. Your webpage contents, including all HTML tags, must fit within a single packet. The length of packet is limited by the SRAM size. Currently half of the RAM space (500 bytes) is used for the network packet buffer which is sufficient for simple webpages as shown in the included examples.