I am just starting with a ENC28J60 on my Nano and I am not getting any indication that the Ethernet is doing ANYTHING.
I installed the library arduino_uip from gethub and wired the ENC as shown on attached.
I have tried various of the Example programs and although the program loads and runs, there is no indication of activity from the ENC - the router says the port is down and shows no activity.
I have been reading for hours and only confused myself about WHICH library I should be using and IF my connections are correct.
(Yes, I know others prefer different Ethernet modules but I HAVE these and they are small enough to fit in my application.)
Can anybody see a problem with this arrangement? (Yes, I know others prefer different Ethernet modules but I HAVE these and they are small enough to fit in my application.)
/*
* UIPEthernet UdpClient example.
*
* UIPEthernet is a TCP/IP stack that can be used with a enc28j60 based
* Ethernet-shield.
*
* UIPEthernet uses the fine uIP stack by Adam Dunkels <adam@sics.se>
*
* -----------------
*
* This UdpClient example tries to send a packet via udp to 192.168.0.1
* on port 5000 every 5 seconds. After successfully sending the packet it
* waits for up to 5 seconds for a response on the local port that has been
* implicitly opened when sending the packet.
*
* Copyright (C) 2013 by Norbert Truchsess (norbert.truchsess@t-online.de)
*/
#include <UIPEthernet.h>
EthernetUDP udp;
unsigned long next;
void setup() {
Serial.begin(9600);
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
Ethernet.begin(mac,IPAddress(10,0,199,5)); // revised to my network
next = millis()+5000;
}
void loop() {
int success;
int len = 0;
if (((signed long)(millis()-next))>0)
{
do
{
success = udp.beginPacket(IPAddress(10,0,199,10),5000);
Serial.print("beginPacket: ");
Serial.println(success ? "success" : "failed");
//beginPacket fails if remote ethaddr is unknown. In this case an
//arp-request is send out first and beginPacket succeeds as soon
//the arp-response is received.
}
while (!success && ((signed long)(millis()-next))<0);
if (!success )
goto stop;
success = udp.write("hello world from arduino");
Serial.print("bytes written: ");
Serial.println(success);
success = udp.endPacket();
Serial.print("endPacket: ");
Serial.println(success ? "success" : "failed");
do
{
//check for new udp-packet:
success = udp.parsePacket();
}
while (!success && ((signed long)(millis()-next))<0);
if (!success )
goto stop;
Serial.print("received: '");
do
{
int c = udp.read();
Serial.write(c);
len++;
}
while ((success = udp.available())>0);
Serial.print("', ");
Serial.print(len);
Serial.println(" bytes");
//finish reading this packet:
udp.flush();
stop:
udp.stop();
next = millis()+5000;
}
}
The library you're using should be fine. I've used it successfully with ENC28J60. The other popular one is called ethercard but I like UIPEthernet AKA arduino_uip because it has the same API as the Ethernet libraries. This means you can usually use code written for the Ethernet library by just changing the include file name. That also means if you decide you want to use a W5x00 eventually you'll be able to easily make the switch.
Your wiring chart shows the ENC28J60 VCC pin connected to the Nano's 3V3 or 5V pin, which is it?
is meant to be powered only at 3.3V. There are some modules that have a voltage regulator and can be switched between 3.3V/5V but I don't think that's the case with yours. The ENC28J60 is 5V I/O tolerant so your SPI lines running at 5V is fine but I'm nervous about you running the chip at 5V because that's definitely outside the specs. The problem may be that the 3.3V supply doesn't support the current requirements of the ENC28J60, shown in the datasheet as 180 mA max but I'm guessing the LEDs increase that a little. The original Nano used the FT232RL chip, which can only supply 50 mA max from the 3V3OUT pin. The clone Nanos that are most commonly used now use the CH340 chip instead and I believe that is also the supply of the 3.3V pin but I haven't ever seen an official figure on what the current limit is on that chip.
My ENC28J60 is sold by Sunfounder and they do specify 3.3v
I will scope the 3.3v line later and see if there is any sag/noise during Tx/Rx. It there is, I will have to provide a different/beefier 3.3v supply and see if the ENC operates properly on that.
OK, I was referencing the link from your other post, it sounds like you ended up buying a different one. The ENC28J60 specifications are the same either way but I don't know how your module is configured. Are you using the Nano clone with CH340? The documentation for that chip is very lacking but I found some interesting information here: http://actrl.cz/blog/index.php/2016/arduino-nano-ch340-schematics-and-details/
The CH340 chip includes the 3.3 V LDO voltage regulator, which can supply up to 25 mA. There is no refence in the original CH340 datasheet or elswhere on the internet, so I measured the supplied 3V3 voltage directly.
With no load, the 3V3 pin voltage was 3.28 V. With load up to 25 mA the voltage dropped to 3.18-3.22 V (on different boards); however at 30 mA load the voltage dropped to 3.10 V and further to 2.85 V at 40 mA.
The ENC28J60 says the minimum supply voltage is 3.10 V so if the information on that page is correct the Nano's 3.3V pin is not able to supply the 180 mA. So the solution may be to add a 3.3 V voltage regulator to your project.
My raw supply is going to be 12 volt from lead-acid batteries so I was providing a 5V regulator anyway so I will just add a 3.3v as well. The 3.3v regulator is rated at 800mA so that should do.