404 Not Found

The server can not find the requested page:

www.wpquery.co/jquery-1.6.3.min.js (port 80)

Please forward this error screen to www.wpquery.co's WebMaster.


You Are Here: Home » Tutorials » A beginner’s guide to connecting and operating the WiFly to Arduino Serially

A beginner’s guide to connecting and operating the WiFly to Arduino Serially

We were working on a home automation project , we used the wifly gsx in our project .
When we bought it, we thought it will be easy to communicate it like a serial modem between the arduino and PC ,,, of course we are not noobs :) but every inch in the datasheet made us feel like one :)
And when we searched for a solution for even one of our countless problems we faced…. the result can be summarized in three words … WIFLY NOT WORKING or we are noobs :D

Of course i am kidding :) ,,we are not noobs and wifly is WORKING :o , thanks to sparkfun wifly library and http://arduinology.tumblr.com/

We decided to start our new virtual hackerspace with this easy step by step tutorial for wifly :

Please post any problem you faced with wifly or arduino .


  1. First of all download the WiFly Serial Library from http://sourceforge.net/projects/arduinowifly/files/ credit goes Twaldock for making this library and examples, for more information go to http://arduinology.tumblr.com/ ,also download NewSoftSerial, Streaming, Time and PString libraries from http://arduino.cc/en/Reference/Libraries
  1. Add the WiFly and the other libraries to your Arduino library folder and restart your Arduino IDE, you now should see the library and examples.

  1. To test the WiFly and library open one of the examples that came with the library, for this tutorial I will use the WebTime example, this one send html of the current time to your browser.

  1. Now connect the WiFly board to the Arduino, connect the Tx of the WiFly to the Rx of the Arduino and the Rx of the WiFly to the Tx of the Arduino (don’t use Pins 0 and 1 or any reserved Pins) for the sake of this example connect the Tx to the Pin 2 and Rx to Pin 3 on the Arduino. Connect the VDD-BATT on the WiFly to the 3.3V on the Arduino and the GND to GND.


  1. Back to the WebTime sketch, modify the first couple of lines of code to your SSID and Passphrase if there’s any, and modify the TX and Rx pins according to your setup.

  1. now add this function to example, this function adjust the configuration of the WiFly in order to make it connect to your Access Point or Ad-Hoc connection

