Arduino Forum

Using Arduino => Installation & Troubleshooting => Topic started by: peter1a on Jun 16, 2017, 10:43 am

Title: Arduino Nano + Ethernet shield ENC28J60
Post by: peter1a on Jun 16, 2017, 10:43 am
Hy,

I am totally new into Arduino things. I buy couple of arduinos and those ethernet shields which would connect to internet and send some data to our API.
First problem is i can't get to work my ethernet shield, all the time i don't get any ip address. All wires are connected right, check it 10 times already also i use a lot of different libaries but no success at all.

Can someone help me little bit with it? Also try on other arduino nano, no success so there is no hardware corruption i guess..
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: ballscrewbob on Jun 16, 2017, 02:27 pm
Your "schematic" and "code" would be very useful as without it even a crystal ball is going to have issues deciding on an answer.

Also use code tags ( </> ) to post code.
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: knut_ny on Jun 16, 2017, 06:24 pm
find the 'add on' for the chip. Then the examples  will 'come to life'.

(the enc... chip is a litte trickey)
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: peter1a on Jun 16, 2017, 08:01 pm
I'm using this library https://github.com/jcw/ethercard.
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: ballscrewbob on Jun 16, 2017, 08:05 pm
Hmm getting 404 error for that link.

So if all else fails a schematic  of what you have hooked up and HOW ?
Hand drawn will be fine too.
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: peter1a on Jun 16, 2017, 08:15 pm
It's wired:
SO - D12
SCK - D13
RST - RST
GND - GND
VCC - 3.3V
CS - D10
SI - D11
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: peter1a on Jun 16, 2017, 09:41 pm
I am now using this code, i get IP local in Serial monitor, but can't ping this ip from my computer.
Here is my complete code with libary: http://www.himix.lt/arduino/arduino-nano-and-nano-ethernet-shield-using-uip-ethernet-library/
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: ballscrewbob on Jun 16, 2017, 10:18 pm
I have one of those NANO shields and just plugged it in.

The only change I made was to put the IP address onto my own subnet 192.168.0.115 and it works just fine.
Are you aware of networking protocols, IP ranges, Subnets, etc.

If not brushing up a little may be in order as the sketch you pointed at is perfect apart from the subnet IP.



