Same string getting rewriten every second, RAM usage issue?

Hy,
In my sketch arduino is checking for mesage via serial (CMD) every second and writes that into string.
I am suspicious that this is using more and more ram until it crashes.

Message looks like:

MF+00000001

when this message changes to something else, for example:

MF+00000002

the message gets writen to another string on that string I remove:

MF+000000

basicly everything but last two characters -hex value.

Now I think that first string getting rewriten every second is using up ram.

What does happen with ram acctualy when string is getting rewriten?

Does the ram usage remains the same or does multiplies?

Thank you

Yet, you don't show the actual code...

That depends on the code that, at this point, is a mystery. Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Here is the code, there is modified library behind it. Believe me whoever wants to help me would spent too much effort. I know that I`m on my own because the size of the project. I just need info.

#include <Wire.h>
#include <DFRobot_BT401.h>
#include <SoftwareSerial.h>

SoftwareSerial ibusPort(2, 3); // RX, TX
//SoftwareSerial debugSerial(8, 9); //RX, TX
char acc = 2;
char lastAcc = 3;
unsigned long accCounter = 1001;
unsigned long val = 1000;
char accCounterTrigger = 0;
char rort = 2; //Radio = 0, Tape = 1
char lastRort = 3;
char rortCounter = 0;
char rortCounterTrigger = 0;
char rortStep = 50;
char mode = 0;
char queryMode = 1;
char queryDirSIZE = 1;
char INTERRUPT = 1;
char buttonPressed = 0;
char btnrd;
char PP = 0;
char FRD = 0;
char RWD = 0;
int FRDcounter = 0;
char FRDcounterTrigger = 0;
int RWDcounter = 0;
char RWDcounterTrigger = 0;
char FRDactivated = 0;
char RWDactivated = 0;
char ibus1 = 0;
char ibus2 = 0;
char ibus3 = 0;
char ibusA = 0;
char ibusB = 0;
char ibusC = 0;
char ibusUpCounter = 0;
char ibusDownCounter = 0;
char ibusUpCounterTrigger = 0;
char ibusDownCounterTrigger = 0;
char ibusCommandCaptured = 0;

char antilag = 0;
int displayRefresh = 0;


char queryFileName = 0;

String nowPlaying;
String songNUMBER;
String lastsongNUMBER;
String dirSIZE;
String lastdirSIZE;
String newdirSIZE;
String newsongNUMBER;


int period = 1000;
int period_display = 700;
int period_ibus = 20;
int period_btn = 700;
unsigned long time_now_ibus = 0;
unsigned long time_now = 0;
unsigned long time_now_display = 0;
unsigned long time_now_btn = 0;
char acolumn = 0;
char bcolumn = 1;
char ccolumn = 2;
char dcolumn = 3;
char ecolumn = 4;
char fcolumn = 5;
char gcolumn = 6;
char hcolumn = 7;
char icolumn = 8;




String inputText;
char inputText_len;
String smallDisplay;
char smallDisplay_len;


constexpr size_t numColumns = 5;



void getColumns(char c, uint8_t columns[numColumns]);

const uint8_t upperCase[][numColumns] PROGMEM = {
  {0X7E, 0X11, 0X11, 0X11, 0X7E}, // Column codes for 'A'
  {0X7F, 0X49, 0X49, 0X49, 0X36}, // Column codes for 'B'
  {0X3E, 0X41, 0X41, 0X41, 0X22}, // Column codes for 'C'
  {0X7F, 0X41, 0X41, 0X22, 0X1C}, // Column codes for 'D'
  {0X7F, 0X49, 0X49, 0X49, 0X41}, // Column codes for 'E'
  {0X7F, 0X09, 0X09, 0X09, 0X01}, // Column codes for 'F'
  {0X3E, 0X41, 0X49, 0X49, 0X7A}, // Column codes for 'G'
  {0X7F, 0X08, 0X08, 0X08, 0X7F}, // Column codes for 'H'
  {0X00, 0X41, 0X7F, 0X41, 0X00}, // Column codes for 'I'
  {0X20, 0X40, 0X41, 0X3F, 0X01}, // Column codes for 'J'
  {0X7F, 0X08, 0X14, 0X22, 0X41}, // Column codes for 'K'
  {0X7F, 0X40, 0X40, 0X40, 0X40}, // Column codes for 'L'
  {0X7F, 0X02, 0X0C, 0X02, 0X7F}, // Column codes for 'M'
  {0X7F, 0X04, 0X08, 0X10, 0X7F}, // Column codes for 'N'
  {0X3E, 0X41, 0X41, 0X41, 0X3E}, // Column codes for 'O'
  {0X7F, 0X09, 0X09, 0X09, 0X06}, // Column codes for 'P'
  {0X3E, 0X41, 0X41, 0X61, 0X3E}, // Column codes for 'Q'
  {0X7F, 0X09, 0X19, 0X29, 0X46}, // Column codes for 'R'
  {0X46, 0X49, 0X49, 0X49, 0X31}, // Column codes for 'S'
  {0X01, 0X01, 0X7F, 0X01, 0X01}, // Column codes for 'T'
  {0X3F, 0X40, 0X40, 0X40, 0X3F}, // Column codes for 'U'
  {0X07, 0X18, 0X60, 0X18, 0X07}, // Column codes for 'V'
  {0X3F, 0X40, 0X38, 0X40, 0X3F}, // Column codes for 'W'
  {0X63, 0X14, 0X08, 0X14, 0X63}, // Column codes for 'X'
  {0X07, 0X08, 0X70, 0X08, 0X07}, // Column codes for 'Y'
  {0X61, 0X51, 0X49, 0X45, 0X43} // Column codes for 'Z'
};

const uint8_t lowerCase[][numColumns] PROGMEM = {
  {0X20, 0X54, 0X54, 0X54, 0X78}, // Column codes for 'a'
  {0X7F, 0X48, 0X48, 0X48, 0X30}, // Column codes for 'b'
  {0X38, 0X44, 0X44, 0X44, 0X44}, // Column codes for 'c'
  {0X30, 0X48, 0X48, 0X48, 0X7F}, // Column codes for 'd'
  {0X38, 0X54, 0X54, 0X54, 0X58}, // Column codes for 'e'
  {0X00, 0X08, 0X7E, 0X09, 0X02}, // Column codes for 'f'
  {0X48, 0X54, 0X54, 0X54, 0X3C}, // Column codes for 'g'
  {0X7F, 0X08, 0X08, 0X08, 0X70}, // Column codes for 'h'
  {0X00, 0X00, 0X7A, 0X00, 0X00}, // Column codes for 'i'
  {0X20, 0X40, 0X40, 0X39, 0X00}, // Column codes for 'j'
  {0X00, 0X7F, 0X10, 0X28, 0X44}, // Column codes for 'k'
  {0X00, 0X41, 0X7F, 0X40, 0X00}, // Column codes for 'l'
  {0X7C, 0X04, 0X18, 0X04, 0X7C}, // Column codes for 'm'
  {0X7C, 0X08, 0X04, 0X04, 0X78}, // Column codes for 'n'
  {0X30, 0X48, 0X48, 0X30, 0X00}, // Column codes for 'o'
  {0X7C, 0X14, 0X14, 0X14, 0X08}, // Column codes for 'p'
  {0X7F, 0X04, 0X04, 0X04, 0X03}, // Column codes for 'q'
  {0X7C, 0X08, 0X04, 0X04, 0X08}, // Column codes for 'r'
  {0X48, 0X54, 0X54, 0X54, 0X24}, // Column codes for 's'
  {0X04, 0X04, 0X3F, 0X44, 0X24}, // Column codes for 't'
  {0X3C, 0X40, 0X40, 0X40, 0X3C}, // Column codes for 'u'
  {0X1C, 0X20, 0X40, 0X20, 0X1C}, // Column codes for 'v'
  {0X3C, 0X40, 0X30, 0X40, 0X3C}, // Column codes for 'w'
  {0X44, 0X28, 0X10, 0X28, 0X44}, // Column codes for 'x'
  {0X04, 0X48, 0X30, 0X18, 0X04}, // Column codes for 'y'
  {0X44, 0X64, 0X54, 0X4C, 0X44} // Column codes for 'z'
};

const uint8_t numerals[][numColumns] PROGMEM = {
  {0X3E, 0X45, 0X49, 0X51, 0X3E}, // Column codes for '0'
  {0X00, 0X42, 0X7F, 0X40, 0X00}, // Column codes for '1'
  {0X42, 0X61, 0X51, 0X49, 0X46}, // Column codes for '2'
  {0X22, 0X41, 0X49, 0X49, 0X36}, // Column codes for '3'
  {0X18, 0X14, 0X12, 0X7F, 0X10}, // Column codes for '4'
  {0X27, 0X45, 0X45, 0X45, 0X39}, // Column codes for '5'
  {0X3E, 0X49, 0X49, 0X49, 0X30}, // Column codes for '6'
  {0X01, 0X71, 0X09, 0X05, 0X03}, // Column codes for '7'
  {0X36, 0X49, 0X49, 0X49, 0X36}, // Column codes for '8'
  {0X06, 0X49, 0X49, 0X49, 0X3E} // Column codes for '9'
};

const uint8_t symbolsa[][numColumns] PROGMEM = {
  {0X00, 0X00, 0X5F, 0X00, 0X00}, // Column codes for '!'
  {0X00, 0X03, 0X00, 0X03, 0X00}, // Column codes for '"'
  {0X14, 0X7F, 0X14, 0X7F, 0X14}, // Column codes for '#'
  {0X24, 0X2A, 0X7F, 0X2A, 0X12}, // Column codes for '$'
  {0X23, 0X13, 0X08, 0X64, 0X62}, // Column codes for '%'
  {0X36, 0X49, 0X55, 0X22, 0X50}, // Column codes for '&'
  {0X04, 0X02, 0X02, 0X01, 0X00}, // Column codes for '''
  {0X00, 0X1C, 0X22, 0X41, 0X00}, // Column codes for '('
  {0X00, 0X41, 0X22, 0X1C, 0X00}, // Column codes for ')'
  {0X14, 0X08, 0X3E, 0X08, 0X14}, // Column codes for '*'
  {0X08, 0X08, 0X3E, 0X08, 0X08}, // Column codes for '+'
  {0X00, 0X00, 0X50, 0X30, 0X00}, // Column codes for ','
  {0X08, 0X08, 0X08, 0X08, 0X08}, // Column codes for '-'
  {0X00, 0X60, 0X60, 0X00, 0X00}, // Column codes for '.'
  {0X20, 0X10, 0X08, 0X04, 0X02} // Column codes for '/'
};

const uint8_t symbolsb[][numColumns] PROGMEM = {
  {0X00, 0X7F, 0X41, 0X41, 0X00}, // Column codes for '['
  {0X02, 0X04, 0X08, 0X10, 0X20}, // Column codes for '\'
  {0X00, 0X41, 0X41, 0X7F, 0X00}, // Column codes for ']'
  {0X04, 0X02, 0X01, 0X02, 0X04}, // Column codes for '^'
  {0X00, 0X00, 0X00, 0X00, 0X00}, // Column codes for '_'
  {0X00, 0X01, 0X02, 0X04, 0X00} // Column codes for '`'

};

