Go Down

Topic: WiFly Shield: can't get it work. (Read 20655 times) previous topic - next topic

NNzz

Good Afternoon,

I'm currently having a lot of troubles with my WiFly Shield. It is the first time I work with Arduino Hardware but I actually need it this time ;-). Well the thing i'm trying to do is simply to connect to my Wifi through javascript:void(0);the WiFly Shield, I can't get it work though.

First question is : how pins have to be connected between the UNO and my Shield ? I put the Shield above the UNO and plugged every pins together with components which look like combs. I don't know the word for that, sorry. Well to sum up, Vin is pluged with Vin, GND with GND, etc.

To use the Wifi, I tried 2 methods. First one, I tried to use the WiFly library and used this code:
Code: [Select]
/*
* based on:
*
* WiFly Autoconnect Example
* Copyright (c) 2010 SparkFun Electronics.  All right reserved.
* Written by Chris Taylor
*
* This code was written to demonstrate the WiFly Shield from SparkFun Electronics
*
* This code will initialise and test the SC16IS750 UART-SPI bridge, and automatically
* connect to a WiFi network using the parameters given in the global variables.
*
* http://www.sparkfun.com
*/

#include "WiFly.h"


#include "Credentials.h"


void setup() {

 Serial.begin(9600);
 Serial.println("\n\r\n\rWiFly Shield Terminal Routine");
 
 WiFly.begin();
 
 if (!WiFly.join(ssid, passphrase)) {
   Serial.println("Association failed.");
   while (1) {
     // Hang on failure.
   }
 }
 
 Serial.println("Associated!");
}


void loop() {
 // Terminal routine

 // Always display a response uninterrupted by typing
 // but note that this makes the terminal unresponsive
 // while a response is being received.
 while(SpiSerial.available() > 0) {
   Serial.print(SpiSerial.read(), BYTE);
 }
 
 if(Serial.available()) { // Outgoing data
   SpiSerial.print(Serial.read(), BYTE);
 }
}


It's stuck on WiFly.begin().

As a consequence, I used the debugging terminal but it's stuck on SPI_Uart(), I can not connect to it... And I don't know why.


The other method I used is the SparkFun tutorial so I used this code here :

http://www.sparkfun.com/commerce/images/WiFly_Tutorial_Files/WiFly_Auto_Connect.zip
But I get : "Could not initialize bridge, locking up."


Anyone has an idea ?

Have a nice day.

I'm having the same problem. I've done a bunch of Arduino projects and NEVER had this much trouble getting a component to work. I've tried pretty much everything I can think of, but nothing works. Let's stay with the debugging terminal example that comes with the alpha-2 release of the WiFly library. Here's what I've done:

1. Installed WiFly alpha-2 in the package contents/resources/java/libraries directory. (the README still has the old version number in it, which was very confusing when I was trying to look at them side by side in my text editor)

2. Connected WiFly (RN-131C) breakout to Arduino Duo with a 6 and an 8 pin connectors.

3. Getting the P104 and P106 lights flashing (see the docs for what the flashing means- it's not affecting me directly yet since I haven't connected to an networks).

4. Selected examples > WiFly > tools > SpiUartTerminal sketch and uploaded to board (after restarting the Arduino IDE to get the library to stick).

5. Waited for the TX light to go off, opened the serial monitor, and have been greeted in each attempt with the "locking up" message.

I'm using Arduino 22 on a Mac running 10.6.7, FYI.

I have a feeling that a lot of the documentation and troubleshooting is based around the retired WiFly shield, but I can't be sure. Seems like nothing I try doe any good. Anybody got any ideas? @NNzz, did you ever figure out how to get this working?

Thanks in advance.

TeslaFan

i tried to get the example code and the other library going for about 10 minutes, then totally abandoned them.

Instead, I looked at the schematic and the WiFly module's reference documentation, then pulled the code that actually makes the SPI and UART work out of the libraries and put it in one place, there's not very much of it. It's actually pretty simple. You just have to figure out how the SPI and the UART work.

