Arduino Uno + Wireless proto shield + Wifly module

Hi Arduino community!!

Let me do a quick introduction here since i'm new, and this would be my first post on these forums.
-- a few years back i ran into this project controlling RGB leds using a PIC microcontroller. This project really triggered an interest in finding out how this stuff works, and how to program these microcontrollers.
So, a few books (mainly on c for PIC's) later, and a few projects later, i decided to try out Arduino. (Arduino is kind of hard to miss once you get to play with microcontrollers)
So i bought myself a Arduino Uno r3 .
After doing a few tutorials (bought some getting started books on arduino as well as the Arduino Cookbook.) it was time to do something a little more advanced.
To make things a bit more interesting, i bought a Wifly module to put into a Wireless proto shield
I would like to start off easy (hello world), by controlling a led:

  • either wireless by making a socket to a server app. (got one by following ms c# tutorials 8) )
  • or control the led through serial, and letting the arduino host a webpage showing the status of the led.

Hooking up the Wifly module wasn't very difficult, i hooked the Wifly module up to the Arduino using the Wireless proto shield, and as per instructions in the manual, i got into command mode, scan all the WLANS in my appartment, and associating with my own SSID. The unit got an IP straight away, and it responds to ping requests. So i figure the module is connected to my WLAN!

Anyway, i soon found out that there are some compatibility issues with the Wifly library and Arduino 1.0
The example code did not compile, and i don't have the skills (yet XD) to fix this myself.
after searching the internet for help i finally found a library which is supposed to be compatible, and made a VERY simple sketch:
after the
#include "WiFly.h"
#include "Credentials.h" //file modifed obviously..
in the setup i have the serial.begin, and in the main loop i just write "hi" to the serial port with a delay before looping.
If i upload this sketch i see the "hi" messages coming into my terminal.
But, once i do a WiFly.begin(); in the setup part (as in the examples) i can still compile and upload the code, but the arduino seems to get stuck. The lights of the wifly unit blinks as it's telling us it's connected to the network (still can ping the unit), but it never starts sending out the "hi" message to the serial port.
If i comment out the WiFly.begin(); the unit starts sending the mssg to the serial port again.
So it seems that the arduino hangs on the WiFly.begin(); method.
Can someone please tell me how to troubleshoot this? or, get me up and running using the Wifly shield using Arduino 1.0?
Any help would be very appreciated!
Thanks in advance,

Sander.

Can someone please tell me how to troubleshoot this? or, get me up and running using the Wifly shield using Arduino 1.0?

Without seeing your code, no, I'm afraid not.

thanks for your answer.
The code i used couldn't be more simple:
To see where it hangs i simply stripped out everything :slight_smile:
The code which does give me the mssg to the terminal:

#include "WiFly.h"
#include "Credentials.h"


Server server(80);

void setup() {
//  WiFly.begin();
  Serial.begin(9600);

}

void loop() {
  Serial.print("Ping");
  delay(100);
}

While this doesn't.

#include "WiFly.h"
#include "Credentials.h"


Server server(80);

void setup() {
  WiFly.begin();
  Serial.begin(9600);

}

void loop() {
  Serial.print("Ping");
  delay(100);
}

in both cases i can ping the unit though..

thanks again!

Well, it would be a pretty cool device if i could get it to work.
Any advice for a newb like myself to find a working library?
I'm not the only one without the issue that the library isn't working with arduino > v22
I know i'm not providing much info here, but i don't really know what i could test / try to come up with additional info.
Would my conclusion be correct to say that it is the Wifly library which does compile is the cause of the unit hanging? (since unit does not hang without the Wifly.Begin())
Any other tips how to proceed?
Many thanks!

Why not skip using the library to start with and just configure the wifly using the serial monitor? Are you wanting to do anything that would require changing the config on the fly? E.g switching between TCP and UDP protocols, sending packets to more than one host? If not then you don't need the wifly library.

Once the wifly is configured it will send anything the arduino writes to its serial port as a UDP or TCP packet to the configured host address and port. The wifly will also send the payload of any packets it receives to the Arduino's serial port.

ok cool! i will experiment with this! thanks!
but does this mean i cannot use the serial link to the pc and the WIFLY module at the same time? as in, connect to WLAN and print out the IP address to the console?

You're right; with the shield you have you can't use the serial monitor and the wifly module at the same time, since the shield connects the wifly module's serial pins to the arduino's hardware serial pins (pins 0 and 1).

One option would be to clip off shield's 0 and 1 connector pins and use two jumper wires from the shield's sockets for pins 0 and 1 to two other pin sockets (e.g. 11 and 12) and use software serial for the wifly communication. Then you can use the serial monitor for debugging your sketch at the same time that the wifly is sending and receiving packet data.

For an example of this take a look at this post:
New XBEE WiFi modules - #15 by system - Networking, Protocols, and Devices - Arduino Forum.

After you do this if you want to configure the wifly using the serial monitor you will need to load a small sketch that reads characters from the serial interface and sends them to the soft serial interface, and reads characters from the soft serial interface and sends them to the serial interface. E.g. (not tested):

#include <NewSoftSerial.h>

NewSoftSerial wfSerial(11, 12);

void setup()
{
    Serial.begin(9600);
    Serial.println("Starting");

    wfSerial.begin(9600);
}

void loop()
{
    if (Serial.available()) {
        wfSerial.write(Serial.read());
    }

    if (wfSerial.available()) {
        Serial.write(wfSerial.read());
    }
}

This example works with the older Arduino IDE (not 1.0) and uses the NewSoftSerial library. With the 1.0 IDE you can use the soft serial library that comes with the IDE.

I've used the software serial interface reliably at 38400 baud, but it might be able to run at a higher baud rates.

Edit: fix typo

I forgot to mention that you can also enable telnet support on the wifly module. Then when you want to configure it you just use telnet to connect to the wifly's IP address and view and modify the config using that. A telnet client application should be available by default in linux and OS X, and I believe one comes with windows too.

You can enable telnet support with the "set ip protocol" command and setting bit 2.

Example telnet command: (wifly IP address is 192.168.1.10 - replace with the IP address of your wifly):

telnet 192.168.1.10 2000

ah, things are becoming much more clearly now! thanks for helping out!
Yesterday i tried to connect to the wifly module through telnet, connected without a problem (could enter command mode straight away 8)) didn't even have to configure the module to accept telnet.
I figure once communication is up, i can also ship any info from the arduino to the pc through the wireless link. (i got the mac address of the unit reserved in my DHCP server, so the IP addy is known.)
Could you confirm that i don't need the wifly library to connect to a server over a socket? I've read through some ethernet examples, but i'm not sure how much different that would be since they all rely on the ethernet library.

Well, you've got the hardware and everything you need to start trying things out, so my advice is to go for it! Time for some experiments :slight_smile:

Regarding any WiFly software libraries that are available; they all use exactly the same commands as you do over the serial port or telnet connection. So you can do everything the libraries can do. The libraries make it easier to use code in a sketch to change the WiFly configuration on the fly and pull status from the WiFly. They build text command strings and send them via serial to the WiFly, and read the text response and map it onto return codes and variables.

ok cool!
seems i'm on my way, being a noob the road is pretty long and the learning curve is pretty steep (imho) but hey, im learning a lot from this, which is my primary goal anyway! :slight_smile:
fyi: yesterday i started my c# backend app, build a nice class to handle (incoming) connections, which worked with a simple client app. 8)
Tonight i'm planning on coding methods for sending and receiving data. Once that's finished i can sink my teeth in some arduino code (if wlan == connected than connect to socket, once socket == connected, send back any incomming data)
Once i'm there i can think about sending commands for turning on / off a led.

Does this path sound logical or would you take a different approach?

again, thx for the help!

Heey Sponder

Seems u are not the only newbie. I was trying to send data from desktop app to arduino wirelessly using the wifly module. Last week I was able to successfully connect the module to my home network and viewing through my Dlink router configuration web page there it was on the list of web clients.

Now the problem was communicating with the module through telnet because I keep on getting "could not open connection to the host, on port 2000: connect failed". I cannot do much more without first solving this problem. DId you get such a problem?..what could be da way out of this?..

never had the problem, can't help you there.
However, i did myself a big favor by printing out the manual and i would suggest you do too! it's a great command reference.
Through serial you can check all the settings, but port 2000 is the default telnet port, so i would check if the unit would response to the network. Can you ping the unit?

Yah i was able to ping it but cannot communicate with it through telnet or TCP. For your info am using the WiFly Transparent Terminal Sketch provided on WiFly Wireless SpeakJet Server - SparkFun Electronics as a start. I followed every step till the telnet part where am currently stuck.

oh sorry am getting this message after pinging the wifly module..."Destination host unreachable" and i guess this means that it has failed to communicate with the device....Pardon me for any trivial mistakes as I am less experienced on networking techs....
When I was configuring the wifly, I set my pc's ip as the host ip address and assigned port 19999 as the remote port number...Isn't this enough to initiate connection between the wifly and the pc....thanks...

Could you do a " get everything" command using the serial port, and a "show net" command and post the output in a code box here (click on the hash symbol in the formatting options above the post).

Also, with any networking, each client or device every gets a unique IP address. If you configure the same IP address for both your pc and you WiFly, you have a ip conflict on the network. Check if a ip is free on the network before assigning it to the WiFly. You can also let your router play for DHCP server, and let that assign an IP address.

edit:
as an example: the output to dhunt's request would look like this:
(got it through telnet :stuck_out_tongue: but through serial you get the same output)

<2.30> show net
show net

SSid=SaikoWlan
Chan=5
Assoc=OK
Rate=12, 24Mb
Auth=OK
Mode=WPA2
DHCP=OK,renew=62155
Boot=2240
Time=FAIL
Links=1
<2.30> get everything
get everything

WiFly Ver 2.30, 10-26-2011 on RN-171
Beacon=100
Probe=5
Reboot=0
OPEN=*OPEN*
CLOSE=*CLOS*
REMOTE=*HELLO*
FlushSize=64
MatchChar=0
FlushTimer=10
IdleTimer=0
CmdChar=$
IF=UP
DHCP=ON
IP=10.0.0.7:2000
NM=255.255.255.0
GW=10.0.0.1
HOST=0.0.0.0:2000
PROTO=TCP,
MTU=1524
FLAGS=0x7
TCPMODE=0x0
BACKUP=0.0.0.0
DNS=10.0.0.1
Name=server1
Backup=backup2
FTP=208.109.78.34:21
File=wifly-EZX.img
User=roving
Pass=Pass123
Dir=public
Timeout=40
FTP_mode=0x0
SSID=SaikoWlan
Chan=0
ExtAnt=0
Join=1
Auth=WPA2
Mask=0x1fff
Rate=12, 24 Mb
Linkmon=0
Passphrase=<my password be gone  :P>
TxPower=0
SleepTmr=0
WakeTmr=0
Trigger=0x1
Autoconn=0
IoFunc=0x0
IoMask=0x21f0
IoValu=0x0
DebugReg=0x0
PrintLvl=0x1
TimeEna=0
TIMEADR=129.6.15.28:123
Zone=7
Baudrate=9600
Flow=0x0
Mode=0x0
JoinTmr=1000
Replace=0x24
DeviceId=WiFly-EZX
Password=
Format=0x0
Signal=0
Average=5
BCAST=255.255.255.255:55555
Interval=0x7
Sensor=0x0
SensePwr=0x0

dhunt, maybe you could help me out some more?
i understand the fact that i don't have to include the library, but instead i can write the commands to the serial link myself.
What i can't seem to figure out though (looked in the manual, on the internet, in the drivers) is how to retrieve the output properly. What kind of type is the output in? doesn't seem to be a simple string.
I have a lcd attached to my arduino, so for example, if i would like to show the ip or mac address:
lcd.print(Serial.print("get ip a")); //shows only ip, not the port nr
i get an 8 on my display?

hi sponder...i dont think there is any ip conflict as dhcp is "ON" meaning the ip is automatically assigned by the AP(Access Point)....

dhunt here is result after sending the 2 commands....

<2.23> get everything
WiFly Ver 2.23, 04-26-2011 on 131C11
Beacon=100
Probe=5
OPEN=*OPEN*
CLOSE=*CLOS*
REMOTE=*HELLO*
FlushSize=64
MatchChar=0
FlushTimer=10
IdleTimer=0
CmdChar=$
IF=UP
DHCP=ON
IP=192.168.1.9:2000
NM=255.255.255.0
GW=192.168.1.1
HOST=192.168.1.2:19999
PROTO=TCP,
MTU=1524
FLAGS=0x7
BACKUP=0.0.0.0
DNS=192.168.1.1
Name=server1
Backup=backup2
FTP=208.109.78.34:21
File=wifly-GSX.img
User=roving
Pass=Pass123
Dir=public
Timeout=40
FTP_mode=0x0
SSID=Alhabsy
Chan=0
ExtAnt=0
Join=1
Auth=WEP
Mask=0x1fff
Rate=12, 24 Mb
Linkmon=0
Keynum=1
Key=.......................................
SleepTmr=0
WakeTmr=0
Trigger=0x1
Autoconn=0
IoFunc=0x0
IoMask=0x20f0
IoValu=0x0
PrintLvl=0x1
TimeEna=0
TIMEADR=129.6.15.28:123
Zone=7
Baudrate=9600
Flow=0x0
Mode=0x0
JoinTmr=1000
Replace=0x24
DeviceId=WiFly-GSX
Password=
Format=0x0
Signal=0
Average=5
BCAST=255.255.255.255:55555
Interval=0x7
Sensor=0x0
SensePwr=0x0
<2.23> show net
SSid=Alhabsy
Chan=1
Assoc=OK
Rate=12, 24Mb
Auth=OK
Mode=WEP
DHCP=OK,renew=64694
Boot=667
Time=FAIL
Links=1
<2.23> show connection
8130

The 3rd command was for checking the connection status....following the reference guide, the result of the command is hexadecimal and its binary equivalent is 1000000100110000...the last 3 bits gives TCP status and judging from my result it is in 'idle' state...shouldn't it be active i mean connected....thanks

To answer your question sponder...i came across some one trying to read data from the wifly but they were using the wifly library to do it...they had some function (readFromWifly()...) that reads from the wifly and prints on the serial monitor....

have a look at the code posted by Gary_BSEE on this forum Troubleshooting the WiFly shield for Arduino - SparkFun Electronics Forum
let me know if it works coz am also planning to read data from the wifly...thanks...

mc63:
dhunt here is result after sending the 2 commands....

The config looks okay, although the firmware version is a bit old - it might pay to update the firmware and see if that helps.

So when you ping 192.168.1.9 you get no response, and telnet 192.168.1.9 2000 does not connect?

If you want to make a tcp connection automatically you will need to set the UART mode to autoconnect. Then when you send write to the WiFly via the serial port it will make a tcp connection to the host address and remote port (192.168.1.2:19999). Do you have something running on 192.168.1.2 to handle the connection?

The wireshark app from http://www.wireshark.org/ can help you monitor the packets sent by the WiFly and the responses from the PC.