Introduction:
In this article, we will learn how to Interface ENC28J60 Ethernet Module with Arduino Webserver to establish communication between computer to Arduino in a LAN or Wireless Network. We are interfacing the ENC28J60 Ethernet controller to Arduino so that our Arduino will be the one of a member of that network.
Once it will be done the Arduino can control things in that network or the Arduino can be controlled by the other devices of that network. To Interface ENC28J60 Ethernet Module with Arduino will further give us the freedom of using the internet on Arduino.
You can check this post as well: Control LED on Inernet using Arduino & ENC28J60 Ethernet Module
ENC28J60 Ethernet Module:
Introduction to ENC28J60:
The ENC28J60 Ethernet Module utilizes the Microchip ENC28J60 Stand-Alone Ethernet Controller IC featuring a host of features to handle most of the network protocol requirements. The board connects directly to most microcontrollers with a standard SPI interface with a transfer speed of up to 20MHz.
This Ethernet Breakout-Module is the simplest way to add LAN connectivity to your microcontroller-based products and projects.
- Use this module to enable an Ethernet interface for your product. It works with any microcontroller operating at 3. 3V or 5V.
- This module works at 3.3V and is compatible with 5V interface lines.
- Use the SPI process to interface with it.
- Host web server, ping the module, or add it to home automation via the internet.
- The heart of this module is the ENC28J60 Ethernet controller from Microchip.
- The use of RJ45 with Integrated magnetics has made it possible to reduce the size of the board.
Features:
- Ethernet LAN Module for Arduino/AVR/LPC/STM3
- ENC28J60 Ethernet chips
- Can be easily mounted with the MCU
- Network Interface: HR911105A
- Supply Voltage: 3.3 V (5V Tolerant DIO)
- 25Mhz crystal oscillator
- Size (L x W x H): Approx. 2.3 x 1.3 x 0.7 inch / 58 x 34 x 17 mm
Block Diagram & Connections:
This is the simple block diagram that explains how an Arduino & ENC28J60 module can be interfaced with Router and Computer.
The Router should be connected with LAN and should have multiple input-output ports. From the router, one ethernet cable is connected to Computer System and another ethernet cable should be connected to the ENC28J60 Module. Similarly, the ENC28J60 Module is connected to Arduino. The connection between Arduino & ENC28J60 is given below.
How to Interface ENC28J60 Ethernet Module with Arduino Webserver:
- Download the Library for ENC28J60 from here: ENC28J60 Library
-
Add the library files to your Arduino IDE library:
- Open Examples and choose the exapmple from Ethernet Master Library:
- Compile & then upload the code to Arduino UNO Board:
-
Open Serial Monitor and copy the IP address:
- Open google chrome or any other web browser and paste the IP address and hit enter:
Sample Code to Interface ENC28J60 Ethernet Module with Arduino:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#include <EtherCard.h> #define STATIC 0 // set to 1 to disable DHCP (adjust myip/gwip values below) #if STATIC // ethernet interface ip address static byte myip[] = { 192,168,1,200 }; // gateway ip address static byte gwip[] = { 192,168,1,1 }; #endif // ethernet mac address – must be unique on your network static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; byte Ethernet::buffer[500]; // tcp/ip send and receive buffer const char page[] PROGMEM = “HTTP/1.0 503 Service Unavailable\r\n” “Content-Type: text/html\r\n” “Retry-After: 600\r\n” “\r\n” “<html>” “<head><title>” “Service Temporarily Unavailable” “</title></head>” “<body>” “<h3>This service is currently unavailable</h3>” “<p><em>” “The main server is currently off-line.<br />” “Please try again later.” “</em></p>” “</body>” “</html>” ; void setup(){ Serial.begin(57600); Serial.println(“\n[backSoon]”); if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) Serial.println( “Failed to access Ethernet controller”); #if STATIC ether.staticSetup(myip, gwip); #else if (!ether.dhcpSetup()) Serial.println(“DHCP failed”); #endif ether.printIp(“IP: “, ether.myip); ether.printIp(“GW: “, ether.gwip); ether.printIp(“DNS: “, ether.dnsip); } void loop(){ // wait for an incoming TCP packet, but ignore its contents if (ether.packetLoop(ether.packetReceive())) { memcpy_P(ether.tcpOffset(), page, sizeof page); ether.httpServerReply(sizeof page – 1); } } |
3 Comments
When I connect the circuit, load the example “backSoone”. It does not work !
After I search the begin function of EtherCard class, it uses default SS pin (pin 10). After I connect pin 10 to CS of ENC28J60 module. It works !!!
Please update the connection diagram .
No getting the required output,it stucks in loop.and also no ip change
yes that fix help, thank you for sharing .!