const uint8_t symbolsc[][numColumns] PROGMEM = {
  {0X08, 0X36, 0X41, 0X41, 0X00}, // Column codes for '{'
  {0X00, 0X00, 0X7F, 0X00, 0X00}, // Column codes for '|'
  {0X00, 0X41, 0X41, 0X36, 0X08}, // Column codes for '}'
  {0X01, 0X02, 0X01, 0X20, 0X00}, // Column codes for '~'
};

const uint8_t equalSymbol [numColumns] PROGMEM = {0x14, 0x14, 0x14, 0x14, 0x14};

const uint8_t afnaSymbol [numColumns] PROGMEM = {0x32, 0x49, 0x71, 0x41, 0x3E};

const uint8_t space[numColumns] PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00};

const uint8_t unknown[numColumns] PROGMEM = {0x00, 0x00, 0x00, 0x00, 0x00};



DFRobot_BT401 bt;

void setup() {
  pinMode(12, INPUT); //acc
  pinMode(11, INPUT); // Radio or Tape - 0 = Radio, 1 = Tape
  pinMode(10, INPUT_PULLUP); //INTERRUPT
  pinMode(4, OUTPUT); //ADG411 pin for ibus -LOGIC 1 = ibus OFF, LOGIC 0 = on...
  pinMode(6, OUTPUT); //ADG411 pin for ARDUINO -LOGIC 1 = Arduino OFF, LOGIC 0 = on...
  pinMode(5, OUTPUT); // ADG411 pin for MCU -LOGIC 1 = mcu OFF, LOGIC 0 = on...

  digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(4, HIGH);


  Wire.begin();
  Wire.setWireTimeout(5000);
  Serial.begin(256000); // BT401 baudrate
  ibusPort.begin(9600);
  //debugSerial.begin(9600);
  /////////////////////////////////////////////////////////

  /*Delay for the BT401 to start*/
  while (!bt.begin(Serial)) {
    delay(1000);
  }
  bt.setVOl(30);
  delay(100);

}

