ENC28J60 + EtherCard.h + Arduino Nano = Fail [Solved!]

Hello Arduino Fellas,

I’m trying to play with an ENC28J60 module driven by the EtherCard.h library, plus an Arduino Nano, without any success at this point, having tried at least 10 examples from several websites, I will try to explain my current setup:

The ENC28J20 module is power feed from 4 alkaline batteries through an fixed 3.3Vdc regulator (ground connected in common with the Arduino_Nano); for assessing the ENC28J60’ current consumption I have inserted my DVM who is happy reporting 120.3 to 120.6 mA (I suppose the device should sink up 160 ~ 180 upon transmitting, so there is a hint), the Ethernet module is connected to a small 8 ports 10/100 switch and my PC to the same device using a couple of cables.

There is no other devices connected to the switch, the Ethernet port of my laptop is set to 192.168.1.100 and the Windows firewall (I believe!) has been turned off.

The ENC28J60 module is wired to my Nano as follows:

ENC28J60 Signal Arduino_Nano Pin
SCK Pin_13
CS Pin_8
SO Pin_12
SI Pin_11

I’m using this code example extracted from …libraries\EtherCard\examples\backSoon:

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl>
//
// License: GPLv2

#include <EtherCard.h>

#define STATIC 1  // 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 Unavailablern"
"Content-Type: text/htmlrn"
"Retry-After: 600rn"
"rn"
"<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.
"
      "Please try again later."
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(57600);
  Serial.println("n[backSoon]");

  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 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);
  }
}

This code compiles with no complains, as far as I understand, this code should show a simple web page on my PC browser, but the module seems sending nothing back to the network.

Hypothesis discarded:

  • Bad Ethernet cables: Tested both cables, Ok.
  • Ethernet Switch tested: Ok.
  • Not enough power to feed the ENC28J60 module: I have tested power feeding from Arduino_Nano pin 5VOut through the 3.3 Vreg (resulting on unstable 3.1v supply @ roughly 100mA); Ended power feeding with the battery pack as described above.

I suspect my module in not transmitting noting at all, for two reasons:
a) Current consumption, as I mentioned before.
b) The stat windows for my Ethernet adapter reports packets sent (as expected), but zero packets received.

Any suggestions, hints or whatsoever to solve this mystery are welcomed :slight_smile:

[

Did you set up the windows computer for a direct ethernet connection? what application on the windows computer are you using to communicate with the arduino? You might use the search function in the upper right of the page and search for the key words of your project.

Hello zoomkat, thanks for answering:

zoomkat:
Did you set up the windows computer for a direct ethernet connection?

Yes, I have setting my PC to static IP address. (See attached image).

zoomkat:
what application on the windows computer are you using to communicate with the arduino?

My default PC browser (Mozilla Firefox).

zoomkat:
You might use the search function in the upper right of the page and search for the key words of your project.

Thanks for the suggestion, I have tried this and tested several examples as I stated before.

1.png

Have you tried a direct connection without the switch? Can the switch be logged into like a router, or is it just hardware like an ethernet hub? Assuming the switch is functioning like a router with the gateway IP address of 192.168.1.1, can you see both devices in the client list?

zoomkat:
Have you tried a direct connection without the switch?

Actually it was my very first test, but getting no answer from the module so switched to the ethernet hub.

zoomkat:
Can the switch be logged into like a router, or is it just hardware like an ethernet hub? Assuming the switch is functioning like a router with the gateway IP address of 192.168.1.1, can you see both devices in the client list?

It's just a simple 8-port hardware like an ethernet hub as you pinpoint.

There is no management features on the device.

I'm getting suspicion on a faulty module, but unless I can check with another PC, I won't be sure.

You have a problem with your addressing.

As you don't use a router, the following must be done:
On the ENC28J60 side you has a fixed IP address, but your Gateway address must point to your PC IPaddress
On the PC side the Gateway must point to the ENC28J60 ip address.
The ip address 192.168.1.1 don't exist in your network. A hub or simple switch has no routing function.

Depending on your PC Ethernetcard, you may have to use a crossover cable.

What output do you have from the serial monitor?

/ffur

ffur:
You have a problem with your addressing.

As you don't use a router, the following must be done:
On the ENC28J60 side you has a fixed IP address, but your Gateway address must point to your PC IPaddress
On the PC side the Gateway must point to the ENC28J60 ip address.
The ip address 192.168.1.1 don't exist in your network. A hub or simple switch has no routing function.

Depending on your PC Ethernetcard, you may have to use a crossover cable.

What output do you have from the serial monitor?

/ffur

ffur:

I think I have more than addressing problems :frowning:

At this point, I have done the following tasks:

On my laptop, I've set Gw to IP: 192, 168, 1, 200

Set the IP parameters on the Arduino to:

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192, 168, 1, 200 };
// gateway ip address
static byte gwip[] = { 192, 168, 1, 100 };
#endif

