Arduino based Webserver (ATMEGA328 + ENC28j60)
Replaced : static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01}; with new value.
As I built a Arduino Pro clone based development board running with 3.3V, I thought to give it a try with my Ethernet module for testing. This is an example for 3.3V LVTTL system. If you use this ENC28J60 on a 5V system,you may have to use logic level convertors.
Ethernet module:
Based on Microchip’s ENC28J60 chip. I’m using a board made by Sure electronics (really good manufacture) called MB-CM14111. I got this 2 years back from ebay for $10. You can now find cheap boards on ebay and do an ebay search as “enc28j60”. ENC28J60 is a SPI device and needed to be connected to ATMEGA328’s SPI module.
Arduino Board:
I’m using my Techduino Pro board which I build on an earlier post along with the my modified CP2102 USB to UART board.
Connections:
I connected the two boards as follows to establish a SPI link between two;
Ethernet Module | Techduino |
3.3V | 3.3V |
GND | GND |
DI | Pin 11 |
DO | Pin 12 |
CLK | Pin 13 |
CS | Pin 10 |
Software Library:
I used EtherCard Arduino library from JCW’s GIT repository. See here for downloads and installation instructions. You just have to download the zip file and extract it to your Arduino’s library folder(in my case arduino-1.0.3\libraries) and rename it to EtherCard.
Code:
I used a very basic code just to serve a static page from the webserver. You can find many more detailed information on using this library from LUCA’s ENC28J60 tutorials.This is the code I used. You just have to copy this code to Arduino IDE and compile it and upload.Modify myip[] ass you wish.This is the device’s IP address.The library also supports DHCP but here I’m using a static IP for the simplicity.I also omitted the standard HTTP requests/replies on this code for the simplicity.
#include <EtherCard.h> static byte mymac[] = {0xDE,0xDD,0xDD,0x00,0x00,0x01}; static byte myip[] = {192,168,1,10}; byte Ethernet::buffer[700]; void setup () { ether.begin(sizeof Ethernet::buffer, mymac,10); ether.staticSetup(myip); } void loop() { word len = ether.packetReceive(); word pos = ether.packetLoop(len); if(pos) { BufferFiller bfill = ether.tcpOffset(); bfill.emit_p(PSTR("<h1>hello</h1>")); ether.httpServerReply(bfill.position()); } } |
I connected the Ethernet module to my gigabit Ethernet card using a straight cable (my card auto detects straight or crossover connection).I set my PC’s address to be 192.168.1.1 manually. Then I tried a ping test to the Ethernet module by “ping 192.168.1.10” on command prompt. It was a success in first round.
Then I opened my browser and visited http://192.168.1.10 , TaDa!!!! The web page is working
I did a simple packet tracking using WireShark too. Just to see what’s happening there. You can see how the ping requests and replies going through the network.
Comments