My Cart

Tutorial: Wifi Module for Arduino "Roving RN-XVee"March 8, 2012

Introduction

In this tutorial we are going to introduce the use of ARDUINO with WiFi. We will use the WiFi Module Roving RN-171. This module fits in the XBee socket of our Communication Shield and allows to connect your Arduino shield to a WiFi network.

Ingredients:

Difficulty: Medium -medium

Preparation Time: 20 minutes

Steps Index

Step 1: Connecting the WIFI module:


Connect the Wifi module to XBEE shield module as shown in the picture.

Then connect the XBEE shield to Arduino as shown in the picture.

Step 2 : Enter in command mode:

To enter in command mode, write “$$$” over the UART, (IMPORTANT: There is no carriage return after $$$). You should see CMD returned to you. This will verify that your cable and comm. Settings are correct.
// Enters in command mode

 Serial.print("$$$"); check();

 

Step 3 : DHCP protocol.

To solve the IP address with DHCP protocol, enter command
set ip dhcp 1

Most valid commands will return an AOK response, and invalid ones will return an ERR decription.

 // Sets DHCP and TCP protocol
 Serial.print("set ip dhcp 1\r"); check();
 Serial.print("set ip protocol 2\r"); check();

 

Step 4 : Connecting to a router AP:

To set the policy for manually joining/associating with network access points, enter command s
set wlan join 0

To set the passphrase for WPA and WPA2 security mode, enter command
set wlan phrase XXX

If the security is WEP, enter command
set wlan key XXX

To join the network ssid manually, enter command
join SSID

If everything is correct, you should see something like next image once called to join.

 // Configures the way to join the network AP, sets the encryption of the
 // network and joins it
 Serial.print("set wlan join 0\r"); check();
 Serial.print("set wlan phrase PASSWORD\r"); check();
 Serial.print("join libelium_wsn2\r"); check();

 

Step 5 : HTTP protocol:

To set the server address with a DNS address, enter commands
set ip host 0
set dns name WWW.URL.COM

To set the HTTP port, enter command
set ip remote 80

To set the GET query that is sent when the por is opened, enter command
set comm remote GET$/....

To set the correct format that is sent to the web server, enter command
set opt format 1 (HTML header based broadcast interval in this case).

And finally, to open the connection, enter command
open

If everything is correct, you should see something like next image.

 // Sets the DNS address
 Serial.print("set i h 0\r"); check();
 Serial.print("set d n www.URL.com\r"); check();

 //Configures HTTP connection
 Serial.print("set i r 80\r"); check();
 Serial.print("set c r GET$/...\r"); check();
 Serial.print("set o f 1\r"); check();

 // Calls open to launch the configured connection.
 Serial.print("open\r"); check();

 

Step 6. Complete Code

char recv[512];
int cont;

void setup()
{

Serial.begin(9600);
}

void loop()
{
while (Serial.available()>0) {}
// Enters in command mode
Serial.print("$$$"); check();

// Sets DHCP and TCP protocol
Serial.print("set ip dhcp 1\r"); check();
Serial.print("set ip protocol 2\r"); check();

// Configures the way to join the network AP, sets the encryption of the
// network and joins it
Serial.print("set wlan join 0\r"); check();
Serial.print("set wlan phrase PASSWORD\r"); check();
Serial.print("join libelium_wsn2\r"); check();

// Sets the DNS address
Serial.print("set i h 0\r"); check();
Serial.print("set d n www.URL.com\r"); check();

//Configures HTTP connection
Serial.print("set i r 80\r"); check();
Serial.print("set c r GET$/...\r"); check();
Serial.print("set o f 1\r"); check();

// Calls open to launch the configured connection.
Serial.print("open\r"); check();
}

void check(){
cont=0; delay(1000);
// Receive the answer from the WIFI module.
while (Serial.available()>0)
{
recv[cont]=Serial.read(); delay(100);
cont++;
}
recv[cont]='\0';
// Print the answer.
Serial.println(recv);
// Clean the buffer to be able to send a command.
Serial.flush(); delay(1000);
}

Important Issues

  • There is no carriage return () after the $$$ to enter command mode.
  • While in command mode, the device will accept ASCII bytes as commands. Each command ends with a carriage return.
  • The messages that come from the WIFI module are quite big, for this reason, if you want to debug your program and check those messages, go to
    /.../arduino-0022/hardware/arduino/cores/arduino and modify HardwareSerial.cpp then make RX_BUFFER_SIZE value set to 512.

 

Links and documentation

Datasheet
User Manual

If you are searching for Wireless Sensor Networks devices (motes) you may be interested in our ready to market sensor platform: Waspmote. You can discover the differences between both platforms in the document: Waspmote vs SquidBee.

8 thoughts on “Tutorial: Wifi Module for Arduino "Roving RN-XVee"”

  • Nicolas

    Hi,
    Can you please give the entire sketche you are using to test this circuit ? (It doesn't work with Arduino 1.0 and oldest)
    Other question : what are the pins (RX+TX) that you are using for the sketche ? I have communications problems between the board + shield + RN XVEE : I can use the RN XVEE alone (using the embedded commands) but can't have it managed by the Arduino ..
    Thks for your help
    Nicolas

    Reply
    • Cooking Hacks

      Hi Nicolas. You should test it with Arduino 0022. In some cases, Arduino 1.0 fails due to libraries or drivers so we recommend to use a previous version.
      For the second question, you should configure first the module and save the configuration. Then, you can program Arduino (without the shield) to upload the code. Remember to upload the code without the shield. You can also use our forum for technical questions: http://www.cooking-hacks.com/index.php/forum.html

      Reply
  • Josep Mª Balaguer
    Josep Mª Balaguer September 24, 2012 at 11:58 pm

    Hi,
    I've gone through the tutorial in order to get my Arduino Mega+ArduinoXBee+Roving RN-XVee configured and attached to my home Wifi.
    The conclusion is that, following the console direct programming mode, I've manage to get my RN-XVee attached to the WiFi network as expected. In the contrary, when I've tried to launch the auto config program that you provide in the tutorial (adapted to my network info: Password and SSID) the system has entered into a infinite loop sequence, launching the config scripts once and again.

    Can you please provide me some insights about what should I be doing incorrectly? It seems that there's something wrong with the program you have provided.

    Reply
    • Cooking Hacks

      Hi Josep.
      The tutorial is based in Arduino UNO + Roving X-Vee. However, it should work. Please, post in our forum and our developers will help you as soon as possible. http://www.cooking-hacks.com/index.php/forum.html
      Thanks for your feedback.

      Reply
  • Sharil Mohd Rizuan

    Hi,
    It is a great thing that I found this blog for Arduino with Wifi. But, can this be done without my router and connect it with my Ipad Internet Plan to communicate, because I want to communicate this RN-Xvee + Arduino with my Ipad. Can you give me a better advise.

    Reply
    • Cooking Hacks

      Hi Sharil. You can use your iPad as a tethering connection. We have used an iPhone in the e-Health example: http://www.cooking-hacks.com/index.php/documentation/tutorials/ehealth-biometric-sensor-platform-arduino-raspberry-pi-medical#step5_5

      Reply
  • Jason Oh

    you are using serial print for receive and transmit. for arduino uno , there is only one port. you should use serial for user interface and serial1 for pc-arduino instead. eg. when u println(recv) it sends the cmd back to the arduino again!

    Reply
Leave a Reply