Tuesday, 7 October 2014

Ethernet(ENC28J60) Interfaced Arduino

In this Artical we will see how to establish communication between computer/mobile 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 member of that network. Once it will done the arduino can control things in that network or the arduino can be controlled by the other devices of that network it might be computer or mobile. Interfacing Arduino with the ENC28J60 will further gives us the freedom of using the internet on Arduino but before that we need to learn how to do all that networking stuff in a locan network.

Soon I will post about how to control the things in local network, how to send data on a local network, and how to interfaced with Android devices or how to make IOT Devices. IOT Devices are quite famous.
 

A simple block diagram of the data flow  is in the image below.


Ethernet Module( ENC28J60):  Microchip's ENC28J60 is a 28-pin,  Ethernet Controller with on board MAC & PHY, 8 Kbytes of Buffer RAM and an SPI serial interface. With a small foot print package size the ENC28J60 minimizes complexity, board space and cost. It used in so many application like Industrial Automation, Building Automation, Home Control, Security and Instrumentation, IOT Devices.
You can build Your own circuit but I use the Module to save my time.



VIRTUAL SIMULATION: I first simulate my design on the Proteus ISIS to make sure I am working in right direction and also to save my time. In ISIS their is already a component named "ENC28J60 ethernet controller" so I picked it from the library. Now I picked up the Arduino and connect it with the ethernet controller.


if the link dont work please comment

* Connections:   
  
Now make these connection in the ISIS design tool.


SOFTWARE: Now we all done with the Virtual Hardware Design lets make the software. All you need is the Ethercard Library for this example. Download it from here EtherCard. Click here
  • Extract the ZIP file , copy and paste the folder in your Arduino1.xx/library/  
  • once you place the folder in your arduino library folder restart your Arduino IDE
  • Now  go to ethercard > Examples > backsoon
 
 Compile the code  : if facing any problem then go to :  How To Simulate Arduino in ISIS

Make some changes in the program as given below
changes are in Red colour
Arduino code
/*#############################################################################
###############################################################################*/

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php

#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

// char page[] is the HTML page you are uploading ..
char page[] PROGMEM =
"HTTP/1.0 503 My Seriavice \r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "2embeddedrobotics "
  "</title></head>"
  "<body>"
    "<h3>Welcome to 2embeddedrobotics</h3>"
    "<p><em>"
      "The World of IOT Devices .<br />"
      "yipeee   Congrats...."
    "</em></p>"

   "</body>"
"</html>"
;

void setup(){
  Serial.begin(9600);
  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);
  }
}
/*##############################################################################
###############################################################################*/

now compile the code with prefrence compile. in file option.. so that you will get the .HEX file for ISIS.







Now you have done every thing . Hit the Play Button and it will give you the assigned IP address in serial monitor now write it down on a paper.

 
open the web browser and write the IP address of your arduino in the browser.
 

 Now you can watch this page on any device connected to that network  As I show.

HARDWARE: We already did everything in virtual now we just need to connet each component as per the connection given in starting.
Now upload the program to your Arduino and turn on its Serial monitor so that u can get Your 
"IP in Serial Monitor" and just open browser and put your IP and check the webpage.



Now you have done then note your IP from the serial monitor and Enjoy..
Wish you a very good Luck.
 
 

About the Author

Vikas Sharma

Author & Editor

Hobbyst Researcher and working in electronics domain, M.Tech in VLSI Design and Embedded Systems.

