Wifly stops trouble shooting, hardware problem? code problem?

Hello guys,

Could anyone help me trouble shooting for WIfly shield with LEDs? I'm in trouble but not sure what's the reasons and where to start (code? or hardware?).

[u]Problem:[/u] LEDs with Wifly shield works as intended for a bit but will loose connection after while.

[u]Program:[/u] Arduino POST to the web address and get some numbers from there via wifi, then show them on segments LEDs. LED matrixes display some graphics according to the numbers. (too much to put all here but I can snip my code if you need to see)

[u]Hardwares:[/u] Arduino with Wifly shield 4 x digits of segments LEDs. 4 x 7 by 5 dots matrix LEDs. LED drivers for each with capacitors and resistors. circuit to split the external power to Arduino and LED 9V 0.5A power supply

[u]What I've found so far:[/u] I prepared two sets of Arduino + Wifly with exact same codes on them. A: a board and a shield with all LEDs and components powered by 9V b: without any LEDs or components, just a board and a shield connect to computer via USB to check in the serial monitor

  1. 'A' stops within 20 - 30 mins much quicker than another plain one. 'B' lasts for 1 - 4 hours.

  2. After stop when I pressed the reset button on boards. 'A' doesn't recover connection, just reset LEDs 'B' recovered, and started to download and show data again

  3. if I unplug the power and plug again, 'A' also started to work again.

  4. The point of stops in the code is random.

[u]To sum up with:[/u] - Wifi connection is lost and stops to download data in random point regardless of LEDs are connected or not anyway. - But the one without LEDs lasts much longer time than one with LEDs.

I'm guessing it's some memory problem or power problem but still not sure what exactly wrong.

Could anyone have any ideas what’s the problem?

I’ll really appreciate if anyone could give me some suggestions and where to start. I can provide any more details if you need, and will update by your suggestions.

Thanks in advance

I'm guessing it's some memory problem or power problem but still not sure what exactly wrong.

Sounds reasonable. We need to see the code.

Thanks for your reply PaulS!

I think it makes here too messy and maybe you feel too much if I put all code here at once.
So, I’m trying to put some parts of codes that possibly there are problems in.

Firstly here is the main loops.

#include "WiFly.h"
#include "Credentials.h"
Client client("xxxx.com", 5000); //port is 5000

boolean animation= false;

void setup() {
  pinMode(14,OUTPUT);
  pinMode(15,OUTPUT);
  pinMode(16,OUTPUT);
  pinMode(17,OUTPUT);
  pinMode(18,OUTPUT);
  pinMode(19,OUTPUT);
  Serial.begin(9600);
  segSetup();    // setup for 7-segments LEDs
  faceSetup();  //  setup for "face" that shown in LED matrix depending on numbers
  wiflySetup(); // setup for wifly
}


void loop()
{
  if(!animation){   // if number is changed it shows numbers between numbers as animation (eg. if number changes from 7 to 4, it shows 6, 5 before shows 4)
    asciiToInt();  // convert ascii data to int value
    wiflyLoop();  // updating data from wifi
    delay(1);
  }
  else{
    segDisplay(); // update segments LED
    faceDisplay(); // update matrix LED
  }
}

And here are functions for wifly

void wiflySetup()
{
  WiFly.begin();

  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Association failed.");
    while (1) {
      // Hang on failure.
    }
  }
  Serial.println("connecting...");
  wiflyUpdate();
}


void wiflyUpdate()
{
  client.flush();
  Serial.flush();
  Serial.println("updating...");
 //post "id=0" to "xxxx.com:5000/retrieveNumbers"
  char body[] = "id=0";
  if (client.connect()) {
    Serial.println("connected");
    client.println("POST /retrieveNumbers HTTP/1.1");
    client.println("Host: xxxx.com");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length:");
    client.println(sizeof(body)-1,DEC);
    client.println();
    client.println(body);
  } 
  else
  {
    Serial.println("connection failed");
  }
}