If you look here:

http://roboticcore.com/?p=53

Find the WiFlyGateway and download the code. The file that contains ALL the SPI and UART initialization and manipulation is CommManager.cpp and .h

If you're looking for a "Black Box" solution for the WiFly, I don't think you're going to find it. And for the simple reason that every system that uses a WiFly is going to be a bit different, look at mine... I also connect to additional SPI UARTS, something none of the libraries seem to support. There is also a WiFlySerial library that someone wrote, but it requires the breakout board version of the WiFly, not the shield.

Once you have the WiFly running and in Command Mode on the serial terminal, program it with the particulars for your WiFi network using the instructions in the Reference manual for the module, then use the "save" command to save the new parameters. Then when the WiFly is power cycled, it will auto-associate with the hub and you're ready to connect it to whatever server it's going to.

Take it one step at a time:

1) Get the SPI to work.
2) Get the SPI UART to work.
3) Get the Serial Monitor to talk to the WiFly.
4) Program the WiFly to connect to your WiFi. Remember to use the "save" command.
5) Power cycle the Shield and watch it connect.

Linux and Arduino, two great things that go great together!
http://www.roboticcore.com

Thanks Tesla- I'll have a try and post my findings here.

Okay here's where I am now:

In CommManager.cpp, I got some errors when I compiled the sketch. It was something like "PB1 undeclared in this scope", and after a but of reading, I found that new you have to use PORTB1 etc. instead of PB1. Changed where that PB got declared through lines 160-194, recompiled and got no errors.

Uploaded to the board, and here's the output from the serial monitor:

UART 10 read test (55) = ff
UART 9 read test (55) = ff

And then a whole bunch of those umlaut y's and the IDE freezes so I can't enter command mode with the WiFly. Any ideas?

M

dodos

I am having the same problem. Anybody got it working?

smd

Hi all,


It's stuck on WiFly.begin().


Had exactly the same problem, think I got it fixed - so I thought I'd document my steps.

So, I get a WiFly, and I get the code from GitHub. With the intent to use it on the Arduino MEGA 2560, I resolder D13, D12, D11, D10 on the shield to D52, D50, D51, D53 on the MEGA 2560 as explained in  src/WiFly/README.txt. I copy the folder WiFly-Shield/src/WiFly from the code to arduino-0022/libraries; and I decide to try src/WiFly/examples/tools/SpiUartTerminal.pde... and, I experience the freeze on WiFly.begin().

Well, since the main communication between the Arduino and the WiFly is via SPI, I decide to check the SPI pins on an oscilloscope. I would have expected at least the SCLK clock (D13 on Uno, D52 on Mega) to be shown pulsing - but surprisingly, all of the pins showed DC voltage. Then I thought about trying the default SPI examples in arduino-0022, so I chose SPI/examples/BarometricPressureSensor.pde. Immmediately after building and uploading this sketch, I could see SCLK pulses on D52 on the Mega; so my conclusion was, there must be a problem with the SPI initialization in the WiFly library.

Thus, I began a somewhat tedious process of comparing the default SPI library in the Arduino IDE, and the SPI related parts of the WiFly library. My initial guess was, that the SCLK pulses start immediately after a succesful .begin() has been initiated; however, actual pulses (that I could catch on the scope) usually occur when a .transfer() command executing in the loop(). So I made me a small .pde program, to have the same .begin in setup(), and .transfer in loop() implemented through either library for comparison - and I could realize that, as concluded earlier, .begin() from WiFLy simply never returns - here's the test code I used, called it spi_test_wi.pde:

Code: [Select]

// comment/uncomment the define as needed:
#define WIFLY
//#define DFLTSPI

#ifdef DFLTSPI
// from Examples/SPI/BarometricPressureSensor.pde
// the sensor communicates using SPI, so include the library:
#include <SPI.h>

