Dear all, I have an Ethernet Shield on the top of an Arduino Uno wires with a serial LCD. What I am trying is to ping my own router. I got it shows, “Connected”, but when I wire the reset pin to ground to reset it, or when I unplug the power to restart the board and it always shows in the display, “Connection fail”. Do you know any command to fix this problem? Please help, and thank you very much in advance!
Below is what I write into the board.
#include <Ethernet.h>
#include <SPI.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
SoftwareSerial LCD(2,3); //communicate on pin 3
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0x1Q, 0xMA, 0x3F, 0x22, 0x2A };
byte ip[] = { 192, 168, 1, 105 };
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 };
//byte pingAddr[] = {192, 168, 1, 1}; // ip address to ping
IPAddress ping(192, 168, 1, 1);
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// Open serial communications and wait for port to open:
LCD.begin(9600);
// give the Ethernet shield a second to initialize:
delay(500);
LCD.println("Connecting...");
delay(4000);
LCD.write(0xFE);
LCD.write(0x01);
// if you get a connection, report back via serial:
if (client.connect(ping,80)) {
LCD.println("Good connection");
delay(4000);
LCD.write(0xFE);
LCD.write(0x01);
}
else {
// if you didn't get a connection to the server:
LCD.println("Connection fail");
delay(4000);
LCD.write(0xFE);
LCD.write(0x01);
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
LCD.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 (LCD.available() > 0) {
char inChar = LCD.read();
if (client.connected()) {
client.print(inChar);
}
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
LCD.println();
LCD.println("Disconnecting");
delay(5000);
LCD.write(0xFE);
LCD.write(0x01);
client.stop();
// do nothing:
//while (true);
for(;;);
}
}