void wiflyLoop()
{
  if (!client.connected()){
    Serial.println("unconnected - will be updated");
    client.stop();
    skipCount=0;
    delay(1000);     
    wiflyUpdate();
  }
}

And here are functions converting ascii from int.
Returned numbers from server by POST method is like:
[11649, 9000]
The code deal with these two numbers (please don’t ask what these two means to avoid further confusion)
The first number (11649 here) is dynamicNum
The second number (9000) is staticNum

Each character stores into an array separately “1”, “1”, “6” …

What doing here is basically getting numbers and make them together as int (actually long)
(1 * 10000) + (1 * 1000) + (6 * 100) + (4 * 10) + (9 * 1) = 11649

String number;
int skipCount= 0;
int numSkipLines=7;
int page=0;

int arrayMax=5;
int array[5];
int charLength=0;
long dynamicNum=0;
long staticNum=5000;
boolean passComma;


void asciiToInt(){
  if (client.available()){
    char c = client.read();
    if(c==0x0A) skipCount++;
    if(skipCount>numSkipLines){
      if ((int)c>= 48 && (int)c<= 57 || int(c)== 44 || int(c)== 93){ // if (int)c is "0-9" or "," or "]"… 0 is 48 and 9 is 57 in ascii, for example
        if(int(c)==44){ // when catching "," as the end of the first value
          dynamicNum= 0;
          if(charLength==5){
            dynamicNum= array[0]*10000;
            dynamicNum+= array[1]*1000;
            dynamicNum+= array[2]*100;
            dynamicNum+= array[3]*10;
            dynamicNum+= array[4]*1;
            printResults(); // function just for printing data with Serial.print
            segDisplay(); //update segments LED
            resetValues();
          }
  	  else if(charLength==4){
            dynamicNum= array[0]*1000;
            dynamicNum+= array[1]*100;
            dynamicNum+= array[2]*10;
            dynamicNum+= array[3]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else if(charLength==3){
            dynamicNum= array[0]*100;
            dynamicNum+= array[1]*10;
            dynamicNum+= array[2]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else if(charLength==2){
            dynamicNum= array[0]*10;
            dynamicNum+= array[1]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else if(charLength==1){
            dynamicNum= array[0]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else{
            Serial.println("error");
          }
        }

        else if(int(c)==93){ // when catching "]" as the end of data
          staticNum= 0;
          if(charLength==5){
            staticNum= array[0]*10000;
            staticNum+= array[1]*1000;
            staticNum+= array[2]*100;
            staticNum+= array[3]*10;
            staticNum+= array[4]*1;
            printResults();
            resetValues();
          }
          else if(charLength==4){
            staticNum= array[0]*1000;
            staticNum+= array[1]*100;
            staticNum+= array[2]*10;
            staticNum+= array[3]*1;
            printResults();
            resetValues();
          }
          else if(charLength==3){
            staticNum= array[0]*100;
            staticNum+= array[1]*10;
            staticNum+= array[2]*1;
            printResults();
            resetValues();
          }
          else if(charLength==2){
            staticNum= array[0]*10;
            staticNum+= array[1]*1;
            printResults();
            resetValues();
          }
          else if(charLength==1){
            staticNum= array[0]*1;
            printResults();
            resetValues();
          }
          else{
            Serial.println("error");
          }
        }
        else{ // "0,1,2,3,4,5,6,7,8,9"
          array[charLength]= (int)c-48;
          charLength++;
        }
      }
    }
  }
}


void resetValues(){
  charLength= 0;
  passComma= true;
  for(int i=0; i<arrayMax; i++) array[i]=0;
}

If you need to see more codes or descriptions please just let me know.

Thanks

You have a lot of code to re-implement the atoi() function. Why not just call that function?

          array[charLength]= (int)c-48;

would be a lot more readable as:

          array[charLength]= c - '0';

Thanks PaulS!

Yes, that’s definitely much more readable.
I remember I was too struggling with this and maybe it directed me to even more complicated way…

I just rewrite the simpler version here for future references.

Do you see any other memory wastes or anything that can cause the problem so far?

Thanks

////////////////////////////////////////
And here are functions converting ascii from int.
Returned numbers from server by POST method is like:
[11649, 9000]
The code deal with these two numbers (please don’t ask what these two means to avoid further confusion)
The first number (11649 here) is dynamicNum
The second number (9000) is staticNum

Each character stores into an array separately “1”, “1”, “6” …

What doing here is basically getting numbers and make them together as int (actually long)
(1 * 10000) + (1 * 1000) + (6 * 100) + (4 * 10) + (9 * 1) = 11649

String number;
int skipCount= 0;
int numSkipLines=7;
int page=0;

int arrayMax=5;
int array[5];
int charLength=0;
long dynamicNum=0;
long staticNum=5000;
boolean passComma;


void asciiToInt(){
  if (client.available()){
    char c = client.read();
    if(c==0x0A) skipCount++; //0x0A is 'new line'
    if(skipCount>numSkipLines){
      if (c >= '0' && c <= '9' || c == ',' || c == ']'){
        if(c == ','){    // when catching "," as the end of the first value
          dynamicNum= 0;
          if(charLength==5){
            dynamicNum= array[0]*10000;
            dynamicNum+= array[1]*1000;
            dynamicNum+= array[2]*100;
            dynamicNum+= array[3]*10;
            dynamicNum+= array[4]*1;
            printResults(); // function just for printing data with Serial.print
            segDisplay(); //update segments LED
            resetValues();
          }
  	  else if(charLength==4){
            dynamicNum= array[0]*1000;
            dynamicNum+= array[1]*100;
            dynamicNum+= array[2]*10;
            dynamicNum+= array[3]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else if(charLength==3){
            dynamicNum= array[0]*100;
            dynamicNum+= array[1]*10;
            dynamicNum+= array[2]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else if(charLength==2){
            dynamicNum= array[0]*10;
            dynamicNum+= array[1]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else if(charLength==1){
            dynamicNum= array[0]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else{
            Serial.println("error");
          }
        }

        else if(c == ']')
          staticNum= 0;
          if(charLength==5){
            staticNum= array[0]*10000;
            staticNum+= array[1]*1000;
            staticNum+= array[2]*100;
            staticNum+= array[3]*10;
            staticNum+= array[4]*1;
            printResults();
            resetValues();
          }
          else if(charLength==4){
            staticNum= array[0]*1000;
            staticNum+= array[1]*100;
            staticNum+= array[2]*10;
            staticNum+= array[3]*1;
            printResults();
            resetValues();
          }
          else if(charLength==3){
            staticNum= array[0]*100;
            staticNum+= array[1]*10;
            staticNum+= array[2]*1;
            printResults();
            resetValues();
          }
          else if(charLength==2){
            staticNum= array[0]*10;
            staticNum+= array[1]*1;
            printResults();
            resetValues();
          }
          else if(charLength==1){
            staticNum= array[0]*1;
            printResults();
            resetValues();
          }
          else{
            Serial.println("error");
          }
        }
        else{ // "0,1,2,3,4,5,6,7,8,9"
          array[charLength]= c - '0';
          charLength++;
        }
      }
    }
  }
}


void resetValues(){
  charLength= 0;
  passComma= true;
  for(int i=0; i<arrayMax; i++) array[i]=0;
}

This code:

          dynamicNum= 0;
          if(charLength==5){
            dynamicNum= array[0]*10000;
            dynamicNum+= array[1]*1000;
            dynamicNum+= array[2]*100;
            dynamicNum+= array[3]*10;
            dynamicNum+= array[4]*1;
            printResults(); // function just for printing data with Serial.print
            segDisplay(); //update segments LED
            resetValues();
          }
     else if(charLength==4){
            dynamicNum= array[0]*1000;
            dynamicNum+= array[1]*100;
            dynamicNum+= array[2]*10;
            dynamicNum+= array[3]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else if(charLength==3){
            dynamicNum= array[0]*100;
            dynamicNum+= array[1]*10;
            dynamicNum+= array[2]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else if(charLength==2){
            dynamicNum= array[0]*10;
            dynamicNum+= array[1]*1;
            printResults();
            segDisplay();
            resetValues();
          }
          else if(charLength==1){
            dynamicNum= array[0]*1;
            printResults();
            segDisplay();
            resetValues();
          }

can be replaced by this code:

            dynamicNum = atoi(array);
            printResults();
            segDisplay();
            resetValues();

if you make array one element larger, and change this:

          array[charLength]= c - '0';
          charLength++;

to this:

          array[charLength]= c - '0';
          charLength++;
          array[charLength] = '\0';

Thanks again PaulS!

I just back to my desk now and tried atoi() function.

I was not sure c++ function but it actually gets much simpler and nicer!

So here is the latest version.
//////////////////////////////////////////
And here are functions converting ascii from int.
Returned numbers from server by POST method is like:
[11649, 9000]
The code deal with these two numbers (please don’t ask what these two means to avoid further confusion)
The first number (11649 here) is dynamicNum
The second number (9000) is staticNum

int skipCount= 0;
int numSkipLines=7;

int arrayMax=5;
char array[5];

int charLength=0;
long dynamicNum=0;
long pWatt=5000;
long staticNum=5000;

void asciiToInt(){
  if (client.available()){
    char c = client.read();
    if(c==0x0A) skipCount++;
    if(skipCount>numSkipLines){
      if (c >= '0' && c <= '9' || c == ',' || c == ']'){
        if(c == ','){ // when catching "," as the end of the first value
            dynamicNum= atoi(array);
            printResults();
            segDisplay();
            resetValues();
        }
        else if(c == ']'){
            staticNum= atoi(array);
            printResults();
            segDisplay();
            resetValues();
        }
        else{ // "0,1,2,3,4,5,6,7,8,9"
          array[charLength]= c;
          charLength++;
        }
      }
    }
  }
}


void resetValues(){
  charLength= 0;
  for(int i=0; i<arrayMax; i++) array[i]= 0;
}

I just needed to change the array from int to char to use atoi().
from:

int array[5];
...
        else{ // "0,1,2,3,4,5,6,7,8,9"
          array[charLength]= c - '0';
          charLength++;
        }

to:

char array[5];
...
        else{ // "0,1,2,3,4,5,6,7,8,9"
          array[charLength]= c;
          charLength++;
        }

When do I need to make the array one element larger as you suggested?

And my code gets much more sophisticated now but still wifi keep stopping:-(
Do you have any idea what the other possible reasons?

Thanks

When do I need to make the array one element larger as you suggested?

Because you ignored the part about needing to add a NULL terminator after each character.

The C string functions (including atoi) operate on strings, which are NULL-terminated arrays of characters. You now have an array of characters, but it is not NULL terminated.

Since the array can hold 5 characters, the incoming string "11649" will fill the array, with no room for the terminating NULL. So, you need to make the array one element larger. And, add the NULL terminator.

Ok, I updated from the code above to like this:

char array[6];
...

else{ // "0,1,2,3,4,5,6,7,8,9"
          array[charLength]= c;
          charLength++;
          array[charLength] = '\0';
        }
...

I didn't know the idea of NULL terminated, so it's really good to know.

Thanks a lot PaulS!

And my code gets much more sophisticated now but still wifi keep stopping

As it gets “more sophisticated”, it also gets smaller/shorter. If there are still problems, you need to post more of (all!) it.

I’m glad you’re helping me out :slight_smile:

Here are the rest of codes.
These are basically control LEDs and involve libraries for them.

This is the codes to control segment LEDs.
Descriptions of the library is here: http://www.arduino.cc/playground/Main/LedControl#Seg7Control

#include "LedControl.h"

int pinDigitDataIn= 16;
int pinDigitClock= 15;
int pinDigitCS= 14;
int numDigitDevices= 1;

LedControl digit=LedControl(pinDigitDataIn, pinDigitClock, pinDigitCS, numDigitDevices);

int numDigit= 4; // numbers of segment LEDs

boolean firstTime= true;


void segSetup(){
  digit.shutdown(0,false);
  digit.setIntensity(0,15);
  digit.clearDisplay(0);
  displayLoad();
}

void displayLoad(){
  digit.setChar(0,0,'L',false);
  digit.setChar(0,1, 0,false);
  digit.setChar(0,2,'a',false);
  digit.setChar(0,3,'d',false);
}


void segDisplay(){
  if(pdynamicNum!=dynamicNum){
    animation= true;
    segAnimation();
  }
  else{
    animation= false;
  }
}



void segAnimation(){
  if (firstTime){
    pdynamicNum= dynamicNum;
    firstTime= false;
  }
  delay(1);
  if(pdynamicNum<dynamicNum) pdynamicNum++;
  if(pdynamicNum>dynamicNum) pdynamicNum--;

  assignDigitsToArrays();
  assignArraysToSegments();
}


// I only have 4 digits LEDs, so the LEDs just shows only top 4 of 5 numbers (eg. 12345 -> 1234, 9876 -> 987)


void assignDigitsToArrays(){ 
  int n= pdynamicNum;
  int j= numDigit;
  while(j>=0){
    array[j]= n%10;
    n/=10;
    j--;
  }  
}


void assignArraysToSegments(){
  if(array[0] == 0){
    digit.setChar(0,0,' ',false);
  }
  else{
    digit.setDigit(0,0,array[0],false);
  }
  digit.setDigit(0,1,array[1],true);
  digit.setDigit(0,2,array[2],false);
  digit.setDigit(0,3,array[3],false);

}

And these are the codes to control 4 matrix LEDs.

LEDs composes a face and each are left/right eye, leftside/rightside of a mouth
The expression of the face changes according to the dynamicNum to compare with staticNum
I’m using another library: Matrix \ Libraries \ Wiring

#include <Sprite.h>
#include <Matrix.h>

//Matrix(din, clk, load);
Matrix rEye = Matrix(2, 3, 4);
Matrix lEye = Matrix(17, 18, 19);
Matrix lMouth = Matrix(5, 7, 6); 
Matrix rMouth = Matrix(8, 10, 9); 

int faceMode= 2;
int pFaceMode= 2;


void faceSetup(){
  refresh();
  neutral();
}


void refresh(){
  lEye.clear();
  rEye.clear();
  lMouth.clear();
  rMouth.clear();
}


void faceDisplay(){
  faceModeChange();
  if(faceMode != pFaceMode){
  Serial.println("");
  Serial.print("faceMode: ");
  Serial.println(faceMode);
  Serial.println("");
  refresh();

    if (faceMode== 0) {
      exatic();
      pFaceMode= 0;
    } 
    else if (faceMode== 1) {
      zen();
      pFaceMode= 1;
    } 
    else if (faceMode== 2) {
      neutral();
      pFaceMode= 2;
    }
    else if (faceMode== 3){
      sad();
      pFaceMode= 3;
    } 
    else if (faceMode== 4){
      cross();
      pFaceMode= 4;
    }
  }
}


// The expression of the face changes according to the dynamicNum to compare with staticNum
void faceModeChange(){
    if(dynamicNum < staticNum *0.7) faceMode = 0; //exatic
  else if(dynamicNum < staticNum *0.9) faceMode = 1; //zen
  else if(dynamicNum < staticNum *1.1) faceMode = 2; //neutral
  else if(dynamicNum < staticNum *1.2) faceMode = 3; // sad
  else faceMode = 4; //cross
}


void exatic(){
  lEye.write(1, 2, HIGH);
  lEye.write(2, 1, HIGH);
  lEye.write(3, 1, HIGH);
  lEye.write(4, 1, HIGH);
  lEye.write(5, 2, HIGH);

  rEye.write(1, 2, HIGH);
  rEye.write(2, 1, HIGH);
  rEye.write(3, 1, HIGH);
  rEye.write(4, 1, HIGH);
  rEye.write(5, 2, HIGH);

  lMouth.write(2, 1, HIGH);
  lMouth.write(3, 1, HIGH);
  lMouth.write(4, 1, HIGH);
  lMouth.write(5, 1, HIGH);
  lMouth.write(6, 1, HIGH);
  rMouth.write(0, 1, HIGH);
  rMouth.write(1, 1, HIGH);
  rMouth.write(2, 1, HIGH);
  rMouth.write(3, 1, HIGH);
  rMouth.write(4, 1, HIGH);

  lMouth.write(3, 2, HIGH);
  lMouth.write(4, 3, HIGH);
  lMouth.write(5, 3, HIGH);
  lMouth.write(6, 3, HIGH);
  rMouth.write(0, 3, HIGH);
  rMouth.write(1, 3, HIGH);
  rMouth.write(2, 3, HIGH);
  rMouth.write(3, 2, HIGH);

  lMouth.write(5, 4, HIGH);
  lMouth.write(6, 4, HIGH);
  rMouth.write(0, 4, HIGH);
  rMouth.write(1, 4, HIGH);
}


void zen(){
  lEye.write(1, 0, HIGH);
  lEye.write(2, 1, HIGH);
  lEye.write(3, 1, HIGH);
  lEye.write(4, 1, HIGH);
  lEye.write(5, 0, HIGH);

  rEye.write(1, 0, HIGH);
  rEye.write(2, 1, HIGH);
  rEye.write(3, 1, HIGH);
  rEye.write(4, 1, HIGH);
  rEye.write(5, 0, HIGH);

  lMouth.write(3, 0, HIGH);
  lMouth.write(4, 1, HIGH);
  lMouth.write(5, 1, HIGH);
  lMouth.write(6, 1, HIGH);

  rMouth.write(0, 1, HIGH);
  rMouth.write(1, 1, HIGH);
  rMouth.write(2, 1, HIGH);
  rMouth.write(3, 0, HIGH);
}

void neutral(){
  lEye.write(2, 1, HIGH);
  lEye.write(3, 1, HIGH);
  lEye.write(2, 2, HIGH);
  lEye.write(3, 2, HIGH);

  rEye.write(3, 1, HIGH);
  rEye.write(4, 1, HIGH);
  rEye.write(3, 2, HIGH);
  rEye.write(4, 2, HIGH);

  lMouth.write(3, 1, HIGH);
  lMouth.write(3, 3, HIGH);
  lMouth.write(4, 2, HIGH);
  lMouth.write(5, 2, HIGH);
  lMouth.write(6, 2, HIGH);

  rMouth.write(0, 2, HIGH);
  rMouth.write(1, 2, HIGH);
  rMouth.write(2, 2, HIGH);
  rMouth.write(3, 1, HIGH);
  rMouth.write(3, 3, HIGH);
}

void sad(){
  lEye.write(1, 0, HIGH);
  lEye.write(2, 1, HIGH);
  lEye.write(3, 1, HIGH);
  lEye.write(4, 0, HIGH);

  rEye.write(2, 0, HIGH);
  rEye.write(3, 1, HIGH);
  rEye.write(4, 1, HIGH);
  rEye.write(5, 0, HIGH);

  lMouth.write(3, 3, HIGH);
  lMouth.write(4, 2, HIGH);
  lMouth.write(5, 2, HIGH);
  lMouth.write(6, 2, HIGH);

  rMouth.write(0, 2, HIGH);
  rMouth.write(1, 2, HIGH);
  rMouth.write(2, 2, HIGH);
  rMouth.write(3, 3, HIGH);
}

void cross(){
  lEye.write(0, 1, HIGH);
  lEye.write(1, 1, HIGH);
  lEye.write(2, 1, HIGH);
  lEye.write(3, 1, HIGH);
  lEye.write(4, 1, HIGH);
  lEye.write(5, 1, HIGH);
  lEye.write(6, 1, HIGH);

  rEye.write(0, 1, HIGH);
  rEye.write(1, 1, HIGH);
  rEye.write(2, 1, HIGH);
  rEye.write(3, 1, HIGH);
  rEye.write(4, 1, HIGH);
  rEye.write(5, 1, HIGH);
  rEye.write(6, 1, HIGH);

  lEye.write(2, 2, HIGH);
  lEye.write(3, 2, HIGH);
  rEye.write(3, 2, HIGH);
  rEye.write(4, 2, HIGH);

  lMouth.write(3, 4, HIGH);
  lMouth.write(4, 3, HIGH);
  lMouth.write(5, 2, HIGH);
  lMouth.write(6, 2, HIGH);

  rMouth.write(0, 2, HIGH);
  rMouth.write(1, 2, HIGH);
  rMouth.write(2, 3, HIGH);
  rMouth.write(3, 4, HIGH);
}

And this is just a function to Serial.print.

void printResults(){
  Serial.print("fixed number: ");
  Serial.println(staticNum);
  Serial.print("current number: ");
  Serial.println(dynamicNum);
  Serial.print("previous number: ");
  Serial.println(pdynamicNum);
  Serial.print("faceMode: ");
  if(faceMode==0) Serial.println("exatic");
  if(faceMode==1) Serial.println("zen");
  if(faceMode==2) Serial.println("neutral");
  if(faceMode==3) Serial.println("sad");
  if(faceMode==4) Serial.println("cross");
  Serial.println("");
  Serial.println("");
}

So I think these are the all codes I have now!

If you find anything can be better, please let me know.

Thanks

What kind of Arduino do you have? That is a lot of code for a UNO. I'd guess that your Arduino quitting is caused by running out of SRAM. Most Arduinos only have 2K of SRAM. Look for a function called FreeMemory() that you can include in your code, and call at various places to find out how much SRAM you have available.

Thanks PaulS always. Sorry for the late reply. I've been working in London time.

I was using Duemilanove with ATMega328, then just replaced with Uno in case. But I currently don't have any other types of Arduino with a lager memory.

Is there a specific function called FreeMemory()? I couldn't find that but I found the code here: http://www.faludi.com/2007/04/18/arduino-available-memory-test/

void printMemoryTest(){
  // run the memory test function and print the results to the serial port
  int result = memoryTest();
  Serial.print("Memory test results: ");
  Serial.print(result,DEC);
  Serial.println(" bytes free");
}


// this function will return the number of bytes currently free in RAM
int memoryTest() {
  int byteCounter = 0; // initialize a counter
  byte *byteArray; // create a pointer to a byte array
  // More on pointers here: http://en.wikipedia.org/wiki/Pointer#C_pointers

  // use the malloc function to repeatedly attempt allocating a certain number of bytes to memory
  // More on malloc here: http://en.wikipedia.org/wiki/Malloc
  while ( (byteArray = (byte*) malloc (byteCounter * sizeof(byte))) != NULL ) {
    byteCounter++; // if allocation was successful, then up the count for the next try
    free(byteArray); // free memory after allocating it
  }
  
  free(byteArray); // also free memory after the function finishes
  return byteCounter; // send back the highest number of bytes successfully allocated
}

I called this printMemoryTest() function at these places:

void setup() {
...
  segSetup();
  faceSetup();
  wiflySetup();
  printMemoryTest();
}


void wiflyUpdate(){
  printMemoryTest();
  client.flush();
  Serial.flush();
  Serial.println("updating...");
  printMemoryTest();
...
}

void asciiToInt(){
...
        else if(c == ']'){
            baseLine= atoi(array);
            printResults();
            segDisplay();
            printMemoryTest();
            resetValues();
        }
...
}

it always shows:

"Memory test results: 318 bytes free"

Do you think 318 bytes is still enough space or too small to keep the program running?

Thanks

Hi, I'm having the same problem with Sparkfun Wifly shield board and Arduino Uno. Every 1 minute it performs a GET using the same structure you are using for connection. After 50 minutes, the green light is blinking fast (lost IP), and it couldn't connect anymore. I have run several test to check what would be the problem, but no success. For sure it is not a memory problem. Maybe there is something wrong in WiFly.h ?