-1

the code error says this and im not sure what to do please i need urgent help :(arduino code error message`

// Easy bluetooth controlled scrolling text


// by Yoruk for Instructable

// 26 02 15 : first code 
// 03 03 15 : buffer updating
// 04 03 15 : faster version, both buffers
// 05 03 15 : cleaning and help


/*
WIRING :
 pin 12 - DataIn of the first led matrix module
 pin 11 - CLK of the first led matrix module
 pin 10 - CS of the first led matrix module

 pin 9 : RX pin of the bluetooth module
 pin 8 : TX pin of the bluetooth module

 5V : 5v of the matrix module, 5v of the bluetooth module
 GND : the two GND signals of the matrix modules and the bluetooth module

 WARNING : Use a 3v3 arduino card (nano...) or a level converter !!!

 Wire the matrix modules in serie. See the Instructable steps.

 */



//Librairie for the LEDs matrix
#include "LedControl.h"

// virtual serial lib, used with bluetooth
#include <SoftwareSerial.h>

//How many matrixes we have ?
int MatrixNumber =5;


//virtual serial port bluetooth configuration
SoftwareSerial BT(8, 9);   //pin 8 : virtual RX    pin 9 :  virtual TX


// the delay between each screen display (ms)
int SpeedDelay = 12;


//total string lenght. The first message is 25 characters long (including spaces)
int LongueurChaine=25;


char incomingByte; //incoming data from the BT link


// the two pixels arrays
char Buffer[200];   //contient tout les pixels de TOUTE LA PHRASE
char Buffer_inverse[200]; //contient tout les pixels de TOUTE LA PHRASE, mais symetrises pour affichage sur ecran inverses

// the message array
char Phrase[50];

//here we set up the led matrix
LedControl lc=LedControl(12,11,10,MatrixNumber); 


// character lib
int fontDefinitions[480] = {
    0x00,0x00,0x00,0x00,0x00,/*space*/ // is 32 in ASCII
    0x00,0xF6,0xF6,0x00,0x00,/*!*/
    0x00,0xE0,0x00,0xE0,0x00,/*"*/
    0x28,0xFE,0x28,0xFE,0x28,/*#*/
    0x00,0x64,0xD6,0x54,0x08,/*$*/
    0xC2,0xCC,0x10,0x26,0xC6,/*%*/
    0x4C,0xB2,0x92,0x6C,0x0A,/*&*/
    0x00,0x00,0xE0,0x00,0x00,/*'*/
    0x00,0x38,0x44,0x82,0x00,/*(*/
    0x00,0x82,0x44,0x38,0x00,/*)*/
    0x88,0x50,0xF8,0x50,0x88,/***/
    0x08,0x08,0x3E,0x08,0x08,/*+*/
    0x00,0x00,0x05,0x06,0x00,/*,*/
    0x08,0x08,0x08,0x08,0x08,/*-*/
    0x00,0x00,0x06,0x06,0x00,/*.*/
    0x02,0x0C,0x10,0x60,0x80,/*/*/
    0x7C,0x8A,0x92,0xA2,0x7C,/*0*/
    0x00,0x42,0xFE,0x02,0x00,/*1*/
    0x42,0x86,0x8A,0x92,0x62,/*2*/
    0x44,0x82,0x92,0x92,0x6C,/*3*/
    0x10,0x30,0x50,0xFE,0x10,/*4*/
    0xE4,0xA2,0xA2,0xA2,0x9C,/*5*/
    0x3C,0x52,0x92,0x92,0x0C,/*6*/
    0x80,0x86,0x98,0xE0,0x80,/*7*/
    0x6C,0x92,0x92,0x92,0x6C,/*8*/
    0x60,0x92,0x92,0x94,0x78,/*9*/
    0x00,0x00,0x36,0x36,0x00,/*:*/
    0x00,0x00,0x35,0x36,0x00,/*;*/
    0x10,0x28,0x44,0x82,0x00,/*<*/
    0x28,0x28,0x28,0x28,0x28,/*=*/
    0x00,0x82,0x44,0x28,0x10,/*>*/
    0x40,0x80,0x8A,0x90,0x60,/*?*/
    0x7C,0x82,0xBA,0xBA,0x62,/*@*/
    0x3E,0x48,0x88,0x48,0x3E,/*A*/
    0xFE,0x92,0x92,0x92,0x6C,/*B*/
    0x7C,0x82,0x82,0x82,0x44,/*C*/
    0xFE,0x82,0x82,0x82,0x7C,/*D*/
    0xFE,0x92,0x92,0x92,0x82,/*E*/
    0xFE,0x90,0x90,0x90,0x80,/*F*/
    0x7C,0x82,0x82,0x8A,0x4E,/*G*/
    0xFE,0x10,0x10,0x10,0xFE,/*H*/
    0x82,0x82,0xFE,0x82,0x82,/*I*/
    0x84,0x82,0xFC,0x80,0x80,/*J*/
    0xFE,0x10,0x28,0x44,0x82,/*K*/
    0xFE,0x02,0x02,0x02,0x02,/*L*/
    0xFE,0x40,0x20,0x40,0xFE,/*M*/
    0xFE,0x60,0x10,0x0C,0xFE,/*N*/
    0x7C,0x82,0x82,0x82,0x7C,/*O*/
    0xFE,0x90,0x90,0x90,0x60,/*P*/
    0x7C,0x82,0x82,0x86,0x7E,/*Q*/
    0xFE,0x90,0x98,0x94,0x62,/*R*/
    0x64,0x92,0x92,0x92,0x4C,/*S*/
    0x80,0x80,0xFE,0x80,0x80,/*T*/
    0xFC,0x02,0x02,0x02,0xFC,/*U*/
    0xF8,0x04,0x02,0x04,0xF8,/*V*/
    0xFC,0x02,0x0C,0x02,0xFC,/*W*/
    0xC6,0x28,0x10,0x28,0xC6,/*X*/
    0xC0,0x20,0x1E,0x20,0xC0,/*Y*/
    0x86,0x8A,0x92,0xA2,0xC2,/*Z*/
    0x00,0x00,0xFE,0x82,0x00,/*[*/
    0x00,0x00,0x00,0x00,0x00,/*this should be / */
    0x80,0x60,0x10,0x0C,0x02,/*]*/
    0x20,0x40,0x80,0x40,0x20,/*^*/
    0x01,0x01,0x01,0x01,0x01,/*_*/
    0x80,0x40,0x20,0x00,0x00,/*`*/
    0x04,0x2A,0x2A,0x2A,0x1E,/*a*/
    0xFE,0x12,0x22,0x22,0x1C,/*b*/
    0x1C,0x22,0x22,0x22,0x14,/*c*/
    0x1C,0x22,0x22,0x12,0xFE,/*d*/
    0x1C,0x2A,0x2A,0x2A,0x18,/*e*/
    0x10,0x7E,0x90,0x80,0x40,/*f*/
    0x18,0x25,0x25,0x25,0x1E,/*g*/
    0xFE,0x10,0x10,0x10,0x0E,/*h*/
    0x00,0x12,0x5E,0x02,0x00,/*i*/
    0x02,0x01,0x01,0x11,0x5E,/*j*/
    0xFE,0x08,0x08,0x14,0x22,/*k*/
    0x00,0x82,0xFE,0x02,0x00,/*l*/
    0x3E,0x20,0x1C,0x20,0x1E,/*m*/
    0x3E,0x20,0x20,0x20,0x1E,/*n*/
    0x1C,0x22,0x22,0x22,0x1C,/*o*/
    0x3F,0x24,0x24,0x24,0x18,/*p*/
    0x18,0x24,0x24,0x3F,0x01,/*q*/
    0x3E,0x10,0x20,0x20,0x10,/*r*/
    0x12,0x2A,0x2A,0x2A,0x04,/*s*/
    0x00,0x10,0x3C,0x12,0x04,/*t*/
    0x3C,0x02,0x02,0x02,0x3E,/*u*/
    0x30,0x0C,0x02,0x0C,0x30,/*v*/
    0x38,0x06,0x18,0x06,0x38,/*w*/
    0x22,0x14,0x08,0x14,0x22,/*x*/
    0x38,0x05,0x05,0x05,0x3E,/*y*/
    0x22,0x26,0x2A,0x32,0x22,/*z*/
    0x00,0x10,0x6C,0x82,0x82,/*{*/
    0x00,0x00,0xFF,0x00,0x00,/*|*/
    0x04,0x02,0xFF,0x02,0x04,/*|, arrow*/
    0x82,0x82,0x6C,0x10,0x00,/*}*/
    0x08,0x10,0x18,0x08,0x10/*~*/
};