33 comments:

  1. when i try to run this project it says "writting to non-assigned register [0x41]=0x00 U1" to simulation log and "Failed to access Ethernet controller" to virtual terminal. Do you know why this error occurred?

    ReplyDelete
    Replies
    1. 3 question: 1> DID you connected a lan to your PC
      2> if so then edit properties of enc28j60 and check network card no
      3> if network card no is not in the edit properties of enc28j60 thenu need higher version of proteus i am using 7.8

      Delete
    2. I connected to wifi network. When i connected to a LAN you project work, Thank.

      Delete
    3. i have the same problem bro someone help me writting to non-assigned register [0x41]=0x00 U1

      Delete
  2. Hi Sir !
    I try to run your project on Proteus 7.10 and I edited MAC, IP and Gateway, choose card number in enc28j60.
    Connected to LAN cable.
    but when i run, Terminal only show : [backSoon].
    Please guide me sir !!Thanks you so much !!!
    [backSoon]

    ReplyDelete
    Replies
    1. when i run, Terminal only show : [backSoon].

      Delete
  3. Im running your project on Proteus 8 and I edited MAC, IP and Gateway, and I tried with all card numbers in ENC28J60.
    Connected to LAN cable.
    but when I run, Terminal only show : [backSoon].

    Could you please tell what´s wrong??

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. I tried this project but while running the serial monitor i found out letters and not any ip address at 9600 baud rate when i changed the baud rate to 57600 i got an indication of backsoon. I have a doubt on how to check whether ethernet is connected to the router or there is any indication on PC's device manager or in networking or there is some more configuration required. I found your project very interesting and thanks you in advance .Please kindly give me your reply.

    ReplyDelete
  6. I'm new and I hope somebody can help me. I got this erros in Isiss when I try to simulate de programe:

    Failed to initialize: WinPcap Drivers
    [SPICE]Error202: Too many iterations withoutconvergence

    ReplyDelete
  7. In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,
    from C:\Users\Alexandre Borges\Documents\Arduino\libraries\ethercard-master/EtherCard.h:28,
    from arduino_temp.ino:7:
    arduino_temp.ino:24:13: error: variable 'page' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
    Erro compilando.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  8. your blogs is awesome.
    V Music
    Now you can listen to your choice of songs wherever you go. Just subscriber to our V Music service and listen to more than 50 thousand songs. Enjoy latest filmy songs, private albums, regional songs and many more. So what are you waiting for, just follow any one step to subscribe:
    Dial 5606001 (toll free) from your Phone.
    Activate : Dial 5606001 (toll free) from your Phone. Deactivate Dial 155223 from your phone. Subscription Charges: Rs 30 for 30 Days to enjoy Music.

    ReplyDelete
  9. Hello sir, I got similar error on proteus 'virtual terminal' screen. It shows 'Failed to access Ethernet controller' by trying 'dev_hub_net.cpp.hex' file and also shows '[backSoon]' by trying 'backSoon.cpp.hex' file (or vice versa).
    You notice above that see enc28j60's card number, Network card number.
    What do you mean by this? I looked to enc28j60 in your arduino+ethernet circuit in proteus. On ISIS 'Edit Component' window, there is Network Card No: 1. Is it right? or what is its mean? There are card numbers: default,0,1,2,3,4,5.
    What does it do? which one must write there, why?
    I know question is a bit boring, so, we need your helpfulness, if you please. yours sincerely (from Turkey)... :-)

    ReplyDelete
  10. Hello!!! Excellent but I get this error i proteus: invalid opcode 0x9419 at PC=0x23D4 and failed to initialize WinPcap Drivers... as I do?

    ReplyDelete
  11. Hello visit your post, it is excellent, but some said that should change what is in red. I do not understand that part, you could tell, because that's the only thing missing for me to work, I do not check my ip address or anything in the simulation

    ReplyDelete
  12. I declared the page varibale const and tried
    I am getting "simulation not running in real time due to excessive cpu load"

    ReplyDelete
  13. How to connect a lan to PC to process this project in Proteus ? Thank you for your replying

    ReplyDelete
    Replies
    1. just connect your internet wire with your pc

      Delete
  14. Sir pls the code is not working and in the virtual screen it shows only backsoon and pls.. reply

    ReplyDelete
    Replies
    1. hi switch pin of cs from 10 to 8 or 8 to 10

      Delete
    2. Respected sir,
      Thanks for your immediate reply and presently the ip address is appearing on virtual terminal but the DNS is appearing as 0.0.0.0
      Thank you

      pls reply......

      Delete
  15. i could not find why DNS is 0.0.0.0 may be due to this the ip is not loading in browser any suggestion please

    ReplyDelete
  16. This is by far the most usefull post on this topic.

    Thanks for the tutorial

    ReplyDelete
  17. variable 'page' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
    how to solve this error?

    ReplyDelete
  18. hello sir,
    this link doesn't work with me
    * DOWNLOAD FULL PROJECT IN ZIP FILE CLICK HERE *

    ReplyDelete
  19. This was the time before the ESP8266 which now allows the arduino through wifi. And of course, NodeMCU which can be used as a standalone server using Arduino IDE.

    ReplyDelete
  20. i receive this error

    "Failed to initialize WinPcap Drivers"


    then what should i do?

    ReplyDelete
  21. https://suntos.com.np/avr/ENC28J60%20Ethernet%20Controller

    ReplyDelete

 
2embeddedrobotics © 2015 - Designed by Templateism.com