void setup() {

  // start the SPI library:
  SPI.begin();

}
#endif

#ifdef WIFLY
// from Examples/WiFly/WiFly-examples/tools/SpiUartTerminal.pde
#include "WiFly.h" // We use this for the preinstantiated SpiSerial object.

void setup() {

  // start the SPI library:
  SpiSerial.begin();

  // if these functions are made public in SpiUart.h, they
  // will then show pulses in this loop here..
  while(!SpiSerial.uartConnected()){
    SpiSerial.configureUart(9600);
  }

}
#endif

void loop() {
#ifdef DFLTSPI
  SPI.transfer(0x00);
#endif

#ifdef WIFLY
// class SpiUartDevice : public SpiDevice, public Print
// overloads SpiDevice, which has SpiDevice::transfer
  SpiSerial.transfer(0x00); // ok if setup doesn't lock
  ////SpiSerial.writeRegister(LCR, 1 << 7); //private :(
  ////SpiSerial.print(0x00); //ok if setup doesn't lock; big delays
  //SpiSerial.write("hello"); //ok if setup doesn't lock; big delays
  //SpiSerial.configureUart(9600); //private
#endif

  ;
  //asm("nop"); //delay? not much ..
}


So, I decide to look closer in SpiSerial.begin(); - that function eventually calls SpiUartDevice::initUart, where a comment can be read: "// Lock up if we fail to initialise SPI UART bridge.", this lock up being entering a while(1) loop. So, I basically decide to comment this loop in arduino-0022/libraries/WiFly/SpiUart.cpp:

Code: [Select]

void SpiUartDevice::initUart(unsigned long baudrate) {
  /*

    Initialise the UART.

    If initialisation fails this method does not return.

   */
  // Initialise and test SC16IS750
  configureUart(baudrate);

  if(!uartConnected()){
    //~ while(1) {
      //~ // Lock up if we fail to initialise SPI UART bridge. <======
    //~ };
  }

  // The SPI UART bridge is now successfully initialised.
}


... and move the running of uartConnected() check in the main .pde code; however, since this function is by default private, it needs to be made public for that - so in arduino-0022/libraries/WiFly/SpiUart.h simply move the uartConnected() and  configureUart() above the private keyword:

Code: [Select]

...
    void ioSetState(unsigned char bits);

    void configureUart(unsigned long baudrate);
    boolean uartConnected();
  private:
    void writeRegister(byte registerAddress, byte data);
...


Now, we can go back to the good old SpiUartTerminal.pde; except now we'd need to modify the connection procedure in setup() as such:

Code: [Select]

...
  Serial.println("Attempting to connect to SPI UART...");
  SpiSerial.begin(); //hack in SpiUart.cpp so it don't lock
  // hack below: repeat configuration until it passes
  while(!SpiSerial.uartConnected()){
    SpiSerial.configureUart(9600);
  }
  // end hack

  Serial.println("Connected to SPI UART.");
...


Finally, with these changes, I could see SCLK pulses immediately after upload; and of course, the entire connection procedure passed - and I could execute the WiFly commands and connect to a wireless router as described in WiFly Tutorial - Wireless SpeakJet Server - SparkFun Electronics. (Note I had to change my router from WEP 64 bit to WEP 128 bit, as that is the only WEP WiFly supports; and then there is difference between key/passphrase command). Here tested telnet wireless access via  SpiUartTerminal.pde, worked fine.

With this done, I also tried the Examples/WiFly/WiFly-examples/WiFly_WebServer, which samples analog inputs and sends them to a client over wireless - the good thing is that the above SpiUart.cpp hack seems to propagate to the WiFly class as well; unfortunately, I couldn't measure more than 2.7 kByte/sec transfer speed over wireless, even with specifying WiFly.configure(WIFLY_BAUD, 38400);.

In any case, glad I could get this to run - so hope this writeup would be of use to others :) ,
Cheers!

Go Up