void setup() {

    //matrix modules init
    for(int adresse=0;adresse<MatrixNumber;adresse++) {
        /*The MAX72XX is in power-saving mode on startup*/
        lc.shutdown(adresse,false);
        /* Set the brightness to a medium values */
        lc.setIntensity(adresse,4);
        /* and clear the display */
        lc.clearDisplay(adresse);
    }

//    BufferBuilding("Hi ! Sent me a message...", 25);   //first message on the led screen


    BufferBuilding("text", 4);   //first message on the led screen


    Serial.begin(9600); //we also set the normal serial link, for debug

    BT.begin(9600);      // bluetooth initialisation

    //we sent a message on the phone to tell the user that he can do someting...
    BT.println("Hi ! I'm waiting for a message. Type it and press SEND."); 

}



void loop() { 

    DrawText( LongueurChaine); //draw the message, in a loop


    //or, if we get something on the virtual bluetooth port...
    if (BT.available() > 0) {

        LongueurChaine = BT.available(); //incoming string lenght

        for  (int i = 0; i < LongueurChaine; i++) {

            // read the incoming byte:
            incomingByte = BT.read();

            Phrase[i] = incomingByte; ///store the character into the string array

        }

        //debug features, to check :
        Serial.print("Display: ");
        Serial.println(Phrase);
        Serial.print("Length : ");
        Serial.println(LongueurChaine);

        //buffers cleaning, to store the new message
        for(int k = 0; k < 200; k++) {
            Buffer[k]=0;
            Buffer_inverse[k]=0;

        }

        //we create the new buffers, so the new message will be drawn when leaving the sub
        BufferBuilding(Phrase, LongueurChaine);
    }

}



