Ethernet shield W5100 - connection to Arduino

Ethernet shield W5100 - connection to Arduino

Daniil Zhuk

It is convenient to use the Internet to communicate with the outside world and transfer data in our modern time. With the advent of Wi-Fi modules, the task has become simpler and cheaper, but there is still meta, where there is no wireless network, it pollutes the frequency range or is simply inconvenient, but there is a network cable nearby. In this case, Ethernet Shield based on the W5100 will help us!

OVERVIEW OF W5100


The shield is designed to communicate the microcontroller with the local network and implements the physical layer of the interface. Connects to the Arduino SPI interface. Internet exchange speed is 10/100 Mb / s. Power supply - 5V.

In addition to the actual elements for communication with the network, there is a slot for a microSD memory card on the board (to simplify the organization of the memory for the web server).

The shield has the RESET button and service LEDs closed by it, including indicators of the wired interface. The shield is compatible with the Arduino Mega, as it uses the ICSP connector (programming connector) to connect.

Ethernet shield w5100
Please note - the standard pin 10 used to select the active device will be busy and for other devices, you will have to choose another pin to avoid conflict on the data lines. This is one of the most common mistakes, due to which many SPI devices do not work with Ethernet Shield.

CONNECTING TO ARDUINO IDE



The shield was developed by one of the first and became the de facto standard, therefore the library for working with it was included in the Arduino IDE package and it is simply called the Ethernet library.

To connect the shield to the Arduino, simply put it on the board (there may be problems with compatibility with the Arduino Leonardo)

Use high-quality network cables, because the equipment is a bit more fastidious about small things than computer network cables. For stable operation, it is desirable to provide a separate external power supply.

Open the environment and download the WebServer sample. Then connect the Arduino to the network and go to the IP address 192.168.1.177. It may surprise you, but you have just logged into your own server, just raised! And if you “forward” port 80 through the router to the outside, you can access it from anywhere in the world, which will allow you to remotely control the device or control it.

#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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "www.google.com"; // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);

// 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;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");

// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.1");
client.println("Host: www.google.com");
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}

void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}

// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();

// do nothing forevermore:
while (true);
}
}

A shield opens up a lot of room for creativity, and Arduino’s computational abilities are enough to ensure the operation of a small page with technical data.

Try changing the IP address of the Arduino or changing the content of the page (for this you will have to study a bit of HTML).

Add a comment

* Comments must be approved before being displayed.