ExtraPutty screen freezes

Hi, I am using a software called ExtraPutty as a serial monitor to send and receive data to and from the arduino mega 2560 adk. But at times when its running for like 6hours, or 12 hours, why does it freeze completely? I mean it stops display in the middle of the 'void loop'.

I need to run that 'void loop' for days... without stopping or switching off... may I know why its stopping dead on its tracks in ExtraPutty?
Should I use a different Serial monitor software? if so, please do tell me some names.... :slight_smile:

why does it freeze completely?

Are you sure that it is not the Arduino that has quit? What makes you suspect that the problem is on the PC end?

First, thank you for taking the time to read my issue and reply :slight_smile:

I think its the problem at PC end is cuz I have set the arduino to do a small task(run a motor) for say 1 hour... and the ExtraPutty screen freezes after 50minutes in that 1 hour... after the remaining 10 minutes, the motor stops working stopping exactly after 1 hour in total... but the screen is still frozen...

First, thank you for taking the time to read my issue and reply

It was really a hint (a little too subtle, I see) for you to post some code.

ohh sorry... heads a little too messed up for me to understand that :slight_smile: hehe
well, the code is pretty long... 2200+ lines... :slight_smile:
hehe...

well, the code is pretty long... 2200+ lines...

Which leads me to further suspect that the problem is on the Arduino end - lack of memory or writing out of array bounds, etc.

But it says that it has 250000+ bytes in total, and I am using only 29000+ bytes... I am using an arduino mega 2560... hmmm

But it says that it has 250000+ bytes in total

Of Flash memory, which is completely independent of SRAM.

errr... so what can I do?

what is SRAM exactly?

Is it possible to break the whole 'void loop' function to smaller functions like in C programming? will that help in my case?

what is SRAM exactly?

It is where variables and constant strings are stored.

Is it possible to break the whole 'void loop' function to smaller functions like in C programming?

Since the Arduino is programmed using C++, which is a superset of C, the answer should be obvious.

will that help in my case?

Since you haven't posted your code, only you can answer that.

I'm going to assume that your code doesn't really look like that.

Go back and modify all the posts. Change the [ quote ] and [ /quote ] tags to have code in them, instead.

int array[24][4];
int inPins[] = {22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
37,38,39,40,41,42,43};
int outPins[] = {44,45,46,47,48,49,50,51,52,53,3,4,5,6,7,8,9,10,
11,12,13,14,15,16};
const int numOfMotors = 24; //constant for number of machines(invertors) working
int reply,reply2,reply3; //user input for menu selection
int machineNumber; //user input for machine number selection
unsigned long displayTime; //no real use; but will display the user with the amount of total time the program was running
unsigned long menuTime1,menuTime2,menuElapsed; //is used to calculate the time elapsed during the user input
unsigned long normalTime1,normalTime2,normalElapsed; //is used to calculate the microseconds spent during the void() loop
int x,y,days,hours,minutes,seconds,totalCount,showCount,tableCount1,tableCount2,tempA,tempB,tempC;

void setup() {
int w,x,y,z;

Serial.begin(9600); // open the serial port at 9600 bps:

//setting value to zero for consistancy
normalElapsed = 0;
normalTime2 = 0;
normalTime1 = 0;
menuTime1 = 0;
menuTime2 = 0;
menuElapsed = 0;
days = -1;
hours = -1;
minutes = -1;
seconds = -1;
displayTime = 0;
machineNumber = -1;
reply = reply2 = reply3 = -1;

for (int w = 0; w < numOfMotors ; w++) {
pinMode(inPins[w],OUTPUT);
}

for (int x = 0; x < numOfMotors ; x++) {
pinMode(outPins[x],INPUT);
}

//Initialization
for(y = 0; y < numOfMotors; y++) {
for(z = 0; z < 4; z++) {
array[y][z] = 0;
}
}
}

