Beginner needs help with WIFI SHIELD!!!!

Hi everyone,
I have used Arduino UNO for several months and I have just bought an Arduino Wifi Shield. I mounted it on the Uno board and try to load several sketches, such as finding available Networks or try to connect to a WPA2 personal wi-fi but none of these worked. When I tried to find available networks, it said : “InitInitializing Wifi…”
I used the sketch below:

#include <SPI.h>
#include <WiFi.h>

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

// attempt to connect using WEP encryption:
Serial.println(“Initializing Wifi…”);
printMacAddress();

// scan for existing networks:
Serial.println(“Scanning available networks…”);
listNetworks();
}

void loop() {
delay(10000);
// scan for existing networks:
Serial.println(“Scanning available networks…”);
listNetworks();
}

void printMacAddress() {
// the MAC address of your Wifi shield
byte mac[6];

// print your MAC address:
WiFi.macAddress(mac);
Serial.print(“MAC: “);
Serial.print(mac[5],HEX);
Serial.print(”:”);
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Serial.println(mac[0],HEX);
}

void listNetworks() {
// scan for nearby networks:
Serial.println("** Scan Networks **");
byte numSsid = WiFi.scanNetworks();

// print the list of networks seen:
Serial.print(“number of available networks:”);
Serial.println(numSsid);

// print the network number and name for each network found:
for (int thisNet = 0; thisNet<numSsid; thisNet++) {
Serial.print(thisNet);
Serial.print(") “);
Serial.print(WiFi.SSID(thisNet));
Serial.print(”\tSignal: “);
Serial.print(WiFi.RSSI(thisNet));
Serial.print(” dBm");
Serial.print("\tEncryption: ");
Serial.println(WiFi.encryptionType(thisNet));
}
}

Please tell me how to fix this problem is there anything wrong with the WIFI Shield that I bought? :smiley:

Try this short sketch. This checks the wifi shield startup. If the firmware version is not 1.1.0, you will probably need to upgrade the firmware. It is a bit of a pain in the backside, but only needs upgraded once.

#include <WiFi.h>

// change to your WPA2 settings
char ssid[] = "mynetwork";     // the name of your network
char pass[] = "mypassphrase";  // your network password

int status = WL_IDLE_STATUS;     // the Wifi radio's status

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

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println(F("WiFi shield not present")); 
    // don't continue:
    while(true);
  } 

  // check firmware version
  Serial.print(F("Firmware version: "));
  Serial.println(WiFi.firmwareVersion());
  
 // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print(F("Attempting to connect to SSID: "));
    Serial.println(ssid);
    status = WiFi.begin(ssid,pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
   
  // you're connected now, so print out the data:
  Serial.print(F("You're connected to the network"));
  printCurrentNet();
  printWifiData();
}

void loop() {
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print(F("SSID: "));
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);    
  Serial.print(F("BSSID: "));
  Serial.print(bssid[5],HEX);
  Serial.print(F(":"));
  Serial.print(bssid[4],HEX);
  Serial.print(F(":"));
  Serial.print(bssid[3],HEX);
  Serial.print(F(":"));
  Serial.print(bssid[2],HEX);
  Serial.print(F(":"));
  Serial.print(bssid[1],HEX);
  Serial.print(F(":"));
  Serial.println(bssid[0],HEX);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print(F("signal strength (RSSI):"));
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print(F("Encryption Type:"));
  Serial.println(encryption,HEX);
}

void printWifiData() {
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
    Serial.print(F("IP Address: "));
  Serial.println(ip);
  Serial.println(ip);
  
  // print your MAC address:
  byte mac[6];  
  WiFi.macAddress(mac);
  Serial.print(F("MAC address: "));
  Serial.print(mac[5],HEX);
  Serial.print(F(":"));
  Serial.print(mac[4],HEX);
  Serial.print(F(":"));
  Serial.print(mac[3],HEX);
  Serial.print(F(":"));
  Serial.print(mac[2],HEX);
  Serial.print(F(":"));
  Serial.print(mac[1],HEX);
  Serial.print(F(":"));
  Serial.println(mac[0],HEX);
  
  // print your subnet mask:
  IPAddress subnet = WiFi.subnetMask();
  Serial.print(F("NetMask: "));
  Serial.println(subnet);

  // print your gateway address:
  IPAddress gateway = WiFi.gatewayIP();
  Serial.print(F("Gateway: "));
  Serial.println(gateway);
}

void ShowSockStatus() {
  for(int x = 0; x < MAX_SOCK_NUM; x++) {
    Serial.print(F("Socket #"));
    Serial.print(x,DEC);
    if(WiFi._state[x] == -1) Serial.println(F(": available"));
    else Serial.println(F(": used"));

//    Serial.println(WiFi._state[x]);    
  }
}

edit: Are both devices an R3 or R2 model Uno and shield? The older Unos are R2, and there will be a 2 pin overhang on each side if using an R3 wifi shield. It has two additional pins on each side. The important pins are the ICSP connector. That is the socket under the shield. Insure it seats firmly on the Uno’s pins.

If there is a 2 pin overhang on each side, you must jumper the 5v to the ioref pin or you will get a “WiFi shield not present” message. The ioref pin (socket) is the one next to the reset pin on the other side of the 3.3v pin. My wifi shield has a component next to the header and there is no room for the silkscreen marking.

Also note the serial port is 115200 baud. Select that speed on the serial monitor bottom right.

I tried to compile the sketch you provided and I receive the following compiler error:

avr\utility\spi_drv.cpp.o: In function SpiDrv::begin()': E:\arduino-1.5.5-windows\arduino-1.5.5\libraries\WiFi\arch\avr\utility/spi_drv.cpp:22: undefined reference toSPIClass::begin()'

I am sure that I have upgraded my wifi shields firmware, but I can't get it work unless I use IDE 1.0.3. I would like to use your test sketch

I haven’t tried v1.5.5 yet. Maybe I should.

edit: OK, I downloaded it and took a look at the examples. The WiFi library now conforms (?) to the ethernet library. You must include SPI.h.

#include <SPI.h>
#include <WiFi.h>

How does that do?

OK, I tried it with IDE v1.5.5. Just include the SPI.h file and it runs good!