wiFly not received until reset

I've got a project setup using the RN-121 wiFly module (from roving networks). I'm using the ATMega328 on strip-board.

I'm experiencing a strange problem where the ATmega starts up fine, I've put code on to make an LED flash, however only once I've pressed the reset button will the device start communicating with the wiFly module.

I haven't gone into any more detail as I'm just wondering at first if that sounds like a common issue where I've just forgotten to wire something in. To me, there doesn't seem to be anything obvious missing.

Thanks. L

Hi Luke

Can you provide an example of the sketch you’re running? Also, what are the LEDs on the WiFly indicating?

Cheers, Geoff

Ok there is a lot of code and after testing I cannot recreate the problem after writing a quick test script…So there is something wrong here:

It is quite long with a lot going on. As you can see the setup up script should send the " ***START UP 2 ***" message as soon as it boots. This only happens once the reset button has been pressed.

#include <Arduino.h>
#include <SoftwareSerial.h>

SoftwareSerial WiFly(2, 3); 

//Pin declarations
int led = 5;
int pan_led = 6;

//Mixer pins
int clk = 9;
int datapin_right = 13;
int ld = 10;
int datapin = 11;
int wrt = 12;

//Stored Values
int values[6];
int left[6];
int right[6];
float pan[6];

//Binary convertion
boolean address [8];
boolean data [8];
boolean data_right [8];

//Timing code
long interval = 500; 
long previousMillis = 0;        // will store last time LED was updated

//Standard Variables
int levels = 0;
char type;
char b[20];
int i = 0;
//Analogue in
const int analogIn1 = A1;
const int analogIn2 = A2;
const int analogIn3 = A3;
const int analogIn4 = A4;
const int analogIn5 = A5;

int sensorValue = 0;
int outputValue = 0;        // value output to the PWM (analog out)

void setup(){

  pinMode(clk, OUTPUT);
  pinMode(ld, OUTPUT);
  pinMode(datapin, OUTPUT);
  pinMode(datapin_right, OUTPUT);
  pinMode(wrt, OUTPUT);
  pinMode(led, OUTPUT);   
  pinMode(pan_led, OUTPUT); 
 
 WiFly.begin(9600);
  WiFly.write( "***START UP 2 ***"); 

}

void loop(){
  unsigned long currentMillis = millis();

  //Reset arrays
  for (int n=0; n<8; n++) {
    address[n] = 0;
    data[n]     =0;
    data_right[n]     =0;
  } 


   if (WiFly.available()){ 
    type = WiFly.read();

    if (type == '*'){ //detect connection started
      WiFly.write( "Welcome to the wiMix Network"); 
    }
    if (type == '?'){ //detect question asked
      i = 0; // refresh pointer to stop i growing
      WiFly.println("Response"); 
      digitalWrite(led,1);
    }
     if (type == '['){ //start sending level information
        levels = 1;
    }
         if (type == ']'){  //stop sending level information
        levels = 0;
    }
    if (type == 'f') { //Start receiving fader data
      i = 0;  //  pointer set at first position
      digitalWrite(led,0);
    }

    b[i] = type;
    i++;
     
    if (type == '!') { //Panning data received
      digitalWrite(pan_led,1);

      int readaddress = b[1] - '0';
      float readdata = (b[4] - '5')/5.00;
      pan[readaddress] = readdata;


      ///set value code///
      if(pan[readaddress]<0){
        address_binaryconv(readaddress);
        left[readaddress] = values[readaddress];
        right[readaddress] = (values[readaddress]) + (-pan[readaddress])*(31 - values[readaddress]); 
      }

      if(pan[readaddress]>0){ 
        address_binaryconv(readaddress);
        left[readaddress] = values[readaddress] + (pan[readaddress])*(31 - values[readaddress]);
        right[readaddress] = (values[readaddress]); 
      }

      address_binaryconv(readaddress);
      data_binaryconv(left[readaddress]);
      data_right_binaryconv(right[readaddress]);

      data[1] = 1;
      data_right[1] = 1;
      address[0]=1;

      send(data, data_right, address);
    }

    if (type == '#') { //Standard fader data received
      int i;

      if((b[2] != 'd' ) || (isdigit(b[4]) == false)) {
        return;
      }

      int readaddress = b[1] - '0';
      address_binaryconv(readaddress);

      int readdata = 0;
      if(isdigit(b[3])) 
        readdata = (b[4] - '0') + (10 * (b[3] - '0'));
      else
        readdata = (b[4] - '0');
      data_binaryconv(readdata);

      values[readaddress] = readdata;

      data[1] = 1;
      data_right[1] = 1;
      if (readdata == 31 && readaddress != 0)
        data[1] = 0;

      address[0]=1;


      send(data, data, address);

    }
  }
  
    if((currentMillis - previousMillis > interval) && (levels == 1)) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   
    WiFly.print("f");
    sensorValue = analogRead(analogIn1); 
    outputValue = constrain(map(sensorValue, 0, 100, 0, 9),0,9);  
    WiFly.print(outputValue);     
    sensorValue = analogRead(analogIn2); 
    outputValue = constrain(map(sensorValue, 0, 100, 0, 9),0,9);  
    Serial.println(sensorValue);
    sensorValue = analogRead(analogIn3); 
    outputValue = constrain(map(sensorValue, 0, 100, 0, 9),0,9);  
    WiFly.print(outputValue);    
    sensorValue = analogRead(analogIn4); 
    outputValue = constrain(map(sensorValue, 0, 100, 0, 9),0,9);  
    WiFly.print(outputValue);    
    sensorValue = analogRead(analogIn5); 
    outputValue = constrain(map(sensorValue, 0, 100, 0, 9),0,9);  
    WiFly.println(outputValue);    

  }
}

I've not read your sketch in depth, but my WiFly wouldn't have connected to the WLAN by the time the sketch got to setup() where you're outputting that string, so I shouldn't expect it to return anything at that stage. I wonder if when you hit reset it just flushes the output buffer out and that's what you're seeing.

Does your WiFly module have lights which indicate a successful connection to the network? I have a WiFly bee which appears to have the same LEDs yours has (according to p6 here http://www.sparkfun.com/datasheets/Wireless/WiFi/WiFlyGSX-um2.pdf) so you should be seeing a slow green LED flash with no reds when you're associated successfully.

The WiFly is setup in ad-hoc mode but it is possible to see when the wiFly receives data over the serial connection as the orange light blinks. I can have the WiFLy connected to a device and receiving data but the arduino will not respond until the reset button has been pressed.