void loop() {

  //while (x=0/*Serial.read(getchar()*/)/* user "presses enter" it will keep on running the following*/ {
     normalTime1 = millis(); //first process start time
     
     
     displayTime = millis();
     displayTime = displayTime/1000;
     Serial.println("");
     Serial.print("The program has been running for: ");
     Serial.println(displayTime,DEC);
     Serial.println("");
     
    //                              [0]              [1]            [2]            [3]
    Serial.println("Machine #\t\tSet Time\t\tTime Remaining\t\tSet Status\t\tCurrent Status"); //table-top
    
    //display printing
    for(x=0; x<numOfMotors; x++) {
      //array[x][1] = array[x][1]-1; //reduce 1 for every second OR minute=================
      
      //to sort digital from analog
      if(x>=0 && x<=10) {
      if(digitalRead(inPins[x]) == HIGH) {
        array[x][3]=1;
      }
        else {
          array[x][3]=0;
        }
      }
       else if(x>10 && x<=numOfMotors) {
         if(analogRead(inPins[x]) >= 800) {
        array[x][3]=1;
      }
        else {
          array[x][3]=0;
        }
      }
      
      if (array[x][2] == 0 && array[x][3] == 0) {//printing table
         //Serial.println("Machine %i\t\t%i\t\t%i\t\tStopped\t\tStopped",x,array[x][0],array[x][1]);
         Serial.print("Machine ");
         Serial.print(x,DEC); //machine number
         Serial.print("\t\t\t");
                   tempA = array[x][0];
                   tableCount1=tempA/60;
         Serial.print(tempA,DEC);
         Serial.print("       \t\t\t");
                   tempB = array[x][1];
                   tableCount2=tempB/60;
         Serial.print(tempB,DEC);
         Serial.println("       \tSTOPPED              \tSTOPPED");
       }
        else if (array[x][2] == 0 && array[x][3] == 1) {
           //Serial.println("Machine %i\t\t%i\t\t%i\t\tStopped\t\tRunning",x,array[x][0],array[x][1]);
         Serial.print("Machine ");
         Serial.print(x,DEC);
         Serial.print("\t\t\t");
                   tempA = array[x][0];
                   tableCount1=tempA/60;
         Serial.print(tempA,DEC);
         Serial.print("       \t\t");
                   tempB = array[x][1];
                   tableCount1=tempB/60;
         Serial.print(tempB,DEC);
         Serial.println("       \tSTOPPED       \tRUNNING\t ERROR");
        }
           else if (array[x][2] == 1 && array[x][3] == 0 && array[x][1] <= 0) {
             //Serial.println("Machine %i\t\t%i\t\t%i\t\tSet\t\tStopped",x,array[x][0],array[x][1]);
             Serial.print("Machine ");
             Serial.print(x,DEC);
             Serial.print("\t\t\t");
                   tempA = array[x][0];
                   tableCount1=tempA/60;
             Serial.print(tempA,DEC);
             Serial.print("       \t\t");
                   tempB = array[x][1];
                   tableCount1=tempB/60;
             Serial.print(tempB,DEC);
             Serial.println("       \t\tSET       \t\tSTOPPED\t\t COUNT REACHED");
           }
            else if (array[x][2] == 1 && array[x][3] == 0 && array[x][1] > 0) {
             //Serial.println("Machine %i\t\t%i\t\t%i\t\tSet\t\tStopped",x,array[x][0],array[x][1]);
             Serial.print("Machine ");
             Serial.print(x,DEC);
             Serial.print("\t\t\t");
                   tempA = array[x][0];
                   tableCount1=tempA/60;
             Serial.print(tempA,DEC);
             Serial.print("       \t\t");
                   tempB = array[x][1];
                   tableCount1=tempB/60;
             Serial.print(tempB,DEC);
             Serial.println("       \t\tSET       \t\tSTOPPED\t\t WAITING FOR OPERATOR");
           }
             else if (array[x][2] == 1 && array[x][3] == 1) {
               //Serial.println("Machine %i\t\t%i\t\t%i\t\tSet\t\tRunning",x,array[x][0],array[x][1]);
               Serial.print("Machine ");
               Serial.print(x,DEC);
               Serial.print("\t\t\t");
                   tempA = array[x][0];
                   tableCount1=tempA/60;
               Serial.print(tempA,DEC);
               Serial.print("       \t\t");
                   tempB = array[x][0];
                   tableCount1=tempB/60;
               Serial.print(tempB,DEC);
               Serial.println("       \tSET       \tRUNNING");
             }
    //***********system(cls);         
    }//end of for loop
for(x=0; x<numOfMotors; x++) {
    if(array[x][1]>0 && array[x][2]==1){
      digitalWrite(outPins[x],HIGH);
    }
    else if(array[x][1]<=0 || array[x][2]==0){
      /*array[x][2] = 0;  //set SET STATUS to 0
      array[x][3] = 0;  //set CURRENT STATUS to 0*/
      digitalWrite(outPins[x],LOW);
    }
  }
  
  //time testing
 /* for(x=0;x<300;x++){
    Serial.print("the time is:  ");
    Serial.println(x,0);
  }*/
  //}//end of while loop
  
      /*need to create a method that will rapidly deduct 1 second from each */
//=====================================================================================================================
 

  Serial.println("Press 1 to run/stop the machines, Press 2 to set new count");
  if (Serial.available()) {
                // read the incoming byte:
                reply = Serial.read();
                reply = reply - 48;

                // say what you got:
                Serial.print("Reply you have entered: ");
                Serial.println(reply, DEC);
        }
        
  
  if(reply == 1){                                                                                                //reply == 1
    Serial.println("START/STOP -> Please enter the machine number (1-24)");
    do{
    /*=============scan for the machine number for the variable "machine_number" */
    if (Serial.available()) {
                machineNumber = Serial.read();
                machineNumber = machineNumber - 48;
                Serial.print("Number you have entered: ");
                Serial.println(machineNumber, DEC);
      }
    }while(machineNumber < 0 || machineNumber > 24);
    
    if(machineNumber>=0 && machineNumber<24){
      if(array[machineNumber][3] == 0){
        Serial.println("The machine is currently switched off");}
      else if(array[machineNumber][3] == 1) {
        Serial.println("The machine is currently switched on");}
      
      Serial.println("Please press 0 to stop the selected machine or 1 to start the selected machine");
      do{
      /*==============scan for user input for the variable "choice" */  
      if (Serial.available()) {
                  reply2 = Serial.read();
                  reply2 = reply2 -48;
                  Serial.print("you have entered: ");
                  Serial.println(reply2, DEC);
                  array[machineNumber][2] = reply2;
          }
      }while(reply2 < 0 || reply2 > 1);
      
      if(array[machineNumber][2] == 1){
        digitalWrite(outPins[machineNumber], HIGH); }
      else if (array[machineNumber][2] == 0){
        digitalWrite(outPins[machineNumber],LOW); }
    }
  else {
    Serial.println("You have entered an invalid value");
  }
  reply = reply2 = machineNumber = -1;
  }//end if (reply == 1)
  
  else if (reply == 2){                                                                                  //reply == 2
    Serial.println("SET COUNT -> Please enter the machine number (1-24)");
    do{
    /*=============scan for the machine number for the variable "machine_number" */
    if (Serial.available() > 0) {
                machineNumber = Serial.read();
                machineNumber = machineNumber - 48;
                Serial.print("you have entered: ");
                Serial.println(machineNumber, DEC);
        }
    }while(machineNumber < 0 || machineNumber > 24);
    
    if(machineNumber>=0 && machineNumber<24){
    /*=============scan for the user input for the amount of time "set_count"*/
    Serial.println("Enter the amount of time for the selected machine to run");
    Serial.println("Enter number of Days\t");
    do{
    if (Serial.available() > 0) {
               days = Serial.read();
               days = days - 48;
        }
    }while(days<0);
    Serial.println("Enter number of Hours\t");
    do{
    if (Serial.available() > 0) {
                hours = Serial.read();
                hours = hours - 48;
        }
    }while(hours<0);
    
    Serial.println("Enter number of minutes\t");
    do{
    if (Serial.available() > 0) {
                minutes = Serial.read();
                minutes = minutes - 48;
        }
    }while(minutes<0);
    
    Serial.println("Enter number of seconds\t");
    do{
    if (Serial.available() > 0) {
                seconds = Serial.read();
                seconds = seconds - 48;
        }
    }while(seconds<0);
     
    totalCount = ((days*86400)+(hours*3600)+(minutes*60)+seconds);
    array[machineNumber][1] = totalCount;  //store for time remaining
    array[machineNumber][0] = totalCount;  //store the user set time
    showCount=totalCount/60;
    Serial.print("total number in minutes: ");
    Serial.print(showCount,DEC);
    

    days = hours = minutes = seconds = machineNumber = reply = -1;
    }
  else {
    Serial.println("You have entered an invalid value");
  }  
}//end if(reply == 2)

  //for time difference between the menu run

  for(x = 0; x < numOfMotors; x++){
    if(array[x][1]>0 /*&& array[x][2]==1*/){
    menuTime2 = array[x][1];
    array[x][1] = menuTime2 - normalElapsed;
    }   //deduct the total time from the current time so as to lessen the timing error
    else if(array[x][1]<0){
      array[x][1] = 0;
    }
  }

delay(2000); //delay is used for consistancy

  normalTime2 = millis();
  normalElapsed = normalTime2 - normalTime1 + 226;
  normalElapsed = normalElapsed/1000;
    
}//end of the void() loop

sorry, when I post it in quotes, the publisher thinks im tryting to enter lists in my 2D arrays...

cant be the SRAM ner...? cuz its got 8KBs of SRAM... I mean, I am hardly using 4kbs for my variables...

There's a code sample in the playground that shows you how to measure the free memory. I suggest you call it and see whether you're anywhere near the limit.

Hi PeterH... I tried this method to see how much of free RAM I have from playground ->

Another method that seems to be even simpler is the following:
Declare this function:
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

and call it anywhere in your program like that: Serial.println(freeRam());

And it always reads, 5173 from the start. I guess it means I have 5173bytes of RAM left in my Mega 2560...

Btw, when the serial output gets stuck, the RX TX lights light up and stay lit, sometimes both, sometimes either and today none... It is really irritating now... :~