hey,
i use http://jeelabs.net/projects/cafe/wiki/EtherCard and work well
more info is in http://www.lucadentella.it/category/enc28j60-arduino/
i connect the enc28j60 to arduino-nano like this
-----------------------------------------------------
Interface Nano - ENC28J60 - SPI
- CLI / OUT - INT d03
- WOL - SO d12
d11 SI - SCK d13
d10 CS ChipSelect - RESET rst
3v3 VCC - GND gnd
-----------------------------------------------------
here some examples
------------------------------------------------------------------------------------------------------------------------
// ip from dhcp
//
#include <EtherCard.h>
static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01};
char website[] PROGMEM = "google.com";
byte Ethernet::buffer[700];
void setup () {
Serial.begin(57600);
Serial.println("DHCP Demo");
if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
Serial.println( "Failed to access Ethernet controller");
else
Serial.println("Ethernet controller initialized");
if (!ether.dhcpSetup())
Serial.println("Failed to get configuration from DHCP");
else
Serial.println("DHCP configuration done");
ether.printIp("IP Address:\t", ether.myip);
ether.printIp("Netmask:\t", ether.mymask);
ether.printIp("Gateway:\t", ether.gwip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
Serial.print("google.com"); ether.printIp(" SRV: ", ether.hisip);
Serial.println("------------------------");
}
void loop() {
ether.packetLoop(ether.packetReceive());
}
------------------------------------------------------------------------------------------------------------------------
// Ping a remote server, also uses DHCP and DNS. (1)
// 2011-06-12 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
static uint32_t timer;
// called when a ping comes in (replies to it are automatic)
static void gotPinged (byte* ptr) {
ether.printIp(">>> ping from: ", ptr);
}
void setup () {
Serial.begin(57600);
Serial.println("\n[pings]");
if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
#if 1
// use DNS to locate the IP address we want to ping
if (!ether.dnsLookup(PSTR("www.google.com")))
Serial.println("DNS failed");
#else
ether.parseIp(ether.hisip, "74.125.77.99");
#endif
ether.printIp("SRV: ", ether.hisip);
// call this to report others pinging us
ether.registerPingCallback(gotPinged);
timer = -9999999; // start timing out right away
Serial.println();
}
void loop () {
word len = ether.packetReceive(); // go receive new packets
word pos = ether.packetLoop(len); // respond to incoming pings
// report whenever a reply to our outgoing ping comes back
if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip)) {
Serial.print(" ");
Serial.print((micros() - timer) * 0.001, 3);
Serial.println(" ms");
}
// ping a remote server once every few seconds
if (micros() - timer >= 5000000) {
ether.printIp("Pinging: ", ether.hisip);
timer = micros();
ether.clientIcmpRequest(ether.hisip);
}
}
------------------------------------------------------------------------------------------------------------------------
// Ping a remote server, (2)
// 2011-06-12 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
//
#include <EtherCard.h>
static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x00};
static byte myip[] = {192,168,1,15};
// static byte staticmask[] = {255,255,255,128};
// ether.copyIp(mymask, staticmask);
byte Ethernet::buffer[700];
void setup () {
Serial.begin(57600);
Serial.println("PING Demo");
if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.staticSetup(myip))
Serial.println("Failed to set IP address");
}
void loop() {
ether.packetLoop(ether.packetReceive());
}
------------------------------------------------------------------------------------------------------------------------
// Simple demo for feeding some random data to Pachube.
// 2011-07-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
// change these settings to match your own setup
#define FEED "use yours"
#define APIKEY "use yours"
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
char website[] PROGMEM = "api.pachube.com";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
void setup () {
Serial.begin(57600);
Serial.println("\n[webClient]");
if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("api.pachube.com SRV: ", ether.hisip);
Serial.println("------------------------- ---------");
}
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 10000;
// generate two fake values as payload - by using a separate stash,
// we can determine the size of the generated message ahead of time
byte sd = stash.create();
stash.print("0,");
stash.println((word) millis() / 123);
stash.print("1,");
stash.println((word) micros() / 456);
stash.save();
// generate the header with payload - note that the stash size is used,
// and that a "stash descriptor" is passed in as argument using "$H"
Stash::prepare(PSTR("PUT http://$F/v2/feeds/$F.csv HTTP/1.0" "\r\n"
"Host: $F" "\r\n"
"X-PachubeApiKey: $F" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
website, PSTR(FEED), website, PSTR(APIKEY), stash.size(), sd);
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
}
}
------------------------------------------------------------------------------------------------------------------------
best regards, pescadito