void loop() {
  if (antilag <= 4) {
    antilag ++;
  }

  if (antilag == 5) {

    if (millis() >= time_now_ibus + period_ibus) {
      time_now_ibus += period_ibus;
      if (ibusCommandCaptured == 1) {
        //     debugSerial.println("IBUS COMMAND CAPTURED:");
        //     debugSerial.println(ibus1);
        //     debugSerial.println(ibus2);
        //     debugSerial.println(ibus3);
        //     debugSerial.println(ibusA);
        //     debugSerial.println(ibusB);
        //     debugSerial.println(ibusC);
        //     debugSerial.println("////////////////////////////////////////////////////////");
        ibus1 = 0;
        ibus2 = 0;
        ibus3 = 0;
        ibusA = 0;
        ibusB = 0;
        ibusC = 0;
        ibusCommandCaptured = 0;

      }

      if (ibusPort.available() > 0 && ibus1 == 0) {
        ibus1 = ibusPort.read();
        //     debugSerial.println("IBUS 1: ");
        //     debugSerial.println(ibus1);
        if (ibus1 != 0x50) {
          ibus1 = 0;
        }
      }

      if (ibusPort.available() > 0 && ibus1 == 0x50 && ibus2 == 0) {
        ibus2 = ibusPort.read();
        //     debugSerial.println("IBUS 2: ");
        //     debugSerial.println(ibus2);
        if (ibus2 != 0x04) {
          ibus1 = 0;
          ibus2 = 0;
        }
      }

      if (ibusPort.available() > 0 && ibus2 == 0x04 && ibus3 == 0) {
        ibus3 = ibusPort.read();
        //     debugSerial.println("IBUS 3: ");
        //     debugSerial.println(ibus3);
        if (ibus3 != 0x68) {
          ibus1 = 0;
          ibus2 = 0;
          ibus3 = 0;
        }
      }

      if (ibusPort.available() > 0 && ibus3 == 0x68 && ibusA == 0) {
        ibusA = ibusPort.read();
        //     debugSerial.println("IBUS A: ");
        //     debugSerial.println(ibusA);
      }

      if (ibusPort.available() > 0 && ibusA != 0 && ibusB == 0) {
        ibusB = ibusPort.read();
        //     debugSerial.println("IBUS B: ");
        //     debugSerial.println(ibusB);
      }

      if (ibusPort.available() > 0 && ibusB != 0 && ibusC == 0) {
        ibusC = ibusPort.read();
        //     debugSerial.println("IBUS C: ");
        //     debugSerial.println(ibusC);
      }

      if (ibusC != 0)
      {
        ibusCommandCaptured = 1;
      }



      //NEXT PRESSED
      if (ibusA == 0x3B && ibusB == 0X01 && ibusC == 0X06) {
        bt.next();
        ibusCommandCaptured = 1;
      }
      //PREV PRESSED
      if (ibusA == 0x3B && ibusB == 0x08 && ibusC == 0x0F) {
        bt.last();
        ibusCommandCaptured = 1;
      }
      //VOL UP PRESSED
      if (ibusA == 0x32 && ibusB == 0x11 && ibusC == 0x1F) {
        digitalWrite(4, LOW);
        //debugSerial.println("iBus ADG state: LOW");
        ibusUpCounterTrigger = 1;
        ibusCommandCaptured = 1;

      }
      //VOL DOWN PRESSED
      if (ibusA == 0x32 && ibusB == 0x10 && ibusC == 0x1E) {
        digitalWrite(4, LOW);
        //debugSerial.println("iBus ADG state: LOW");
        ibusDownCounterTrigger = 1;
        ibusCommandCaptured = 1;
      }


      //NEXT RELEASED
      if (ibusA == 0x3B && ibusB == 0X21 && ibusC == 0X26) {
        ibusCommandCaptured = 1;
      }
      //PREV RELEASED
      if (ibusA == 0x3B && ibusB == 0x28 && ibusC == 0x2F) {
        ibusCommandCaptured = 1;
      }
      //VOL UP RELEASED
      if (ibusA == 0x32 && ibusB == 0x31 && ibusC == 0x3F) {
        //DOESNT OCCUR
      }
      //VOL DOWN RELEASED
      if (ibusA == 0x32 && ibusB == 0x30 && ibusC == 0x3E) {
        //DOESNT OCCUR
      }



      if (ibusUpCounterTrigger == 1) {
        ibusUpCounter = ibusUpCounter + 1;


        if (ibusUpCounter <= 10 && ibusC == 0x1F) {
          ibusUpCounter = 0;
        }
        if (ibusUpCounter == 11 && ibusC != 0x1F) {
          digitalWrite(4, HIGH);
          //debugSerial.println("iBus ADG state: HIGH");
          ibusUpCounterTrigger = 0;
          ibusUpCounter = 0;
        }

      }



      /////////////////////////////////////////////////


      if (ibusDownCounterTrigger == 1) {
        ibusDownCounter = ibusDownCounter + 1;


        if (ibusDownCounter <= 10 && ibusC == 0x1E) {
          ibusDownCounter = 0;
        }
        if (ibusDownCounter == 11 && ibusC != 0x1E) {
          digitalWrite(4, HIGH);
          //debugSerial.println("iBus ADG state: HIGH");
          ibusDownCounterTrigger = 0;
          ibusDownCounter = 0;
        }

      }
    }
    ////////////////////////////////////////////////////////////
    if (mode != 0) {


      INTERRUPT = digitalRead(10);
      if (INTERRUPT == 0 && millis() >= time_now_btn + period_btn) {
        // debugSerial.println("interrupt = 0");
        time_now_btn += period_btn;
        Wire.requestFrom(0x20, 1);

        while (Wire.available()) {
          char btnrd = Wire.read();
          buttonPressed = btnrd;

          if (btnrd == 28) {

            Wire.beginTransmission(0x20);
            Wire.write(0x1D);
            Wire.endTransmission();
            Wire.requestFrom(0x20, 1);
            char btnrd = Wire.read();
            buttonPressed = btnrd;
          }

          if (btnrd == -116) {

            Wire.beginTransmission(0x20);
            Wire.write(0x03);
            Wire.endTransmission();
            Wire.requestFrom(0x20, 1);
            char btnrd = Wire.read();
            buttonPressed = btnrd;
          }

          Wire.beginTransmission(0x20);
          Wire.write(0x9c);
          Wire.endTransmission();
          //debugSerial.println(btnrd, HEX);
        }
        if (FRDcounterTrigger == 1)
        {
          FRDcounterTrigger = 0;
          buttonPressed = 0;
          if (FRDcounter <= 7009)
          {
            FRDcounter = -1;
            buttonPressed = 0;
          }
        }
        if (RWDcounterTrigger == 1)
        {
          RWDcounterTrigger = 0;
          buttonPressed = 0;
          if (RWDcounter <= 7009)
          {
            RWDcounter = -1;
            buttonPressed = 0;
          }
        }
        if (FRDactivated == 1)
        {
          FRDactivated = 0;
        }
        if (RWDactivated == 1)
        {
          RWDactivated = 0;
        }
        INTERRUPT = 1;
      }
    } //end of if mode != 0

    if (FRDcounter == 7012)
    {
      FRDcounter = 0;
      buttonPressed = 0;
    }
    if (RWDcounter == 7012)
    {
      RWDcounter = 0;
      buttonPressed = 0;
    }


    if (buttonPressed == 3 && mode == 0) //radio
    {
      mode = 1;
      queryMode = 1;
      buttonPressed = 0;
      delay(250);

    }

    if (buttonPressed == 3 && mode == 1) //USB
    {
      mode = 2;
      queryMode = 1;
      buttonPressed = 0;
      delay(250);
    }

    if (buttonPressed == 3 && mode == 2) //BLUETOOTH
    {
      buttonPressed = 0;
      queryMode = 1;
      mode = 0;
      digitalWrite(6, LOW);
      Wire.begin(0x20);
      Wire.write(3);
    }




    if (buttonPressed == 28 && mode != 0) //PLAY / PAUSE
    {
      //Serial.println("PLAY / PAUSE pressed");
      bt.playPause();

      buttonPressed = 0;
    }

    if (buttonPressed == 1 && mode != 0) //FRD
    {
      FRDcounterTrigger = 1;
    }

    if (FRDcounterTrigger == 1 && FRDcounter <= 7010)
    {
      FRDcounter = FRDcounter + 1;

    }

    if (FRDcounter == -1)
    {
      bt.next();
      FRDcounter = 0;
      FRDcounterTrigger = 0;


    }

    if (FRDcounter == 7010)
    {
      FRDactivated = 1;
      FRDcounterTrigger = 0;
      FRDcounter = 7012;
    }
    if (FRDactivated == 1)
    {
      bt.FRD();
    }

    if (buttonPressed == 2 && mode != 0) //RWD
    {
      RWDcounterTrigger = 1;
    }

    if (RWDcounterTrigger == 1 && RWDcounter <= 7010)
    {
      RWDcounter = RWDcounter + 1;

    }

    if (RWDcounter == -1)
    {
      bt.last();
      RWDcounter = 0;
      RWDcounterTrigger = 0;


    }

    if (RWDcounter == 7010)
    {
      RWDactivated = 1;
      RWDcounterTrigger = 0;
      RWDcounter = 7012;
    }
    if (RWDactivated == 1)
    {
      bt.RWD();
    }

  } // end of antilag


  acc = digitalRead(12);

  if (accCounter <= val)
  {
    accCounter = accCounter + 1;
  }




  if (acc == HIGH && acc != lastAcc && accCounter == val + 1) {
    if (mode == 0) {
      mode = 1;
      queryMode = 1;
    }
    bt.pause();
    lastAcc = HIGH;
    accCounter = 1;
    val = 150000;
  }

  if (acc == LOW && acc != lastAcc && accCounter == val + 1) {


    bt.play();
    lastAcc = LOW;
    accCounter = 1;
    val = 150000;
  }




  if (mode == 0 && queryMode == 1) //RADIO
  {
    inputText = "Radio";
    digitalWrite(6, HIGH);
    digitalWrite(5, LOW);
    digitalWrite(4, LOW);
    //debugSerial.println("iBus ADG state: LOW");
    queryMode = 0;
  }

  if (mode == 1 && queryMode == 1) //USB
  {
    digitalWrite(5, HIGH);
    digitalWrite(6, LOW);
    digitalWrite(4, HIGH);
    bt.usbMode();
    //debugSerial.println("iBus ADG state: HIGH");
    delay(500);
    Wire.beginTransmission(0x20);
    Wire.write(0x9c);
    Wire.endTransmission();
    lastsongNUMBER = "0";
    queryFileName = 1;
    queryDirSIZE = 1;
    queryMode = 0;
  }

  if (mode == 2 && queryMode == 1) //BLUETOOTH
  {
    digitalWrite(6, LOW);
    digitalWrite(5, HIGH);
    digitalWrite(4, HIGH);
    bt.bluetoothMode();
    //debugSerial.println("iBus ADG state: HIGH");
    inputText = "Bluetooth";
    smallDisplay = "--:--";
    queryMode = 0;
    acolumn = 0;
    bcolumn = 1;
    ccolumn = 2;
    dcolumn = 3;
    ecolumn = 4;
    fcolumn = 5;
    gcolumn = 6;
    hcolumn = 7;
    icolumn = 8;
  }
  inputText_len = inputText.length() + 1;

  if (mode == 1 && queryDirSIZE == 1) {
    do {
      dirSIZE = (bt.dirSIZE());
      if (lastdirSIZE != dirSIZE) {
        lastdirSIZE = dirSIZE;
        newdirSIZE = dirSIZE;
      }
    } while (! newdirSIZE.startsWith("M2"));
    newdirSIZE.replace("M2+00000", "");
    newdirSIZE.replace("0A", "1.0");
    newdirSIZE.replace("0B", "1.1");
    newdirSIZE.replace("0C", "1.2");
    newdirSIZE.replace("0D", "1.3");
    newdirSIZE.replace("0E", "1.4");
    newdirSIZE.replace("0F", "1.5");
    newdirSIZE.replace("10", "1.6");
    newdirSIZE.replace("11", "1.7");
    newdirSIZE.replace("12", "1.8");
    newdirSIZE.replace("13", "1.9");
    newdirSIZE.replace("14", "2.0");
    newdirSIZE.replace("15", "2.1");
    newdirSIZE.replace("16", "2.2");
    newdirSIZE.replace("17", "2.3");
    newdirSIZE.replace("18", "2.4");
    newdirSIZE.replace("19", "2.5");
    newdirSIZE.replace("1A", "2.6");
    newdirSIZE.replace("1B", "2.7");
    newdirSIZE.replace("1C", "2.8");
    newdirSIZE.replace("1D", "2.9");
    newdirSIZE.replace("1E", "3.0");

    newdirSIZE.replace(".", "");
    if (newdirSIZE != "000") {
      queryDirSIZE = 0;
    }
    //debugSerial.println(dirSIZE);
  }


  if (mode == 1 && millis() >= time_now + period) {
    time_now += period;
    songNUMBER = (bt.songNUM());
    if (lastsongNUMBER != songNUMBER) {

      do {
        songNUMBER = (bt.songNUM());
        lastsongNUMBER = songNUMBER;
        newsongNUMBER = songNUMBER;
      } while (! newsongNUMBER.startsWith("MO"));
      //debugSerial.println(newsongNUMBER);
      newsongNUMBER.replace("MO+000000", "");
      newsongNUMBER.replace("0A", "1.0");
      newsongNUMBER.replace("0B", "1.1");
      newsongNUMBER.replace("0C", "1.2");
      newsongNUMBER.replace("0D", "1.3");
      newsongNUMBER.replace("0E", "1.4");
      newsongNUMBER.replace("0F", "1.5");
      newsongNUMBER.replace("10", "1.6");
      newsongNUMBER.replace("11", "1.7");
      newsongNUMBER.replace("12", "1.8");
      newsongNUMBER.replace("13", "1.9");
      newsongNUMBER.replace("14", "2.0");
      newsongNUMBER.replace("15", "2.1");
      newsongNUMBER.replace("16", "2.2");
      newsongNUMBER.replace("17", "2.3");
      newsongNUMBER.replace("18", "2.4");
      newsongNUMBER.replace("19", "2.5");
      newsongNUMBER.replace("1A", "2.6");
      newsongNUMBER.replace("1B", "2.7");
      newsongNUMBER.replace("1C", "2.8");
      newsongNUMBER.replace("1D", "2.9");
      newsongNUMBER.replace("1E", "3.0");

      newsongNUMBER.replace(".", "");

      queryFileName = 1;
      smallDisplay = newsongNUMBER + newdirSIZE;
      //      debugSerial.println(smallDisplay);
      smallDisplay_len = smallDisplay.length() + 1;
    }
  }




  ///////////////////////////////////////////////////////////////

  if (queryFileName == 1)
  {
    do {
      nowPlaying = (bt.getFilename());

      inputText = nowPlaying;
      inputText.replace(".mp3", "  ");
      inputText_len = inputText.length() + 1;
    } while (! inputText.startsWith("MF+"));
    inputText.replace("MF+", "");
    acolumn = -1;
    bcolumn = 0;
    ccolumn = 1;
    dcolumn = 2;
    ecolumn = 3;
    fcolumn = 4;
    gcolumn = 5;
    hcolumn = 6;
    icolumn = 7;

    queryFileName = 0;
  }


  ///////////////////////////////////////////////////////////////////////////////////////////////////////

  if (millis() >= time_now_display + period_display) {
    time_now_display += period_display;
    char inputText_array[inputText_len];
    inputText.toCharArray(inputText_array, inputText_len);


    uint8_t ahr[numColumns];
    getColumns(inputText[acolumn], ahr);


    uint8_t bhr[numColumns];
    getColumns(inputText[bcolumn], bhr);


    uint8_t chr[numColumns];
    getColumns(inputText[ccolumn], chr);


    uint8_t dhr[numColumns];
    getColumns(inputText[dcolumn], dhr);

    uint8_t ehr[numColumns];
    getColumns(inputText[ecolumn], ehr);


    uint8_t fhr[numColumns];
    getColumns(inputText[fcolumn], fhr);


    uint8_t ghr[numColumns];
    getColumns(inputText[gcolumn], ghr);


    uint8_t hhr[numColumns];
    getColumns(inputText[hcolumn], hhr);


    uint8_t ihr[numColumns];
    getColumns(inputText[icolumn], ihr);


    char smallDisplay_array[smallDisplay_len];
    smallDisplay.toCharArray(smallDisplay_array, smallDisplay_len);

    uint8_t smla[numColumns];
    getColumns(smallDisplay[0], smla);
    uint8_t smlb[numColumns];
    getColumns(smallDisplay[1], smlb);
    uint8_t smlc[numColumns];
    getColumns(smallDisplay[2], smlc);
    uint8_t smld[numColumns];
    getColumns(smallDisplay[3], smld);
    uint8_t smle[numColumns];
    getColumns(smallDisplay[4], smle);


    if (inputText_len > 10 && icolumn < inputText_len) {

      acolumn = (acolumn + 1);
      bcolumn = (bcolumn + 1);
      ccolumn = (ccolumn + 1);
      dcolumn = (dcolumn + 1);
      ecolumn = (ecolumn + 1);
      fcolumn = (fcolumn + 1);
      gcolumn = (gcolumn + 1);
      hcolumn = (hcolumn + 1);
      icolumn = (icolumn + 1);

    } else {
      acolumn = 0;
      bcolumn = 1;
      ccolumn = 2;
      dcolumn = 3;
      ecolumn = 4;
      fcolumn = 5;
      gcolumn = 6;
      hcolumn = 7;
      icolumn = 8;
    }
    if (mode != 0) {

      //COMMANDS TO SET UP THE DISPLAY
      Wire.begin();
      Wire.beginTransmission(0x3C);
      Wire.write(0x55);             // set_mode  -normal video, mixed mode, MUX 1:8
      Wire.endTransmission();

      Wire.beginTransmission(0x3C);
      Wire.write(0x3e); // RAM access
      Wire.endTransmission();

      Wire.beginTransmission(0x3C);
      Wire.write(0x7c); //set start bank 0
      Wire.endTransmission();

      Wire.beginTransmission(0x3C);
      Wire.write(0x62); //device select
      Wire.endTransmission();


      //WRITING TO DISPLAY STARTS HERE

      Wire.beginTransmission(0x3C);
      Wire.write(0x0F); //load x address

      Wire.write(bhr[3]);             // DATA column 10
      Wire.write(bhr[2]);             // DATA column 9
      Wire.write(bhr[1]);             // DATA column 8
      Wire.write(bhr[0]);             // DATA column 7
      Wire.write(0x00);               // DATA column 6
      Wire.write(ahr[4]);             // DATA column 5
      Wire.write(ahr[3]);             // DATA column 4
      Wire.write(ahr[2]);             // DATA column 3
      Wire.write(ahr[1]);             // DATA column 2
      Wire.write(ahr[0]);             // DATA column 1

      Wire.endTransmission();     // stop transmitting


      Wire.beginTransmission(0x3C);
      Wire.write(0x05); //load x address

      Wire.write(dhr[1]);             // DATA column 20
      Wire.write(dhr[0]);             // DATA column 19
      Wire.write(0x00);               // DATA column 18
      Wire.write(chr[4]);             // DATA column 17
      Wire.write(chr[3]);             // DATA column 16
      Wire.write(chr[2]);             // DATA column 15
      Wire.write(chr[1]);             // DATA column 14
      Wire.write(chr[0]);             // DATA column 13
      Wire.write(0x00);               // DATA column 12
      Wire.write(bhr[4]);             // DATA column 11

      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x00); //load x address

      Wire.write(0x00);               // DATA MISSING COLUMN -BLANK
      Wire.write(0x00);               // DATA column 24
      Wire.write(dhr[4]);             // DATA column 23
      Wire.write(dhr[3]);             // DATA column 22
      Wire.write(dhr[2]);             // DATA column 21

      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x61); //device select
      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x1f); //load x address

      Wire.write(fhr[3]);             // DATA column 34
      Wire.write(fhr[2]);             // DATA column 33
      Wire.write(fhr[1]);             // DATA column 32
      Wire.write(fhr[0]);             // DATA column 31
      Wire.write(0x00);               // DATA column 30
      Wire.write(ehr[4]);             // DATA column 39
      Wire.write(ehr[3]);             // DATA column 28
      Wire.write(ehr[2]);             // DATA column 27
      Wire.write(ehr[1]);             // DATA column 26
      Wire.write(ehr[0]);             // DATA column 25

      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x61); //device select
      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x14); //load x address

      Wire.write(hhr[2]);             // DATA column 45
      Wire.write(hhr[1]);             // DATA column 44
      Wire.write(hhr[0]);             // DATA column 43
      Wire.write(0x00);               // DATA column 42
      Wire.write(ghr[4]);             // DATA column 41
      Wire.write(ghr[3]);             // DATA column 40
      Wire.write(ghr[2]);             // DATA column 39
      Wire.write(ghr[1]);             // DATA column 38
      Wire.write(ghr[0]);             // DATA column 37
      Wire.write(0x00);               // DATA column 36
      Wire.write(fhr[4]);             // DATA column 35

      Wire.endTransmission();


      Wire.beginTransmission(0x3C);
      Wire.write(0x61); //device select
      Wire.endTransmission();



      Wire.beginTransmission(0x3C);
      Wire.write(0x0A); //load x address

      Wire.write(0x00);             // DATA column 55
      Wire.write(0x00);             // DATA column 54
      Wire.write(ihr[4]);             // DATA column 53
      Wire.write(ihr[3]);             // DATA column 52
      Wire.write(ihr[2]);             // DATA column 51
      Wire.write(ihr[1]);             // DATA column 50
      Wire.write(ihr[0]);             // DATA column 49
      Wire.write(0x00);             // DATA column 48
      Wire.write(hhr[4]);             // DATA column 47
      Wire.write(hhr[3]);             // DATA column 46

      Wire.endTransmission();



      //SMALL DISPLAY

      //FOURTH
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x0A); //load x address

      Wire.write(0x00);
      Wire.write(smle[4]);             // DATA column 5
      Wire.write(smle[3]);             // DATA column 4
      Wire.write(smle[2]);             // DATA column 3
      Wire.write(smle[1]);             // DATA column 2
      Wire.write(smle[0]);             // DATA column 1


      Wire.endTransmission();

      //THIRD
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x10); //load x address


      Wire.write(smld[4]);             // DATA column 5
      Wire.write(smld[3]);             // DATA column 4
      Wire.write(smld[2]);             // DATA column 3
      Wire.write(smld[1]);             // DATA column 2
      Wire.write(smld[0]);             // DATA column 1


      Wire.endTransmission();


      //STRIPE OR SEMICOLUMN COLUMN
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x15); //load x address

      Wire.write(0x7F);             // 0x22 is semicolumn, 0x7F is stripe

      Wire.endTransmission();

      //SECOND
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x16); //load x address


      Wire.write(smlb[4]);             // DATA column 5
      Wire.write(smlb[3]);             // DATA column 4
      Wire.write(smlb[2]);             // DATA column 3
      Wire.write(smlb[1]);             // DATA column 2
      Wire.write(smlb[0]);             // DATA column 1


      Wire.endTransmission();

      //FIRST
      Wire.beginTransmission(0x3C);
      Wire.write(0x60); //device select
      Wire.endTransmission();
      Wire.beginTransmission(0x3C);
      Wire.write(0x1c); //load x address


      Wire.write(smla[4]);             // DATA column 5
      Wire.write(smla[3]);             // DATA column 4
      Wire.write(smla[2]);             // DATA column 3
      Wire.write(smla[1]);             // DATA column 2
      Wire.write(smla[0]);             // DATA column 1


      Wire.endTransmission();

    } //if mode != 0
  }

}

