The module is 3.3V, meaning some form of level shifting is needed with a 5V system like an Arduino. You can use this module with an Arduino via an XBee shield pretty easily. However it is even easier to use with the 3.3V Teensy 3.0 ARM board, provided you have a breakout for small-pitch XBee module footprint. The Teensy is also nice for this application because it has multiple serial ports, so you don't need to use the SoftwareSerial library, or program the board, then disconnect to use the wireless.
Setting everything up was pretty easy once I knew what to do, but this post summarizes the process should I ever need to do it again.
The setup that I am using is shown below:
Only four connections are needed once you're set up, 3.3V, GND and two data connections. DOUT from the Teensy3.0 Serial3 connects to DIN of the RN-XV and DIN from the Teensy to DOUT to the RN-XV. This makes the module operate as just a serial port, making it pretty easy to interface with. The remaining orange wire connects the Serial LCD display, more on this later.
To get started, I found it was easiest to set the RN-XV in ad-hoc mode. This can be done by connecting pin 8 to 3.3V and will cause the module to create its own wireless network. When this happens you will see the status LEDs blinking green, orange and red; they're doing it, but you can't really see in this picture. Note the additional green wire to 3.3V connected to the 8th pin.
You can then look for the network. On a Mac it's pretty easy, it just shows up in the list of networks in the status bar:
The WiFly shows up towards the bottom as WiFly-GSX-a8 or something similar. If you connect to this network, you can then telnet to the module using the IP address: 169.254.1.1, port 2000. The module should then respond with a *HELLO* string, at which point you type $$$
When the module is ready, it will respond with the CMD message to indicate that you're in command mode. To set up your network you can issue the commands:
set wlan phrase (password); set lan ssid (your network name); save reboot
You can also issue commands to assign a static IP address to the module, but I didn't do this. For more information, see this excellent introduction http://www.tinkerfailure.com/2012/02/setting-up-the-wifly-rn-xv/
I found that sometimes the module would respond with a confirmation and sometimes would not. I repeated the process a few times in the hopes that some combination would stick. After this process, remove the power and and connection from pin 8 to 3.3V. This will cause the device to try to connect to your wireless network.
You should now be able to telnet to the device, but this time with your computer and it connected to your normal WiFi network rather than the ad-hoc network that the device creates. However first you need to find the IP address of the module. To do this, I went into my router configuration page:
Conveniently the WiFly module had an entry: 192.168.1.106. Depending on your router, you should be able to set up a specific IP address for the router to assign to the module based on the MAC address. However my POS router does not allow this.
I could then telnet to the module's IP address, again using port 2000. This module responds with the same *HELLO* prompt, indicating that everything was successful and the module is on the network and communicating.
With the connections above the Teensy should now see the module as just another serial port. To test this, I attached the Serial LCD and uploaded the following code to the Teensy:
#include<stdio.h> void setup(){ Serial.begin(9600); Serial2.begin(9600); Serial3.begin(9600); } void write_lines( const char *L0, const char *L1 ){ Serial2.write( 0xFE ); Serial2.write( 0x01 ); delay(10); Serial2.write( 0xFE ); Serial2.write( 128 ); delay(10); Serial2.print( L0 ); Serial2.write( 0xFE ); Serial2.write( 192 ); delay(10); Serial2.print( L1 ); } void loop(){ if( Serial3.available() ){ char L0[17]; char L1[17]; int pos = 0; L0[0] = '\0'; L1[0] = '\0'; while( Serial3.available() ){ char c = Serial3.read(); if( c == '\n' ){ pos = 0; Serial.print('\n'); } else if( c == '\r' ){ } else { if( pos < 16 ){ L0[pos] = c; pos++; L0[pos] = '\0'; } else if( pos < 32 ){ L1[pos-16] = c; pos++; L1[pos-16] = '\0'; } Serial.print( (char)c ); } } write_lines( L0, L1 ); } delay(100); }
My LCD is a 2x16 character display. The code above just polls for available data on the third serial port and, when a newline is encountered, prints it out onto the display. Lo and behold, after the following session:
Jamess-MacBook-Pro:~ jgregson$ telnet 192.168.1.106 2000 Trying 192.168.1.106... Connected to 192.168.1.106. Escape character is '^]'. *HELLO* This is James
The result on the display is below:
Hooray! An utterly useless internet thingy!
5 comments:
Thank you, gave me a great jumpstart on building an arduino wifly server for configuration purposes.
Glad you found it helpful!
James
Can i set a specified port of LAN NETWORK to send data because i would like to connect 10 arduino's with their respective xbee wifi ... I don't want lost data if connect all these arduinos in the same port. (for listening in a SOCKET of C# application).
Example:
Arduino 1 :
set ip "to send data" : 192.168.1.4
specified port : 2220
Arduino 2 :
set ip "to send data" : 192.168.1.4
specified port : 2222
Arduino 3 :
set ip "to send data" : 192.168.1.4
specified port : 2222
Can anyone help me?
I'm really not sure. It sounds like you're trying to do something way beyond what I set up.
Good luck though!
Hi, what did you use to connect the non-standard pins spacing on the WiFly to your breadboard?
Post a Comment