Arduino Ethernet Shield Not Assigning Correct IP Address - arduino

I've purchased two of the Arduino Ethernet Shields made by Arduino. I am using the Arduino Uno for my project. I cannot seem to assign an IP address to the shield. When I run the following code I receive 0.253.253.253 as the IP for one of the shields, and for the other one I receive 0.15.15.15 with the exact same code. I have no Idea what's going on here. Any help would be appreciated. Thanks
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x30, 0x71 };
IPAddress ip(192,168,1,22);
void setup() {
Serial.begin(9600);
// disable SD card if one in the slot
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
delay(5000);
Serial.println("Starting w5100");
Ethernet.begin(mac, ip);
Serial.println(Ethernet.localIP());
}
void loop() {
}

If both the boards are connected on the same network then they can't have the same IP address, change the address of one of the boards.
edit :
Check if it is indeed starting up properly
if(!Ethernet.begin(mac, ip))
Serial.println("failed");
else
Serial.println(Ethernet.localIp());
Also try it without the ip, to check if your router can assign the ip address.

Related

RFID does not respond after Ethernet.begin(mac, ip) initialization

Good day, I have this problem with my simple project. I have a database with all RFID number of employee. What I want to do is to use an rfID to check if it is registered in the database. If it is, it would return a value of 1 else would be a value of 0.
I tried with arduino HanRun Ethernet shield. I was able to get a response from the php web server to the serial monitor. Tried the seeedrfid it successfully get the rfcard number. However, when i tried to combine the two, it would hang on Ethernet.begin(mac, ip) initialization. My code is below.
#include <Ethernet.h>
#include <SoftwareSerial.h>
#include <SeeedRFID.h>
#define RFID_RX_PIN 10
#define RFID_TX_PIN 11
SeeedRFID RFID(RFID_RX_PIN, RFID_TX_PIN);
char state = '0';
char c;
byte mac[] = {0x60, 0xF8, 0x1D, 0xBA, 0x1D, 0x52};
IPAddress ip(192, 168, 20, 228);
EthernetClient client;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Serial set up");
Ethernet.begin(mac, ip);
Serial.print("My IP Address: ");
Serial.println(Ethernet.localIP());
}
void loop() {
long rfID;
// put your main code here, to run repeatedly:
if (RFID.isAvailable()) {
rfID = RFID.cardNumber();
Serial.println(rfID);
}
}
Serial.println(rfID) is not executed unless I remove the Ethernet.begin(mac, ip). Can anybody point me to the right direction?
Thank you everyone for helping out. My supervisor who gave me the shield just remembered that there might be a pin changes(or anything you call it). That I might need to try other pin in order for the rf reader and ethernet shield to work together. now its working fine..

Arduino Ethernet Shield 2 not working

I am currently trying to get the Ethernet Shield working on my Mega. I was trying to run the Webserver example but the program seems to stuck at one point, so I tried to start from scratch.
This is my test code:
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0F, 0xF6, 0x3D
};
byte subnet[] = { 255,0,0,0 };
byte gateway[] = { 2,0,0,1 };
IPAddress ip(2, 0, 0, 1);
EthernetServer server(80);
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip, gateway, subnet);
Serial.println("Ethernet started");
server.begin();
Serial.println("Server started");
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Loop");
}
The output I get from the serial console is:
Etrted
Ethernet started
So I think the program gets stuck inside the EthernetServer::begin() function.
I am aware that there are earlier versions of ethernet shields which are not compatible to the mega, but the vendor of my shield says it is.
Also I don't understand, why it outputs the first line.
Thanks for your hints!
Arduino.cc and Arduino.org are not the same... Arduino.org, who is selling the ethernet shield 2, has their own IDE with the correct library! You can download it at http://www.arduino.org/downloads and the source can be found at https://github.com/arduino-org/Arduino/tree/1.7.4/libraries
Try this code form (http://www.arduino.cc/en/Tutorial/DhcpAddressPrinter):
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// 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() {
}
And post what the serial monitor output is.
Try this:
NB. You can reuse your code written for Arduino Ethernet Shield, simply replacing
#include <Ethernet.h> --> #include <Ethernet2.h>
#include <EthernetUdp.h> --> #include <EthernetUdp2.h>
See this: http://labs.arduino.org/Arduino+Ethernet+Shield+2

Arduino Ethernet Shield does not accept connections