void getColumns(char c, uint8_t columns[numColumns]) {
  switch (c) {

    case 'A'...'Z':
      memcpy_P(&columns[0], &upperCase[c - 'A'][0], numColumns);
      break;

    case 'a'...'z':
      memcpy_P(&columns[0], &lowerCase[c - 'a'][0], numColumns);
      break;

    case '0'...'9':
      memcpy_P(&columns[0], &numerals[c - '0'][0], numColumns);
      break;

    case ' ':
      memcpy_P(&columns[0], &space[0], numColumns);
      break;

    case '!'...'/':
      memcpy_P(&columns[0], &symbolsa[c - '!'][0], numColumns);
      break;

    case '['...'`':
      memcpy_P(&columns[0], &symbolsb[c - '['][0], numColumns);
      break;

    case '{'...'~':
      memcpy_P(&columns[0], &symbolsc[c - '{'][0], numColumns);
      break;


    case '=':
      memcpy_P(&columns[0], &equalSymbol[0], numColumns);
      break;

    case '@':
      memcpy_P(&columns[0], &afnaSymbol[0], numColumns);
      break;



    default:
      memcpy_P(&columns[0], &unknown[0], numColumns);
      break;
  }

}

String in question is songNUMBER

Since songNUMBER is a String, it will manage its own memory usage properly. As long as you have a reasonable amount of free RAM (i.e. - "dynamic memory" in Arduino-speak), you should be just fine.

Thank you. I think that I`m having dynamic memory issues, because arduino freezes randomly and was thinking that this could be the issue.

Then look at how much free RAM you have AT RUNTIME, by using one of the many libraries that allows you to see how much memory is available at any time.

1 Like

I didnt know that is possible. I googled for ram usage check earlier today... ofcourse if I would google dynamic memory I would got the anwser.... Im looking at MemoryFree library atm and will try it out.

In my experience String is a RAM eater. This has ceased to be a problem since I started using strings instead of Strings.

That confused me, too, at first.

String is the Arduino-only library that simplifies character strings for new users.
When we say 'string', we mean C++ character strings.

Here is an explanation of what Strings do to RAM.

May I suggest that your loop() function is a mess.
It is a good practice to not do everything in the loop() function. Break it into a number of functions that you call from loop. In the long run it makes your code easier to read, modify or organize. (Especially if you need to revisit the sketch a year later).

Instead of

void loop(){
  if(test)
    {
       do lot's of stuff
    }
  if(test2)
    {
       do lot's of other stuff
    }
}

many dozens of times,
put the 'do stuff' code into separate functions:

void loop(){
  if(test) do lot's of stuff;
  if(test2) do lot's of other stuff
}

You should be able to test if there is a memory problem with songNUMBER by using .reserve()

I did check usage with memoryFree and its good, I have 720 - 700 left.
I setted timeouts for while loops and watchdog to 4s. Watchdog didnt trip yet, its good for now.

Most likely you are mis-managing a pointer, an array, or an interrupt somewhere.

I had just found the problem. It`s IBUS... there are just too many messages on it and my code serial read cant handle it.... Will try to solve that.

Solved by changing SoftwareSerial for AltSoftSerial.