chipKIT® Development Platform

Inspired by Arduino™

Hints on using the WiFi Shield

Created Wed, 01 May 2013 15:21:46 +0000 by KeithV


Wed, 01 May 2013 15:21:46 +0000

I am seeing a lot of topics poping up where some have had troubles getting the WiFiShield to connect. Most of the problems are configuration issues. Instead of attempting to answer each and every post, hopefully you will get some hints here.

To start with the examples are intentially simple for readability, not for robustness; so when you fail the examples don't give much information as to why. There is an example, the WiFiRemoteWOL example that shows how to write a robust sketch and will do much better error reporting. However, I would not start there, I would start with the WiFiScan application as that does not require any security setting and it will let you know if the WiFiShield is working.

So start with WiFiScan, if this works then your hardware is up and running and you are successfully talking to the router/AP. If this does not work, chances are you have included the wrong WiFi Hardware library. The WiFiShield now comes in 2 flavors, B and G; and they require different libraries to work. The older Shield has a B MRF24WB on it and requires you to include WiFiShieldOrPmodWiFi.h, the newer WiFiShields come with a G MRF24WG on it and you need to include the WiFiShieldOrPmodWiFi_G library. Get the wrong library and the sketch will compile but just hangs when run. Sorry, there is no runtime check that I know of to to determine that you have a B or G.... especially checking the G from the B library.

Once you get the scan working, now you need to set up your security settings. And yes WPA works... But it can get very tricky depending on the model of router you have and if you have a B or G MRF24. Be honest... how many of you have read the document under ...\libraries\DWIFIcK\documents\DWIFIcK.pdf? I bet not many... Go read the section on how to set up your router! The short answer is, some routers will not talk (by default) at 2Mbs, and the B module's max speed is 2Mbs. The G module can run at 54Mbs, so it can talk to more routers by default. Also you must broadcast your SSID. Now, before blasting the MRF24WB too much, understand ALL routers are required by definition to talk at 2Mbs; but many manufactures have assumed everyone can talk faster than that now. I like LinkSys, they just seem to work out of the box.

Once you get WiFiScan to work, if you get the generic error 40 back, chances are you don't have your security setting set up correctly. This is for secruity reasons. If you don't hit the router with the correct security parameters the router intentionally does not give you a detailed diagnostic code; you could be a bad guy attempting a bad thing, so the router tells you nothing about what went wrong. So the WiFi library has no clue what went wrong, thus error 40. If you get an error other than 40, then moving to WiFiRemoteWOL might help as you will get better error reporting in that example. There probably was some post connection failure where we do get some diagnostics, you just have to step through each of the connection steps individually to see where the error is occuring. WiFiRemoteWOL steps through the steps whereas the WiFiTCPEchoClient jumps right to the TCP connection.

Hope this helps.


Tue, 29 Oct 2013 11:15:20 +0000

Got the WIFI scan working fine. But when I try another example (e.g. WIFI TCPechoClient), isInitialized (status) returns false with status = 41????

IPv4 myIP;
myIP.rgbIP = {192,168,0,7};
do {
    if (DNETcK::isInitialized(status)) {
        if (DNETcK::isStatusAnError(status)) {
            Serial.print("Error: ");
            Serial.println(status, DEC);
            Serial.print("Waiting..Status: ");
            Serial.println(status, DEC);

any Ideas?