sketch uses to much sram.

Hello all,

I hope you can help me with my problem, i made a sketch witch uses to mutch sram.
The uno kan only handle about 2k of sram but my sketch uses 2.311 bytes.
I have already used some trimming but i cant make it fit.

Here is my code:

#include <SimpleSoftwareServo.h>
#include <SPI.h>
#include "Adafruit_BLE_UART.h"
#include "WaveUtil.h"
#include "WaveHC.h"

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're playing
WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

SimpleSoftwareServo servo1;
char servo1_pin = 2;
byte pos = 0;    // variable to store the servo position 

char ledPin1 = 19;

// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_RDY 2     // This should be an interrupt pin, on Uno thats #2 or #3

    Configure the Arduino and start advertising with the radio
void setup(void)
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    while(1);                            // then 'halt' - do nothing!
  // enable optimize read - some cards may timeout. Disable if you're having problems
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  if (part == 5) {                       // if we ended up not finding one  :(
    while(1);                            // then 'halt' - do nothing!
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    while(1);                             // then 'halt' - do nothing!

  while(!Serial); // Leonardo/Micro should wait for serial init
  BTLEserial.setDeviceName("IronMan"); /* 7 characters max! */


    Constantly checks for new events on the nRF8001
aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;

void loop()
  // Tell the nRF8001 to do whatever it should be working on.

  // Ask what is our current status
  aci_evt_opcode_t status = BTLEserial.getState();
  // If the status changed....
  if (status != laststatus) {
    // print it out!
    if (status == ACI_EVT_DEVICE_STARTED) {
        Serial.println(F("J.A.R.V.I.S searching for Device"));
    if (status == ACI_EVT_CONNECTED) {
        Serial.println(F("J.A.R.V.I.S Connected!"));
    if (status == ACI_EVT_DISCONNECTED) {
        Serial.println(F("J.A.R.V.I.S disconnected or advertising timed out"));
    // OK set the last status change to this one
    laststatus = status;

  if (status == ACI_EVT_CONNECTED) {
    // Lets see if there's any data for us!
    if (BTLEserial.available()) {} 
    String input = "";
    // Read any serial input
    while (BTLEserial.available() > 0)
        input += (char); // Read in one char at a time
        delay(5); // Delay for 5 ms so the next char has time to be received
    if (input == "on")

        digitalWrite(ledPin1, HIGH); // on  
        for(pos = 0; pos <= 120; pos += 1) // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    servo1.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(5);                       // waits 15ms for the servo to reach the position
     else if (input == "off")
        digitalWrite(ledPin1, LOW); // off 
        for(pos = 120; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees 
    servo1.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(5);                       // waits 15ms for the servo to reach the position


    // Next up, see if we have any data to get from the Serial console

    if (Serial.available()) {
      // Read a line from Serial
      Serial.setTimeout(100); // 100 millisecond timeout
      String s = Serial.readString();

      // We need to convert the line to bytes, no more than 20 at this time
      uint8_t sendbuffer[20];
      s.getBytes(sendbuffer, 20);
      char sendbuffersize = min(20, s.length());

      Serial.print(F("\n* Sending -> \"")); Serial.print((char *)sendbuffer); Serial.println("\"");

      // write the data
      BTLEserial.write(sendbuffer, sendbuffersize);

// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  while (wave.isplaying) {
  // do nothing while its playing
  // now its done playing
void playfile(char *name) {
  // see if the wave object is currently doing something
  if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
  // look in the root directory and open the file
  if (!, name)) {
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
  // ok time to play! start playback;

My question is if its possible to trim it some more or do i have to upgrade to a mega?
I realize i have a lot of big libraries but i need them all for my project.

if you need all those libs then the MEGA is the way to go (or divide functionality over 2 UNO's?)

Or a '1284P - 16K SRAM to play in, twice that of a Mega. 32 IO, dual hardware serial ports, 128K flash.
Here’s one of several 1284P board types I offer.

Thanks for the fast replies guys!!

So there is no way for me to do some coding magic and make it fit on an uno?
To bad, i already orderd a arduino mini pro.

You've already got your serial prints in flash, and you don't have a lot of code in your sketch.
Look at my website, I have other '1284P form factors if it's small that you're after.

You could look for alternative libs
#include <Servo.h>
#include <SimpleSoftwareServo.h>

you could strip the used libs to a minimum (although compiler might already do a good job there)

Which version of the IDE are you using?

Can you post the verbose output of the compilation?

Can you post links to the libs used?

The servo.h lib isnt compatible with the “Adafruit_BLE_UART.h” lib, it uses the same timer.

I went through my code again and found out that if i exclude this line;


It only uses about half of the sram, but without this line the sketch wont compile/work.
(found this out by simply adding line for line untill my sketch was using to much sram.)

I know this line is using the Adafruit_BLE_UART.h library but is there any way i can alter the line so that my sketch wil fit on an uno?

links to the libs;

wavehc & WaveUtil

(sorry for my bad enlish)

There is a RX buffer in the BLE library (.cpp) of 64 bytes which might be oversized? 32 might be big enough?

do not see so quickly why it uses that much RAM