void BufferBuilding(char * stringToDisplay, byte stringLength)
{
    int i =0;

    //loop on every characters (on the string)
    for(int k = 0; k < stringLength; k++) {
        //here we call the characters library  
        int caract= k;   
        Buffer[i+0] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 0];  
        Buffer[i+1] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 1];  
        Buffer[i+2] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 2];  
        Buffer[i+3] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 3];  
        Buffer[i+4] =  fontDefinitions[((stringToDisplay[caract] - 32) * 5) + 4];  
        Buffer[i+5] =  B00000000;  //one blank column of leds between two characters
        i=i+6;
    }

    // here, we create a second buffer, to display the message on the switched matrixes
    for(int k = 0; k < stringLength*6; k++) {
        for(int i = 0; i < 8; i++) {
            bitWrite(  Buffer_inverse[k] ,i,  bitRead(Buffer[k] ,7-i) )   ;
        }
    }
}



void DrawText( byte stringLength) {

    for(int k = 0; k < stringLength*6; k++) { 

        delay(SpeedDelay);


//delay(10000);
        //k is the column

        //buffer drawing
        for (int m = 0; m < MatrixNumber; m++) {  //loop on the matrix                     
            if (m % 2 ==  0) //check is the module is upside-down or not...
            {
                //here, the matrix is flipped upside-down                
                for (int i = 0; i < 8; i++) {  //loop on the columns

                      lc.setRow(m,7-i,Buffer[i+k+8*m]);
                }
            }
            else
            {
                //classical   
                for (int i = 0; i < 8; i++) {  //loop on the columns


                       lc.setRow(m,i,Buffer_inverse[i+k+8*m]);
                }
            }
        }
    }

}

closed as unclear what you're asking by VE7JRO, sempaiscuba, Greenonline, MatsK, Juraj Nov 17 '18 at 16:33

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    It means you are using too much RAM on the microcontroller. Follow Juraj suggestion. – MichaelT Oct 27 '18 at 15:25
  • "im not sure what to do": You need to reduce the amount of RAM space (variables, strings, constants, large or numerous arrays) by moving constants, especially large ones like strings, to program memory. But without seeing your code, we can only guess. With only 5K of code and nearly 2K of globals, it does seem likely that you have used a lot of space for strings, and those are often easy to move to program memory. Show us the code if it isn't too huge, or at least gives us some clues from which to help you better. – JRobert Oct 27 '18 at 15:32
  • 2
    Please provide source code if you want help. – Andre Courchesne Oct 27 '18 at 16:09
  • how do i post the code here? its too long to be posted in the comments – Sam Oct 28 '18 at 7:37
  • Edit your question and format it correctly by selecting the code portion and click the {} button, or press Ctrl+k – chrisl Oct 28 '18 at 8:47
3

The font definition table takes 960 bytes of RAM - nearly 1/2 of the the total usage. You can regain 480 bytes just by declaring that array as uint8_t; 1 byte each entry instead of 2 bytes each for ints. You can regain the remaining 480 if you still need to, by moving that table to program memory. The Arduino.cc site has a good discussion with examples. Just pay attention to the data-types you use if you do that; the functions to read data out of program memory each return one specific type.

-1

You can free up RAM by moving large arrays and strings into Flash. By default all strings and arrays are placed into RAM. The disadvantage to putting data into Flash is that you will not be able to modify it at runtime.

To place an array in Flash use the PROGMEM compiler directive:

static const unsigned char PROGMEM my_array[] = { 0x00, 0x01, 0x02 ... };

When doing this your likely to notice, besides more available RAM, that many library functions can longer access the array you've placed into FLASH. The AVR microcontrollers have to use special instructions to read data out of Flash memory. Some library functions handle this automatically but many do not. In order to access the data you'll have to implement a function that copies the data out of Flash and into RAM.

Here is an example of a function to copy Flash data into RAM:

char *Get_Flash_String(const char *FlashString)
{
    static char buff[MAX_FLASH_STRING_LENGTH+1];
    int i, len;

    len = strlen_P(FlashString);
    for (i = 0; i <= len; i++)
        buff[i] = pgm_read_byte_near(FlashString + i);

    return(buff);
}

Note that the function above assumes you're reading a NULL terminated string out of flash. If you're reading an array you don't want to use strlen() to determine the length.

  • this answer is too general but not general. confusing. show him how to use it for his case. – Juraj Oct 28 '18 at 15:36
  • Perhaps it's better to teach a hungry man to fish, rather than hand him a fish? – Jeff Wahaus Oct 28 '18 at 15:59
  • from this answer he learns nothing. the link in JRobert's answer is usefull. first I added it as comment, but then I deleted it, to not to confuse OP. changing the type of array item gains him memory for now – Juraj Oct 28 '18 at 16:40
  • And you've been granted permission to speak for another person? – Jeff Wahaus Oct 28 '18 at 18:19
  • no. I always comment why I down-vote – Juraj Oct 28 '18 at 18:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.