Which RN-XV library to use?

I spent a while going through lots of different WiFi libraries before I found one that made things easy. Eventually I’ve settled on dpslwk‘s version of the WiFly library here and there’s one big reason why:

The WiFlyClient class inherits from Client meaning it can be dropped in as a replacement for the standard Ethernet library.

That said, there’s still a little bit of work to do if you don’t want to use the shield as that uses SPI communication and without the shield, you’re stuck with normal uart. Here’s a modified version of the WiFly_WebClient that uses SoftwareSerial.

// (Based on WiFly's WebClient Example)
 
#include <SPI.h>
#include <WiFly.h>
#include <SoftwareSerial.h>
 
char passphrase[] = "yourpassphrase";
char ssid[] = "yourssid";
 
WiFlyClient client;
SoftwareSerial pin89Serial(8,9);
 
void setup() {
 
  Serial.begin(9600);
  pin89Serial.begin(9600);
 
  WiFly.setUart(&pin89Serial);
  WiFly.begin();
 
  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }  
 
  Serial.println("connecting...");
 
  if (client.connect("reddit.com", 80)) {
    Serial.println("connected");
    client.println("GET / HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
 
}
 
void loop() {
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
 
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

Upload that, open the serial console and you should see the HTTP output after a few seconds.

Setting up a RN-XV WiFi module without a shield

I was looking for a cheap way of getting an Arduino online and the official ethernet and wifi shields were just too expensive. coolcomponents.co.uk sell an RN-XV wifi module for around £30. There are a couple of issues I had to work through though:

Pin spacing
The little module has very tight pin spacing. It fits on the XBee Breakout Board but I didn’t want to spend any more so as you can see below, I did some terrible soldering to give myself direct access to 3.3V, GND, TX and RX pins. I may add some of the others later but that’s all you need to start with.

rn-xv wifi module

Getting It Set Up
There are lots of guides but they all either go through the shield, or were too complicated for my noob mind. It took me a long time but eventually after trudging through a bunch of details, I modified one of the Arduino example scripts to get me straight through to the module’s serial interface. The sketch is below:

/*
Serial Passthrough to pin 89 based on the mega multi-serial example
 */
 
#include <SoftwareSerial.h>
SoftwareSerial pin89Serial(8,9);
 
void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  pin89Serial.begin(9600);
}
 
void loop() {
  // read from port 1, send to port 0:
  if (pin89Serial.available()) {
    int inByte = pin89Serial.read();
    Serial.write(inByte); 
  }
 
  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    pin89Serial.write(inByte); 
  }
}

Connect your RN-XV to your arduino as listed below:

Pin 1 (3.3V) to Arduino 3.3V (DO NOT connect to 5V)
Pin 2 (TX) to Arduino pin 8
Pin 2 (RX) to Arduino pin 9
Ping 10 (GND) to Arduino GND

…and upload the sketch. If you open the serial console, you’ll probably now see some output from the module. Either way, send ‘$$$’ with ‘no line ending’. You should get the response ‘CMD’. If so, you’re all good and you can now change to ‘Carriage Return’ in the drop-down and try ‘show stats’. You should get some stat output back.

If that’s all worked then try the following to get onto your WLAN:

set wlan phrase pass-phrase
set ssid network-name
save
reboot

Once it’s successfully rebooted, I’d suggest a firmware update. It’s easy and just requires you to go back into CMD mode with ‘$$$’ (remember to turn off the carriage return), then run:

ftp update
ver

The manual suggests a factory reset so:

factory RESET
set wlan phrase pass-phrase
set ssid network-name
save
reboot

You should be all set now 🙂
There’s lots more info on the module’s page here

Too Many Things To Try

Having a really short attention span and a wide range of interests makes for lots and lots of things to try. Now I just need to figure out what to do with some of these: