CC3000 shield simple sketch exceeds UNO memory limit

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
davide3
 
Posts: 49
Joined: Wed Aug 14, 2013 5:21 pm

CC3000 shield simple sketch exceeds UNO memory limit

Post by davide3 »

I have the CC3000 shield: http://www.adafruit.com/products/1491

and easily got it to talk with Xively using this nice tutorial...

http://learn.adafruit.com/adafruit-cc30 ... ino-sketch

...simplified (for testing purposes) to just put out a constant value instead of reading sensors.

That's here:

Code: Select all

 int weight = 35;
I also commented out the libraries that were not needed (though that didn't shrink the compiled size at all).

The full tutorial code with my simplifications is at bottom of this post.

On compile, the IDE says it uses 22,208 of 32,256 bytes. It works fine...data goes to Xively, makes a nice plot with a flat line at 35 (pounds).

Then, to test out the SD card part of the CC3000 shield, I add the following lines in the declaration part:

Code: Select all

#include <SD.h>
File myFile;
and the following in the setup() part:

Code: Select all

 
  pinMode(4, OUTPUT);
  if (!SD.begin(4)) {
    Serial.println(F("SDinitFail"));
    return;
  }
 
 myFile = SD.open("test.txt", FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print(F("Rite test.txt"));
    myFile.println(F("test 123"));
	// close the file:
    myFile.close();
    Serial.println(F("SDsaveDone"));
  } else {
    // if the file didn't open, print an error:
    Serial.println(F("ErrOpng test.txt"));
  }
  
Adding that small amount of code balloons the sketch up to 32,596 bytes and it fails to compile because it is too large.

It is hard to believe that such a seemingly simple sketch can kill the UNO and drive me to a MEGA.

Am I doing something wrong? I don't see an easy way to trim any fat out of this; is there a way to shrink it down?

Thank you,
Dave



Started with this:

Code: Select all

/*************************************************** 
  This is a sketch to use the CC3000 WiFi chip & Xively
  
  Written by Marco Schwartz for Open Home Automation
 ****************************************************/
// Libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>

// tutorial had these libs...not needed
//#include <ccspi.h> //compiles fine without it
//#include <string.h> //compiles fine without it
//#include "utility/debug.h" //compiles fine without it
//#include "DHT.h" //compiles fine without it...4 the sensors
//#include<stdlib.h> //compiles fine without it

// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

// Create CC3000 instances
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2); // you can change this clock speed
                                        
// WLAN parameters
#define WLAN_SSID       "blahblahblah"
#define WLAN_PASS       "moreblahblah"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

// Xively parameters
#define WEBSITE  "api.xively.com"
#define API_key  "abigstringoflettersandnumbersgoesherethislongzzz"
#define feedID  "ninenumbersgohere"

uint32_t ip;

void setup(void)
{
  // Initialize
  Serial.begin(115200);
  
  Serial.println(F("\nInit..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Fail begin()-Chk wires"));
    while(1);
  }
 
}

void loop(void)
{
  // Connect to WiFi network
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("\nCnctd 1"));
  
  /* Wait for DHCP to complete */
  Serial.println(F("RqustDHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }  

  // Get the website IP & print it
  ip = 0;
  Serial.print(WEBSITE); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Cdn't rslve"));
    }
    delay(500);
  }
  cc3000.printIPdotsRev(ip);
  
  int weight = 35;
  
  // Prepare JSON for Xively & get length
  int length = 0;

  String data = "";
  data = data + "\n" + "{\"version\":\"1.0.0\",\"datastreams\" : [ {\"id\" : \"SouthPostWeight\",\"current_value\" : \"" + String(weight) + "\"}]}";
  
  length = data.length();
  
  //Serial.print("Data length");
  //Serial.println(length);
  //Serial.println();
  
  // Print request for debug purposes
  //Serial.print("PUT /v2/feeds/");
  //Serial.print(feedID);
  //Serial.println(".json HTTP/1.0");
  //Serial.println("Host: api.xively.com");
  //Serial.print("X-ApiKey: ");
  //Serial.println(API_key);
  //Serial.print("Content-Length: ");
  //Serial.println(length, DEC);
  //Serial.print("Connection: close");
  //Serial.println();
  //Serial.print(data);
  //Serial.println();
  
  // Send request
  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
  if (client.connected()) {
    Serial.println(F("Cnctd 2"));
    client.println("PUT /v2/feeds/" + String(feedID) + ".json HTTP/1.0");
    client.println("Host: api.xively.com");
    client.println("X-ApiKey: " + String(API_key));
    client.println("Content-Length: " + String(length));
    client.print("Connection: close");
    client.println();
    client.print(data);
    client.println();
  } else {
    Serial.println(F("Conn faild"));    
    return;
  }
  
  // echos reply...apparently necessary
  Serial.println(F("----------"));
  while (client.connected()) {
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }
  client.close();
  
  Serial.println(F("----------"));
    
  //Serial.println(F("\nDscnctng"));
  Serial.println(F("Dscnctng"));
  cc3000.disconnect();
  
  // Wait 60 seconds until next update
  delay(60000);
  
}

User avatar
adafruit_support_bill
 
Posts: 88142
Joined: Sat Feb 07, 2009 10:11 am

Re: CC3000 shield simple sketch exceeds UNO memory limit

Post by adafruit_support_bill »

There are some tips for optimizing memory usage here: http://learn.adafruit.com/memories-of-an-arduino
But, as you say, there is just a small amount of code there. Unfortunately, both the CC3000 and SD libraries are fairly large libraries and the Arduino has limited resources. You could try to remove some of the library functionality you are not using. But that has other risks associated wth it.

User avatar
davide3
 
Posts: 49
Joined: Wed Aug 14, 2013 5:21 pm

Re: CC3000 shield simple sketch exceeds UNO memory limit

Post by davide3 »

Thank you for the reply. I don't know enough about what's going on in those libraries to dare mess with them.

I wouldn't have bought the CC3000 shield if I had known that I couldn't use the SD part of it with the UNO.

It would be helpful to make that clear in the product page (which currently says "For use with Arduino Uno & Mega only at this time - we'll try to get the code ported to the Leonardo/Due at some point but no ETA.")

User avatar
pocketmoon
 
Posts: 78
Joined: Fri Dec 27, 2013 8:21 pm

Re: CC3000 shield simple sketch exceeds UNO memory limit

Post by pocketmoon »

When you're close to the limit it's not too tricky saving enough bytes to get back under:

Comment out anything you don't need like

cc3000.printIPdotsRev(ip);


Once I was happy with the way I was using the CC3000 I went through the CC3000 libs and commented out ALL the CC3KPrinter calls.
e.g.

// We can abort a scan with a time of 0
// if (time)
// {
// if (CC3KPrinter != 0) {
// CC3KPrinter->println(F("Start AP/SSID scan\n\r"));
// }
// }

User avatar
davide3
 
Posts: 49
Joined: Wed Aug 14, 2013 5:21 pm

Re: CC3000 shield simple sketch exceeds UNO memory limit

Post by davide3 »

pocketmoon - thanks! That sounds like something I can handle; I will give it a try.

But I also want to use the LCD and Chronodot real-time clock libraries with the CC3000, so in the long run, I think I'm hosed.

Dave

PS: I just realized that I may not need the Chronodot lib, since I can get internet time from the CC3000. But using the internet time part of the CC3000 library will probably increase the memory usage, anyway. So I'm probably still hosed. We'll see.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”