(http://forum.arduino.cc/index.php?action=dlattach;topic=484062.0;attach=215664)

If you need screen caps of it working I have no issues.
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: peter1a on Jun 16, 2017, 11:43 pm
Can you tell me which libary are you using?
As i can see you are not using Ethernet shield ENC28J60, correct?
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: ballscrewbob on Jun 16, 2017, 11:49 pm
I "AM" using the Ethernet shield ENC28J60.

Using the standard UIPEthernet lib.

I can change to a different ethernet shield but you were pretty clear its the ENC28J60

This one to be precise (https://img.banggood.com/thumb/water/oaupload/banggood/images/4E/06/efd068ec-cad8-4a81-88d3-a99b1e6113d8.jpg)
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: ballscrewbob on Jun 16, 2017, 11:54 pm
Think at this point you should be posting pictures and proper schematics of your ACTUAL setup.
along with your ACTUAL code that you are trying to use if it is any way different from the one you gave us a link to.

There is a really nice thread HERE about how to do those things. (http://forum.arduino.cc/index.php?topic=148850.0)
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: ballscrewbob on Jun 17, 2017, 12:12 am
You might want to re-do that LOL

Code should come out like this.
Code: [Select]

// Watch video here: https://www.youtube.com/watch?v=M4mVDnlnzSA

// UIP is a proper library for Arduino Nano Ethernet shield
// NOTE: UIPEthernet library is not needed if you are using Arduino UNO/Duemilanove/Mega/etc.
// UIPEthernet library is used for Arduino Nano Ethernet Shield

#include <UIPEthernet.h> // Used for Ethernet

// **** ETHERNET SETTING ****
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xEE  };  
// Change the IP below to your subnet if you have any issues
//    IPAddress ip(192, 168, 0, 115);                                
IPAddress ip(192, 168, 1, 115);

                        
EthernetServer server(80);

void setup() {
  Serial.begin(9600);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();

  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();

  if (client)
  {  
    Serial.println("-> New Connection");

    // an http request ends with a blank line
    boolean currentLineIsBlank = true;

    while (client.connected())
    {
      if (client.available())
      {
        char c = client.read();

        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank)
        {
          client.println("<html><title>Hello World!</title><body><h3>Hello World!</h3></body>");
          break;
        }

        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r')
        {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }

    // give the web browser time to receive the data
    delay(10);

    // close the connection:
    client.stop();
    Serial.println("   Disconnected\n");
  }
}
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: peter1a on Jun 17, 2017, 12:16 am
I get output:

IP Address: 192.168.1.115
IP Address: 192.168.1.115


But when i try open this IP in browser doesn't open anything.
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: ballscrewbob on Jun 17, 2017, 12:30 am
What is your subnet IP range ?

Check the DHCP list in your router or if you are on windows open a command prompt and type "ipconfig /all"
Check the "Default gateway IP to get the range (normally 192,168,0.1) or if its a little older then it may actually be as you said and show 192.165.1.115.

Some of the nastier routers may also have ranges cut down too to under 100. but thats not too often.

Left you enough clues to get going and that it shows that IP (presumably in serial monitor) means the sketch ran fine so thats probably not the issue and chances are neither is your Ethernet module.

Really looks like it may be down to a lack of understanding about network basics.

But just to be sure some final thoughts.

1. Change the IP in your sketch (as already mentioned) to 192.168.0.115 (confirm that's in your subnet)
2. Turn off your computers security for a little while.
3. If you run Chrome as you browser open an INCOGNITO window with NO add ons.
   (other browsers usually have similar options)
4. try the new IP from step 1.


Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: peter1a on Jun 17, 2017, 01:05 am
This is now mu current code, i'm trying to send some data to some domain, when i check access log on domain of course nothing inside log from my Arduino IP, but i still receive in serial monitor:

ip-192.168.2.255
Subnet mask-255.255.255.0
Gateway-192.168.2.1ip-192.168.2.255
Subnet mask-255.255.255.0
Gateway-192.168.2.1
DNS-192.168.2.1
connected

disconnecting.
==================

My code:
Code: [Select]
#include <UIPEthernet.h>
#include <SPI.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 2, 255);

char serverName[] = "checking.tozdajdela.net"; // test web page server

EthernetClient client;
String data;
void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  Serial.print("ip-");
  Serial.println( Ethernet.localIP());
  Serial.print("Subnet mask-");
  Serial.println( Ethernet.subnetMask());
  Serial.print("Gateway-");
  Serial.println( Ethernet.gatewayIP());
  Serial.print("DNS-");
  Serial.println( Ethernet.dnsServerIP());
}

void loop() {
  sendGET(); // call sendGET function below when byte is an e
}

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET / HTTP/1.0"); //download text
    client.println("Host: checking.tozdajdela.net");
    client.println(); //end of get request
  }
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}



Also if i put out ethernet cable so, arduino doesn't have network this program keep saying that is connected/disconnected and it gives me same IP as before, that's really weird.
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: ballscrewbob on Jun 17, 2017, 01:46 am
LMAO about the last bit of your post and i'm sorry about that.

See the fourth line where it tells the dhcp what IP it wants to use.
Clearly its going to get that IP every time it wants it regardless of what you do with the cable unless you clear out all the tables.
Only reason it would not get that IP is if another device demanded it whilst yours was disconnected.


As for the sketch no spending a lot of time on it but a quick glance has me thinking there is something missing ?

I may play with it a little later

IS the "tozdajdela.net" supposed to put anything out ?
I get this if I open that page.
Code: [Select]

Your IP has been logged !



You are using: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36


Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: peter1a on Jun 17, 2017, 05:59 am
No matter which page i put i will always get same results, first it is connected and than it disconnected.
Also get same output if arduino isn't connected to ethernet cable at all..

I don't know what to do anymore i'm trying this module almost 2 days with no success, ok first succcess was i'm now getting some kind of local IP, but as i said this ip keeps getting no matter if i am connected or not. Anyway this ip doesn't use any other device.
Title: Re: Arduino Nano + Ethernet shield ENC28J60
Post by: blahop on Nov 29, 2019, 09:31 am
Hi @peter1a, how did you finally solve the issue?

I'm having a really similar problem here:  https://forum.arduino.cc/index.php?topic=650735.0 (https://forum.arduino.cc/index.php?topic=650735.0)

See you