Go Down

Topic: Arduino Nano + Ethernet shield ENC28J60 (Read 16612 times) previous topic - next topic

peter1a

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..

ballscrewbob

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.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

knut_ny

find the 'add on' for the chip. Then the examples  will 'come to life'.

(the enc... chip is a litte trickey)
Ny

peter1a

I'm using this library https://github.com/jcw/ethercard.

ballscrewbob

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.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

peter1a

It's wired:
SO - D12
SCK - D13
RST - RST
GND - GND
VCC - 3.3V
CS - D10
SI - D11

peter1a

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/

ballscrewbob

#7
Jun 16, 2017, 10:18 pm Last Edit: Jun 16, 2017, 10:19 pm by ballscrewbob
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.





If you need screen caps of it working I have no issues.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

peter1a

Can you tell me which libary are you using?
As i can see you are not using Ethernet shield ENC28J60, correct?

ballscrewbob

#9
Jun 16, 2017, 11:49 pm Last Edit: Jun 16, 2017, 11:50 pm by ballscrewbob
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
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

ballscrewbob

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.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

ballscrewbob

#11
Jun 17, 2017, 12:12 am Last Edit: Jun 17, 2017, 12:53 am by ballscrewbob
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");
  }
}
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

peter1a

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.

ballscrewbob

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.


It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

peter1a

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.

Go Up