Arduino not taking the IP Address

Hey guys I’ve got an ethernet problem on my arduino’s

Hardware :

I’ve try the these combinaisons (Uno + Arduino shield | Uno + Neuftech shield | Zero + Arduino shield | Zero + Neuftech shield) with or without SD and external supply.

I use a router without DHCP, and several ethernet cable. I’m on MAC OS 10.11 El Captain and Arduino 1.6.5

Here is my code :

#include <SPI.h>
#include <Ethernet.h>

/Déclarations des define/
#define W5200_CS 10 //PIN utilisé par la communication ethernet
#define SDCARD_CS 4 //PIN utilisé par la communication avec la carte SD

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

IPAddress ip = (192, 168, 0, 9);

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) ;

pinMode(W5200_CS, OUTPUT);
digitalWrite(W5200_CS, HIGH);

// On inhibe la carte SD
digitalWrite(SDCARD_CS, HIGH);
Serial.println (“Launch Ok”);

Ethernet.begin(mac, ip);
Serial.println (“Ethernet Ok”);

//print your local IP address:
Serial.print(“My IP address: “);
for (byte thisByte = 0; thisByte < 4; thisByte++) {
//print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(”.”);
}
Serial.println();
}

void loop() {

}

I always get My IP address : 9.0.0.0 and I can’t figure why.

I think you should change

IPAddress ip = (192, 168, 0, 9);
// to
IPAddress ip(192, 168, 0, 9);

The IP-address is printed backwards (in your code), so it would be better to use

for (byte thisByte = 3; thisByte >=0; thisByte--) {

Whandall: The IP-address is printed backwards (in your code), so it would be better to use

for (byte thisByte = 3; thisByte >=0; thisByte--) {

that loop will fail as thisByte will always be >= 0 --> byte is unsigned

loop should be

for (byte thisByte = 4; thisByte-- > 0; ) {

pyrotecnix: - Ethernet Shield from Arduino : http://www.arduino.org/products/shields/5-arduino-shields/arduino-ethernet-shield-2 - Ethernet Shield from Neuftech : http://amzn.to/1iL1vz7

The Neuftech shield uses W5100 which is compatible with the Arduino Ethernet library but the Ethernet Shield 2 uses the W5500 Ethernet Controller which is not compatible with the Ethernet library. To use it you will need to install an Ethernet library that supports it. Here are some options:

https://github.com/Wiznet/WIZ_Ethernet_Library - This library will support the W5500 or the W5100 but you need to edit the library to configure it for which one(it defaults to W5500).

https://github.com/per1234/EthernetMod/tree/W5x00 - This library supports both W5500 and W5100 and it automatically detects which is being used.

As for Arduino Zero support I'm not sure if those libraries will work or not.

pyrotecnix:

  //print your local IP address:

Serial.print(“My IP address: “);
 for (byte thisByte = 0; thisByte < 4; thisByte++) {
 //print the value of each byte of the IP address:
   Serial.print(Ethernet.localIP()[thisByte], DEC);
   Serial.print(”.”);
 }
 Serial.println();

There’s no need to do all that, you can just do:

Serial.println(Ethernet.localIP());

Two pieces of IP test code. The first checks if a DHCP IP address is assigned and displays it in the serial monitor. The second assigns an IP address and checks to see if it is assigned.

DHCP

//open serial monitor to see assigned IP address

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

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

  // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.println("Starting w5100...");
  if(!Ethernet.begin(mac)) Serial.println("failed");
  else Serial.println(Ethernet.localIP());
}

void loop() {

}

assigned IP

#include <SPI.h>
#include <Ethernet.h>

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

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

  // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);

  Serial.println(Ethernet.localIP());
}

void loop() {
}

Thank you guys, it works !

IPAddress ip = (192, 168, 0, 9); // to IPAddress ip(192, 168, 0, 9);

Now I'am trying to disable the SD card on Arduino Zero

This should disable the SD card.

digitalWrite(4,HIGH);