boolean initSettings()
{
WiFly.SendCommand(“set wlan auth <value>”,”AOK”);
//WiFly.SendCommand(“set wlan key <value>”,”AOK”);
WiFly.SendCommand(“set wlan channel <value>”,”AOK”);
WiFly.SendCommand(“set wlan join <value>”,”AOK”);
WiFly.SendCommand(“set dhcp <value>”,”AOK”);
WiFly.SendCommand(“save”,”AOK”);
WiFly.SendCommand(“reboot”,”AOK”);
}





  1. instead of <value> a real value should be entered
    1. for the first line of code WiFly.SendCommand(“set wlan auth <value>”,”AOK”) this is for the authentication type replace <value> with
      1. 0, Open
      2. 1, WEP-128
      3. 2, WPA1
      4. 3, Mixed WPA1&WPA2-PSK
      5. 4, WPA2-PSK
      6. 5, Not Used
      7. 6, Adhoc, Join any Adhoc network

    1. You don’t need to do this step unless you chose WEP-128 in the authentication type then you must enter this line WiFly.SendCommand(“set wlan key <value>”,”AOK”) where the value is the HEX key.
    1. WiFly.SendCommand(“set wlan channel <value>”,”AOK”), 1-13 is the valid range for a fixed channel. If 0 is set, then scan is performed, using the ssid.

    1. The WiFly.SendCommand(“set wlan join <value>”,”AOK”) sets the policy for automatically joining/associating with network access points. This policy is used when the module powers up, including wake up from the sleep timer.
      1. 0,, Manual, do not try to join automatically.
      2. 1, Try to join the access point that matches the stored SSID, passkey and channel. Channel can be set to 0 for scanning.
      3. 2, Join ANY access point with security matching the stored authentication mode. This ignores the stored SSID and searches for the access point with the strongest signal.
      4. 3, Reserved – Not used.
      5. 4, Create an Adhoc network, using stored SSID, IP address and netmask. Channel MUST be set. DHCP should be 0 (static IP) or set to Auto-IP with this policy. (unless another Adhoc device can act as DHCP server) add the ip and netmask
        1. WiFly.SendCommand(“set ip address 169.254.1.1″,”AOK”);
        2. WiFly.SendCommand(“set netmask 255.255.0.0″,”AOK”);
        3. Also set channel to 1, WiFly.SendCommand(“set wlan chan 1″,”AOK”);

    1. Last line in the configuration process WiFly.SendCommand(“set dhcp <value>”,”AOK”); which set the DHCP
      1. 0, DHCP OFF, use stored static IP address
      2. 1, DHCP ON, get IP address and gateway from AP
      3. 2, Auto-IP, generally used with Adhoc networks
      4. 3, DHCP cache mode, Uses previous IP address if lease is not expired (lease survives reboot)

    1. You need to save and reboot each time you configure the WiFly Wlan options thus the WiFly.SendCommand(“save”,”AOK”) and WiFly.SendCommand(“reboot”,”AOK”);


  1. Now add initSettings() as the first line of a function called Reconnect();

  1. That’s it, upload the WebTime Sketch to your Arduino and see if it works, if you connected the green, yellow, red LEDs to the PIO4, PIO5, PIO6 respectively of the WiFly you should see its status
    1. Red LED
      1. Fast blinking, not connected to wireless network
      2. OFF, Connected
    2. Yellow LED
      1. With each blink it means its either sending or receiving data from Tx or Rx
    3. Green LED
      1. ON Solid, connected over TCP
      2. Fast Blink, no IP address
      3. Slow Blink, IP address OK



  1. After uploading the Sketch open the serial monitor to see the Arduino activity, it should display “Starting WebTime – Please wait.” and then “Free memory= <value>” and then stops for about 10 sec or more and the continue, if it doesn’t continue the means you have something wrong in your connection between the Arduino and WiFly and it’s not receiving data


  1. After it continues you should see quite a lot of lines coming up on your serial monitor if it connected successfully you should see your IP address that has been assigned to the WiFly and the Green LED is slowly Blinking while the RED LED is OFF, if you find your IP address to be 0.0.0.0 then the WiFly failed to connect to your wireless network and that you may have configured it wrong.


  1. When you see ready for HTTP in the serial monitor, go to your browser and enter the IP address found in the serial monitor and add port 2000 to it (xxx.xxx.xxx.xxx:2000).


  1. You should see some activity in the serial monitor and the browser should show you some data about current time



  1. If all works right for you, you can remove the initSettings() function as this is only need to be run once to configure the WiFly and you won’t be needing it anymore

  1. For more information about the commands that can be sent to the WiFly check the WiFly Command Reference Manual http://www.sparkfun.com/datasheets/Wireless/WiFi/WiFlyGSX-um2.pdf

  1. Good Luck and Have Fun

Comments (13)

  • discount mens ugg boots

    This is really interesting, You are a very skilled blogger. I’ve joined your feed and look forward to seeking more of your wonderful post. Also, I’ve shared your site in my social networks!

  • Suburb Crochet Ugg Boots

    Your site isn’t only informative but very artistic too. There are often very several people who can write not simple articles that creatively. Continue the excellent writing !!

  • womens ugg boots on sale

    YES! I lastly found out this web page! I’ve been looking just for this post for so long!!

  • bubbleshooter2.info

    Useful material, many thanks for sharing these in A beginner’s guide to connecting and operating the WiFly to Arduino Serially | Cairo|Hackerspace.

  • bubble shooter 2 free

    Excellent job writing A beginner’s guide to connecting and operating the WiFly to Arduino Serially | Cairo|Hackerspace. I would like to learn more about this subject.

  • دومين

    Attractive portion of content. I simply stumbled upon your web site and in accession capital to claim that I acquire actually enjoyed account your blog posts. Any way I’ll be subscribing on your feeds or even I fulfillment you access persistently quickly.

  • reseller web hosting

    Loving the info on this site, you have done great job on the blog posts. best reseller hosting | reseller hosting |

  • bubble shooter games free

    Hi, many thanks for sharing your ideas in A beginner’s guide to connecting and operating the WiFly to Arduino Serially | Cairo|Hackerspace. This is actually a cool website.

  • face exercises

    Congratulations Alyssa as you embark on another and the most awarding career, motherhood.

  • Ugg boots outlet

    I do trust all the concepts you have introduced for your post. They’re really convincing and can definitely work. Still, the posts are too quick for newbies. May just you please prolong them a little from next time? Thank you for the post.

  • Chuck Altmann

    Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there’s even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That’s right AUTOMATICALLY, just watch this 4minute video for more information at. WordPress Seo Plugin