I recently bought an Arduino Ethernet shield (Ethernet Shield WizNet W5100 R3 2012 for Arduino UNO Mega 2560 Duemilanove PoE) which I want to use with my Arduino Duemilanove ATMega 328. I connected my ethernet shield with my Arduino board and connect shield with my router using Ethernet cable.
Then I upload the following program to my Arduino board (I'm using IDE 1.0.6):
//IMPORT SOME LIBRARIES
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
//GLOBAL VARIABLES
char API_SERVER[] = "www.google.com"; // name address for Google (using DNS)
//Set some data for manual configuration of the arduino
byte IP_ADDRESS[]={192,168,1,20};
byte DNS_SERVER[] = { 8,8,8,8 };
byte DEFAULT_GATEWAY[]={192,168,1,1};
byte SUBNET_MASK[]={255,255,255,0};
byte MAC_ADDRESS[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// 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);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
//Use DHCP and try to get some IP address
if (Ethernet.begin(MAC_ADDRESS) == 0) {
Serial.println("Failed to configure myself using DHCP, I will set static IP");
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("Setting manual network configuration");
Ethernet.begin(MAC_ADDRESS, IP_ADDRESS,DNS_SERVER,DEFAULT_GATEWAY,SUBNET_MASK);//This will
}
else{
Serial.println("Bravo DHCP, my local IP is: ");
Serial.println(Ethernet.localIP());
}
// if you get a connection, report back via serial:
if (client.connect(API_SERVER, 80)) {
Serial.println(":) Connected to the API server");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.1");
client.println("Host: www.google.com");
client.println("Connection: close");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("Connection to the API failed :( ");
}
}
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);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
}
Serial.println("STOPPED");
}
Program compiles and uploads without any errors. When I open my serial monitor, I always get the message that Arduino couldn't connect. Is my board compatible with the shield I bought, and why I can't connect to the google?
I had problems with the R3 version of the WiFi shield if connected to a Pre-R3 version of an Arduino of any model. Maybe you have the same problem.
The R3 version shields require the IOREF pin (normally overhangs the sockets on the Arduino pre-R3 versions) to have a voltage applied. Since the Mega in my case (Duemilanove in your case) is a 5 volt IO device, I used a small jumper wire to connect the IOREF socket to the 5v socket on the shield. Problem solved. Let us know if that works for you.
That is not the problem you said you had in the original unedited post.
If connecting to google is the only problem, then try this test sketch to insure you have the correct network settings. Post the results of the serial monitor output.
SurferTim:
I had problems with the R3 version of the WiFi shield if connected to a Pre-R3 version of an Arduino of any model. Maybe you have the same problem.
The R3 version shields require the IOREF pin (normally overhangs the sockets on the Arduino pre-R3 versions) to have a voltage applied. Since the Mega in my case (Duemilanove in your case) is a 5 volt IO device, I used a small jumper wire to connect the IOREF socket to the 5v socket on the shield. Problem solved. Let us know if that works for you.
I connected IOREF with +5V pin. Still don't have any resutls
I don't understand what you mean by "don't have any result". Try the test code I posted above and post the serial monitor output. Does it show the network settings or show "failed"?
SurferTim:
I don't understand what you mean by "don't have any result". Try the test code I posted above and post the serial monitor output. Does it show the network settings or show "failed"?
I uploaded the code that you provided. I attached the image.
In the SerialMonitor I only get the message "Starting ethernet...". When I reset my device, the same message appears in the SerialMonitor. Also I attached the image of the DHCP clients, and there is no this device in the list.
SurferTim:
Those are solder bridges. If that is a new shield, I would contact your supplier, explain what you found, and request an exchange for a good shield.