2013-03-06

Arduino and WiFi

As part of my first goal to integrate my on-board electronics with my iPad/iPhone, I have to come up with a solution on how to makes my marine gear talk Wi-Fi.

I have spent quite a few hours in the past days to figure out how to configure the Arduino with WiFi. This post is quite technical, and summarizes all steps to achieve the goals that I had. There was a bit of trial-and-error involved, but I got things working in the end.

I am currently using an old Arduino Duemilanove, connected to a Roving Networks RN-XV WiFly module, with an old XBee Explorer Regulated in between. I got all this stuff from Sparkfun.com a few years ago. It would probably be easier to buy the WiFly Shield today, but I had these modules laying around, so I decided to use them.

With the stuff mentioned above, I have connected a serial signal, currently coming through my USB cable from my PC to my Arduino, to a UDP broadcast over WiFi.

The longer plan is to use this as a basis for my NMEA hub, but extend it with a new Arduino MEGA controller. I will wait with the connection until I got everything working.

I also have a XBee Explorer USB that I have been using to configure my WiFly module.
XBee Explorer USB
The WiFly module is configured by connecting the WiFly module with the XBee Explorer USB, plugging the XBee Explorer USB to the PC, and running Putty as a configuration terminal software.

On my computer, the XBee Explorer USB shows up on COM3, and I connect to that with the default speed of 9600 bps.

Once connected with Putty, I ran the following commands, taken from the WiFly manual:

factory RESET
save
reboot
set wlan ssid <your-wifi-ssid>
set wlan pass <your-wifi-password>
save
reboot 

I am using Port Peeker for monitoring UDP packages on my network: Install, then start Port Peeker, and select the UDP protocol, and port 55555, which is the default WiFly heartbeat port. You should see something like this, that indicates that your WiFly is operating as expected:


---- 06.03.2013 22:33:07.562
0000   28 CF DA B7 9D 63 01 1F 07 D0 00 00 06 6B 0B ED   (....c.......k..
0010   0D 01 54 69 6D 65 20 4E 4F 54 20 53 45 54 00 00   ..Time NOT SET..
0020   57 69 46 6C 79 20 56 65 72 20 32 2E 33 30 2C 20   WiFly Ver 2.30, 
0030   31 30 2D 32 36 2D 32 30 31 31 00 00 57 69 46 6C   10-26-2011..WiFl
0040   79 2D 45 5A 58 00 00 00 00 00 00 00 00 00 00 00   y-EZX...........
0050   00 00 00 00 00 00 00 00 00 00 00 09 21 00 00 00   ............!...
0060   00 00 00 00 00 00 00 00 00 00 00 00 00 00         ..............  

I continued with Putty, and added the following commands:

set ip proto 1
set uart baudrate 38400
save
reboot

This puts WiFly into UDP only mode, and sets the baud rate to 38400, which is the standard baudrate for AIS messages. I intend to run all NMEA messages on 38400 bps.

I removed the WiFly module from the USB adapter, and inserted it into the XBee Explorer Regulated module, that I had to solder in a 10 kOhm resistor between the pins indicated in the picture below to make the WiFly module work with the XBee Explorer Regulated.


Modification of XBee Explorer Regulated with 10kOhm resistor
The connections are done in the following way:
Arduino with WiFly

Arduino          XBeeExplorerRegulated
5V         ->    5V
GND        ->    GND
D2         ->    DOUT
D3         ->    DIN

In the Arduino development tool, I have created a small program that simulates an incoming AIS signal:

#include <WiFlyHQ.h>
#include <SoftwareSerial.h>

SoftwareSerial _wiflySerial(2,3);
WiFly _wifly;

void setup()
{
  _wiflySerial.begin(38400);
  _wifly.begin(&_wiflySerial);
  _wifly.setIpProtocol(WIFLY_PROTOCOL_UDP);
}

void loop()
{
  _wifly.sendto("!AIVDM,1,1,,B,19NWrrP02sbuuuuhM86hA0=n2<0:,0*12\r\n", "255.255.255.255", 50000);
  delay(1000);
}

This small program simply dumps out a hard-coded test NMEA sentence on the WiFly module. I verify that the entire signal flow is working by running Port Peeker again, this time monitoring UDP port 50000. I got the following results, which confirms that everything works as expected:

192.168.1.19 : 2000 Length = 49 bytes
MD5 = 694D4EFC160306E00AA945CD995B9E77
---- 06.03.2013 22:40:39.359
0000   21 41 49 56 44 4D 2C 31 2C 31 2C 2C 42 2C 31 39   !AIVDM,1,1,,B,19
0010   4E 57 72 72 50 30 32 73 62 75 75 75 75 68 4D 38   NWrrP02sbuuuuhM8
0020   36 68 41 30 3D 6E 32 3C 30 3A 2C 30 2A 31 32 0D   6hA0=n2<0:,0*12.
0030   0A       

Hurrah! I now have an Arduino that can output NMEA sentences via Wi-Fi, and broadcasting it using the UDP protocol. This is what I need for the next step...

No comments:

Post a Comment