Memory Issues

Hi Forum,
I am making a robot that is designed to tweet a String about Mao everytime it turns. I have it situated out into three files, a main file (tweeting) a file that includes all my twitter security codes (not posting that :smiling_imp: ) and one with functions to drive the robot. I have not completely finished but I have run into a problem. I ran out of memory. It says the following:

Sketch uses 15,056 bytes (52%) of program storage space. Maximum is 28,672 bytes.
Global variables use 2,836 bytes (110%) of dynamic memory, leaving -276 bytes for local variables. Maximum is 2,560 bytes. Not enough memory; see for tips on reducing your footprint.

This leads me to believe that the many #define statements in the beginning is taking up all the space but I thought that #define takes no memory. Also, I have a 32GB micro-SD card in the Y√ļn. Why do I have so little storage. The code is below. PLEASE RESPONFQUICKLY THIS IS DUE IN A COUPLE OF HOURS!!!

Main File

#include <Temboo.h>
#include <Bridge.h>
#include "TembooAccount.h" // contains Temboo account information

//conatains functions to drive robot
int numRuns = 1;   // execution count, so this sketch doesn't run forever
int maxRuns = 1;  // the max number of times the Twitter Update Choreo should run
int quoteCounter;  //make a counter for the quotes
int motorCounter;  //make a counter for the motor
                    //declare the tweets
  #define tweet1  "1949 - Mao becomes Chairman of China"  
  #define tweet2 "1949 Foreign Affairs - Mao gets Stalin to sign a treaty for economic aid"
  #define tweet3 "1956 - Culture - Mao ecourages 'a hundred flowers to bloom', telling intellectuals to speak out"
  #define tweet4 "Mao then targetted the imtellectuals who had spoken out for improvement"
  #define tweet5 "1958 - Mao launchs The #Great #Leap #Forward"
  #define tweet6 "He encouraged people to set up 'people's communes' telling them to disolve private property"
  #define tweet7 "People did not have resources or administration to manage such large social units"
  #define tweet8 "In an effort to please Mao party officials left very little grain for people, most of it sent to the governemnt"
  #define tweet9 "'Backyard steel' created in an attempt to rapidly industrialize China was useless and consumed rescources."
  #define tweet10 "The result was economic disaster"
  #define tweet11 "1959 - Mao realises change is needed."
  #define tweet12 "1966 - Culture - The Great Proletariat #Cultural #Revolution"
  #define tweet13 "Mao purged many officials whom he doubted to have loyalty."
  #define tweet14 "Called for students to become 'Red Guards' an organized group of Mao followers who act as his 'civilian police force'"
  #define tweet15 "Red Guards rampaged through cities to destroy fourolds - old culture, habits, beliefs and traditions"
  #define tweet16 "Red Guards attacjed and humiliated people from a 'bad class status' either intellectuals or those from a wealthy family"
  #define tweet17 "This created great chaos, violence, injury and death"
  #define tweet18 "1966 - Mao Zhuxi Yulu or the Sayings of Mao, often known as the #Little_Red_Book, was published"
  #define tweet19 "August 1966 - Culture - Lao She, a famous plaright is beaten to death by Red Guards"
  #define tweet20 "1972 - Foreign Affairs - Nixon Visits China"  
  #define tweet21 "Mao is able to part differences with capiltalists to his benefit"
  #define tweet22 "US agrees to aid China if Taiwan(the nationalists) tries to take China"
  #define tweet23 "US used to support nationalists, Mao made China a more valuable ally"
  #define tweet24 "Culture -'Model Dramas' proposed, plays that reflect class struggle and revolutionary action. #propaganda"
  #define tweet25 "People of 'bad class status' sent to work in fields or imprisoned"
  #define tweet26 "The end result: 1.5 million murdered, a million more tortured, imprisoned, humiliated and robbed of property."

void setup() {



void loop(){

 if (numRuns <= maxRuns) {
    // define the text of the tweet we want to send
    String tweetText;

    TembooChoreo StatusesUpdateChoreo;

    // invoke the Temboo client
    // NOTE that the client must be reinvoked, and repopulated with
    // appropriate arguments, each time its run() method is called.
    // set Temboo account credentials

    // identify the Temboo Library choreo to run (Twitter > Tweets > StatusesUpdate)
    // add the Twitter account information
    StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN);
    StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET);
    StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_API_KEY);    
    StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_API_SECRET);