I have been playing around with an arduino ethernet shield, trying to get basic examples to work, to no avail. Here is my setup:
The Arduino Mega 2560 is connected to the computer via usb and the ethernet shield is stacked upon it. I have tried many variations of the examples that come with the arduino software, and none seemed to work properly.After lots of debugging with wireshark, I figured that:
I can't use DHCP, because it just hangs at the Ethernet.begin(mac) call.
When I try with a static ip, the Ethernet.localIP() function returns 0.0.0.0. However, I can ping my device from my computer using the ip I have set and the device seems to receive and send packets properly.The problem now is that for some reason it drops the tcp connections.E.g here is the code I run that comes the closest to working:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,27);
IPAddress server(192,168,2,52);
EthernetClient client;
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("a");
delay(1000);
Serial.println("connecting...");
if (client.connect(server, 23)) {
Serial.println("connected");
}
else {
Serial.println("connection failed");
}
Serial.println(Ethernet.localIP());
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// as long as there are bytes in the serial queue,
// read them and send them out the socket if it's open:
while (Serial.available() > 0) {
char inChar = Serial.read();
if (client.connected()) {
client.print(inChar);
}
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing:
while(true);
}
}
Its basically the Ethernet/TelnetClient example.
I have set up a telnet server on my computer. Now this is the arduino/computer exchange:
The arduino sends a RST packet, but my server goes on to send it the greeting and login prompt.
I have tried the same with an arduino uno, and have also tried disconnecting the usb and using another power supply.
So, what could be the issue?
The problem is in the connection to the shield, sometimes this shield if it is chinese version, It might have small short-circuit.
I tried disconnect the shield and connect with wire as like as arduino website indicate for arduino uno (the connections with arduino mega aren't correct, so you need connect like arduino uno)
If it don't work , try change the arduino shield. I have a similar problem with the same shield , and normally the problem is the connection to the arduino.
The example should work if the arduino is correctly connected
Strangely, I found that Ethernet fails to initialize if an SD card is inserted and not initialized. So, either take the SD card out, or initialize the SD card:
Sd2Card card;
card.init(speed, pinSelect);
I have some Chinese (SunFounder) version of Ethernet Shield, so it might not be relevant to cards from other manufacturers.

Arduino ethernet shield make a get request but no response

I would like my arduino to send a get request to a uri I have on my local network. I can open a browser and manually paste the request in and it works. I have also made the same request on a webpage using jQuery again no problem.
I have followed the tutorials for the Arduino and I can't see what I am doing wrong if some could help would be very grateful.
#include <SPI.h>
#include <Ethernet.h>
// 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 server(192,168,0,34);
// Set the static IP address
IPAddress ip(192,168,0,177);
// Initialize the Ethernet client library
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
Ethernet.begin(mac, ip);
// give the Ethernet shield a second to initialize:
delay(1000);
}
void loop()
{
Serial.println("connecting...");
if (client.connect(server, 81)) {
Serial.println("connected");
client.print("GET /tenHsServer/tenHsServer.aspx?t=ab&f=ToggleDevice&d=");
client.print("E3");
client.println(" HTTP/1.1");
client.println("Host: 192.168.0.34");
client.println(""); //mandatory blank line
}
}
For this kind of issue you should learn about web debbugging tools. My favourite is fiddler2. However it is only available for windows. For other plattforms search the net for http debug proxy. Besides that there is always wireshark or ncat.
Once you have such a tool in place just have a look at the generated traffic and compare it with traffic that actually worked. This usually allows to pinpoint the issue rather quickly.

My Arduino + Ethernet shield WebServer sketch sometimes fails to connect to the client. Causes?

My Arduino web server sketch sporadically fails on:
EthernetClient client = server.available();
if (client)
This morning, it connected just fine on the first run. Now, it can't connect to the client again. A couple of days ago, it worked several times, but failed several time as well. I have the shield connected via an Ethernet cable to my home router. I've verified the IP address assigned to the Arduino. I've tried ports 80 and 8080. What could be going wrong and what else can I try? Could my ISP be blocking something here? Please don't be afraid to suggest the obvious, since I know almost nothing about networks.
If relevant, here is a larger piece of the code, which loops on
Serial.println("Listening");
Code:
#include <SPI.h>
#include <Ethernet.h>n
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xF7, 0x99 };
IPAddress ip(192,168,2,5);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
String roundOpenTag = "";
String roundCloseTag = "";
void setup()
{
// Start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
int ledPin = 8;
// Initialize the digital pin as an output.
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("Setting up");
}
void loop()
{
// Listen for incoming clients
EthernetClient client = server.available();
Serial.println("Listening");
if (client)
{
Serial.println("Server available");
// An HTTP request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
Serial.println("Client connected");
if (client.available())
{
char c = client.read();
I don't see the purpose in including the rest of the sketch. I really appreciate your help.
You have a empty Seiral.begin() in your setup() function. Try removing it.
Edit:
When you call Serial.begin() you have to provide the baut rate(speed) at which you want to communicate. You can read more about the function at Arduino library page.
You had two problems in your code
You had a empty Serial.begin() function call, without any parameter
You had duplicate Serial.begin() function. You had already specified it in the beginning of the setup() function.

Resources