Connecting module CS pin to Arduino_Nano pin D8 AND setting the code as follows seems to initialize the module (Green led stay light solid & Yellow flickers eventually).

  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)

Serial monitor only report "n[backSoon]" message upon module resetting, no more messages are reported.

Here comes the estange thing, moving CS to Arduino D10 pin, seems to not initializing the module, (no activity is reported from the RJ45 leds, both stay off all the times); serial monitor only report "n[backSoon]" message upon module resetting, with no further messages reported.

Inverting things (CS to D10) AND (ether.begin(sizeof Ethernet::buffer, mymac, 8) seems to initialize the module (Green led stay light solid & Yellow flickers), serial monitor remain the same upon module resetting.

In either case still no response from the web browser.

Should I switch to another library?

Try to define the csPin like in the example:

int csPin = 8; // Chip select pin
and

if (ether.begin(sizeof Ethernet::buffer, mymac, csPin) == 0)


From your PC, can you 'ping 192.168.1.200 ?


You do have a minor problem with the backslashes () in your sketch.

/ffur

ffur:
Try to define the csPin like in the example:

int csPin = 8; // Chip select pin
and

if (ether.begin(sizeof Ethernet::buffer, mymac, csPin) == 0)

Code as follows: (I’ve removed some blank lines for saving space on post).

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl>
//
// License: GPLv2
#include <EtherCard.h>
int csPin = 8;  // Chip select pin
#define STATIC 1  // 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, 100 };
#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.
"
  "Please try again later."
  "</em></p>"
  "</body>"
  "</html>"
  ;
void setup() {
  Serial.begin(57600);
  Serial.println("\n[backSoon]");
  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, csPin) == 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);
  }
}

ffur:

From your PC, can you 'ping 192.168.1.200 ?

Request timed out.

Ping statistics for 192.168.1.200:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss)

ffur:

You do have a minor problem with the backslashes () in your sketch.

/ffur

Corrected!

Have you tried a 'crossover' cable directly from the PC to the ENC module (Without the hub/switch)?
If the ENC module is initiated ok, you should be able to 'ping' the module.
I had an ENC module running on an UNO a year ago without any problem, but now I'm running out of ideas.
By the way is your ENC module a 3.3v or 5v. module?

/ffur

Sorry about the delayed reply...I have been very busy on my "real world, day-to-day job" :slight_smile:

ffur:
Have you tried a 'crossover' cable directly from the PC to the ENC module (Without the hub/switch)?

If the ENC module is initiated ok, you should be able to 'ping' the module.

Tried with no success.

Beyond the Link/Status leds, there is any way to know if the module has been initiated ok?

ffur:
I had an ENC module running on an UNO a year ago without any problem, but now I'm running out of ideas.
By the way is your ENC module a 3.3v or 5v. module?

/ffur

Mine is a 3.3v, now powered with a device similar to this: YwRobot Breadboard Power Supply
In next post a couple of pics of my module.

  1. Removed the module from circuit to take photos, inadvertently unplugged some wires from the protoboard.

  2. Take a handful of pics, to choose a couple.

  3. Decided re-wire all the circuit (still ugly anyway), but upon powering on SUCCESS!

See attached images, thanks you all for your suggestions.

Notes:
Ping test was done using a cross-over cable and using the hub, with the same results (1<ms).

Conclusion: Circuit wired poorly :fearful:

1Untitled.png

2Untitled.png

Super.
As I wrote, I was running out of ideas, but you got it up and running and ready for new projects.

Then please edit your first post. Add "[Solved]" to the subject line. Thanks.

/ffur

I was thinking about a faulty module, as sometimes occur with those chinese-cheapo-things.

ffur:
Super.
As I wrote, I was running out of ideas, but you got it up and running and ready for new projects.

Then please edit your first post. Add "[Solved]" to the subject line. Thanks.

/ffur

Done!