//switch statement evaluates which tweet to tweet

 case 1:
  tweetText = tweet1;

 case 2:
  tweetText = tweet2;
 case 3:
  tweetText = tweet3;
 case 4:
  tweetText = tweet4;

 case 5:
  tweetText = tweet5;
 case 6:
  tweetText = tweet6;
 case 7:
  tweetText = tweet7;
 case 8:
  tweetText = tweet8;
 case 9:
  tweetText = tweet9;
 case 10:
  tweetText = tweet10;
 case 11:
  tweetText = tweet11;
 case 12:
  tweetText = tweet12;\
 case 13:
  tweetText = tweet13;
 case 14:
  tweetText = tweet14;
 case 15:
  tweetText = tweet15;
 case 16:
  tweetText = tweet16;
 case 17:
  tweetText = tweet17;
 case 18:
  tweetText = tweet18;
  case 19:
  tweetText = tweet19;
 case 20:
  tweetText = tweet20;
 case 21:
  tweetText = tweet21;

 case 22:
  tweetText = tweet22;

 case 23:
  tweetText = tweet23;
 case 24:
  tweetText = tweet24;
 case 25:
  tweetText = tweet25;
 case 26:
  tweetText = tweet26;

    // and the tweet we want to send
    StatusesUpdateChoreo.addInput("StatusUpdate", tweetText);

    // tell the Process to run and wait for the results. The 
    // return code (returnCode) will tell us whether the Temboo client 
    // was able to send our request to the Temboo servers
    unsigned int returnCode =;

    // a return code of zero (0) means everything worked
   /* if (returnCode == 0) {
        Serial.println("Success! Tweet sent!");
    } else {
      // a non-zero return code means there was an error
      // read and print the error message
      while (StatusesUpdateChoreo.available()) {
        char c =;

    // do nothing for the next 90 seconds


Robot File

#define aDirection  12      //define the pins
#define bDirection 13       
#define aSpeed 3
#define bSpeed 11
#define aBrake 9
#define bBrake 8

void moveForward(){

digitalWrite(aBrake, LOW); //disable brakes
digitalWrite(bBrake, LOW);
digitalWrite(aSpeed, 100); //set speed to 100
digitalWrite(bSpeed, 100);
digitalWrite(aDirection, HIGH); //set direction to forward
digitalWrite(bDirection, HIGH);


void turnAround(){

digitalWrite(aDirection, LOW); 
digitalWrite(bDirection, HIGH);
digitalWrite(aSpeed, 100);
digitalWrite(bSpeed, 100);


/*void setupRobot(){
pinMode(aBrake, OUTPUT); 
pinMode(bBrake, OUTPUT);
pinMode(aDirection, OUTPUT);
pinMode(bDirection, OUTPUT);
pinMode(aSpeed, OUTPUT);
pinMode(bSpeed, OUTPUT);

UPDATE: I also tried making an array with all the tweets in it and then just making tweetText = array[quoteCounter]. This used up even more memory. PLEASE HELP!!!

Arduino Yun sending tweets without Temboo

Weird things happening when code gets long

make sure move most code into Yun side.

put all the tweet1-26 into one text file, read it into python array.

f = open('filenameoftweettext ')
lines = f.readlines()

pass Parameter 0-25 back to python file.
send out lines(0) - lines(25) to tweet

This leads me to believe that the many #define statements in the beginning is taking up all the space but I thought that #define takes no memory. Also, I have a 32GB micro-SD card in the Y√ļn. Why do I have so little storage. The code is below. PLEASE RESPONFQUICKLY THIS IS DUE IN A COUPLE OF HOURS!!!!

Waiting until the last minute? :smiling_imp:

#define doesn't take up memory when you define it, but does when you use it. There is no free lunch, those strings must be defined somewhere, or else the code would not be able to access them. sonnyu's suggestion is a good one: write a Python scrip that takes a number as a parameters and prints out the desired string. Then use the Process class in the Arduino sketch to run the Python script, and read the result.

Another idea: put each individual quote on the SD card in files like 1.txt, 2.txt, etc. then use the Yun's FileIO class to read each file as it is needed. (This would give the Arduino sketch access to that 32G of SD card space, which it can't access directly.)

Also, I have a 32GB micro-SD card in the Y√ļn. Why do I have so little storage.

Because the Atmel ATmega32u4 chip simply has only 2.5KB of usable RAM!

You simply have to design your programs accordingly, you can't just wildly allocate arrays and dynamic structures at will.

One of the biggest tripwires for most people is that on the AVR chips, each and every string used in your sketch will take up precious RAM space! They are not (only) stored in code space, as in most other programming environments.

The #define statements itself won't take any space, but the assignments in the case statement will. Put them straight in the case statement, surrounded by the F() macro or check up on the use of PROGMEM. Those will leave those constant strings in code space (FlashROM) only, with a small internal overhead for the different way how those strings will be loaded...