how to solve low memory

hello i have codes and this message appear

how can i solve that?

Hi noura91

Your program is trying to use too much memory for storing variables.

Please post your code - use [nobbc][code] [/code][/nobbc] tags so people can look at it.

There may be ways to reduce the memory usage.

Regards

Ray

thankx for replaying

these are the codes

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include <stdlib.h>

const int IN1=4;
const int IN2=2;
const int IN3=7;
const int IN4=8;
  char input;

// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2); // you can change this clock speed

#define WLAN_SSID       "aa"   // cannot be longer than 32 characters!
#define WLAN_PASS       "0000"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define LISTEN_PORT           80      // What TCP port to listen on for connections.  
                                      // The HTTP protocol uses port 80 by default.
                                      
Adafruit_CC3000_Server httpServer(LISTEN_PORT);

String readString;

void setup()
{
   
pinMode( IN1 ,OUTPUT);// Right Motor 1st wire
pinMode( IN2 ,OUTPUT);// Right Motor 2nd wire
pinMode( IN3 ,OUTPUT);// left Motor 1st wire
pinMode( IN4 ,OUTPUT);// left Motor 2nd wire

Serial.begin(115200);

// analogWrite(E1, 0);
  Serial.println(F("Hello, CC3000!\n")); 

  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
  
   
  // Initialise the module
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
  
  Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
   
  Serial.println(F("Connected!"));
  
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }  

  // Display the IP address DNS, Gateway, etc.
  while (! displayConnectionDetails()) {
    delay(1000);
  }
  // Start listening for connections
  httpServer.begin();
  
  Serial.println(F("Listening for connections..."));

}

void loop() {
  
    // Try to get a client which is connected.
  Adafruit_CC3000_ClientRef client = httpServer.available();
  
   if (client) 
  {
    delay(5);
    Serial.println(F("Client connected."));
    // Process this request until it completes or times out.
    // Note that this is explicitly limited to handling one request at a time!

    // An HTTP request ends with a blank line
        boolean currentLineIsBlank = true;
        
        
        while (client.connected()) 
        {
          
            if (client.available())
            {
                char c = client.read();
                //Serial.write(c);
                // If you've gotten to the end of the line (received a newline
                // character) and the line is blank, the HTTP request has ended,
                // so you can send a reply.
                if (readString.length() < 100) {
                    readString += c;
                    Serial.print(c);
                }
                
                if (c == '\n' && currentLineIsBlank) {
                  
                  client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println();
                    client.println("<!DOCTYPE HTML>"); 
                    
                    //send the HTML stuff
                    client.println("<html><head><title>Randi Control Panel</title><style type=\"text/css\">");
                    client.println("body { font-family: sans-serif }");
                  /*
                    client.println("h1 { font-size: 14pt; }");
                    client.println("p  { font-size: 10pt; }");
                    client.println("a  { color: #2020FF; }");
                    client.println("</style>");
                    client.println("</head><body text=\"#A0A0A0\" bgcolor=\"#080808\">");
                 */ 
                    client.println("<h1>Randi Controls</h1>
");
                  
                    client.println("<form method=\"link\" action=\"/forward\"><input type=\"submit\" value=\"Go!\"></form>");
                    client.println("<form method=\"link\" action=\"/backward\"><input type=\"submit\" value=\"Reverse!\"></form>");
                   client.println("<form method=\"link\" action=\"/stop\"><input type=\"submit\" value=\"Stop\"></form>");
                  
                    client.println("<form method=\"link\" action=\"/Fleft\"><input type=\"submit\" value=\"Front Left\"></form>");
                    client.println("<form method=\"link\" action=\"/Fright\"><input type=\"submit\" value=\"Front Right\"></form>");
                    client.println("<form method=\"link\" action=\"/Bleft\"><input type=\"submit\" value=\"Back Left\"></form>");
                    client.println("<form method=\"link\" action=\"/Bright\"><input type=\"submit\" value=\"Back Right\"></form>");
                    client.println("
");
                    client.println("</body></html>"); 
                    client.println();
                    break; 
                }
                
                if (c == '\n') {
                  // You're starting a new line.
                  currentLineIsBlank = true;
                }
                else if (c != '\r') {
                  // You've gotten a character on the current line.
                  currentLineIsBlank = false;
                }
                 
            }
        }
        // Give the web browser time to receive the data.
          
         process(client);
        
          readString = "";
  }
 
        
  }  
        
 void process (Adafruit_CC3000_ClientRef client)
{       
   if(readString.length() > 0){
    if (readString.indexOf("/forward") > 0)
      {
  // put your main code here, to run repeatedly:
/*if (Serial.available()) {
    // read the most recent character
    */
 //  input = Serial.read();
    // switch based on the character
  //  switch(input){
    //  case 'F': 
        // forward
  analogWrite(IN1,0);
  analogWrite(IN2,255);
  analogWrite(IN3,255);
  analogWrite(IN4,0);
   //break;
  }
  else if (readString.indexOf("/backward") > 0)
      {
   //   case 'B':  // backwards
           // v=Serial.read();
   analogWrite(IN1,200);
  analogWrite(IN2,0);
  analogWrite(IN3,0);
  analogWrite(IN4,200);
  // break;
      }
   //   case 'S':  // stop
   
    else if (readString.indexOf("/stop") > 0)
      {
        analogWrite(IN1,0);
        analogWrite(IN2,0);
        analogWrite(IN3,0);
        analogWrite(IN4,0);
     //   break;
      }
     // case 'L':  // left
      else if (readString.indexOf("/left") > 0)
      {   
  analogWrite(IN1,0);
  analogWrite(IN2,150);
  analogWrite(IN3,0);
  analogWrite(IN4,200);
      }
      //  break;
    //  case 'R':  // right
   else if (readString.indexOf("/right") > 0)
      { 
  analogWrite(IN1,150);
  analogWrite(IN2,LOW);
  analogWrite(IN3,200);
  analogWrite(IN4,LOW);
      }//  break;
   //   default:    // if character not recognized then stop
      else if (readString.indexOf("/stop") > 0)
      {
        analogWrite(IN1, 0);
        analogWrite(IN3, 0);
    //    break;
    }
}}


// Tries to read the IP address and other connection details
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  
  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}

Too many libaries, try and do without string and stdlib for a start.

the same problem :slightly_frowning_face:

how can i know how many KB these codes so if i buy Mega will solve this problem?

Use the F Macro to place string literals in flash and free SRAM. F macro will work with client.print, too.

client.println("HTTP/1.1 200 OK");

becomes:

client.println(F("HTTP/1.1 200 OK"));
int freeRam () {
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}

This function returns the number of available bytes in RAM. If you've already used all the RAM, it might not work well or return a negative number.

EDIT: misunderstood what the problem was, never mind...

thanx guys I tried all, that but seems need another memory or another kind of arduino is mega will be enough? and how can i know how many bytes is my codes and arduino mega how much can handle?

The compiler will tell you how much memory you are using, the product spec page will tell you how much memory a particular board has. Did you apply the F() macro to all the HTML?

AWOL: The compiler will tell you how much memory you are using, the product spec page will tell you how much memory a particular board has. Did you apply the F() macro to all the HTML?

thaank u thats work ro tell the truth i tried on some of them but the same problem was accure so i said that not working but know its compiling fine

and big thanks to groundfungus also :)

but wat does F() do exactly ?

The F() macro ensures that constant strings remain in flash where they belong, and don't get copied to RAM.

aha i got it know

thanks alot :)

hello again

when i upload the codes its work fine but my problem that is takes one command i mean when i write in URL 192.168.1.7/forward its accept the direction but when i want to change the direction or stop the car it doesn't response its give me webpage not available

how can i solve that?

any suggestion plz

Let's see your latest code.

Cheers, /dev

#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include <stdlib.h>

const int IN1=4;
const int IN2=2;
const int IN3=7;
const int IN4=8;
  char input;

// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2); // you can change this clock speed

#define WLAN_SSID       "aa"   // cannot be longer than 32 characters!
#define WLAN_PASS       "00"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define LISTEN_PORT           80      // What TCP port to listen on for connections.  
                                      // The HTTP protocol uses port 80 by default.
                                      
Adafruit_CC3000_Server httpServer(LISTEN_PORT);

String readString;

void setup()
{
   
pinMode( IN1 ,OUTPUT);// Right Motor 1st wire
pinMode( IN2 ,OUTPUT);// Right Motor 2nd wire
pinMode( IN3 ,OUTPUT);// left Motor 1st wire
pinMode( IN4 ,OUTPUT);// left Motor 2nd wire

Serial.begin(115200);

// analogWrite(E1, 0);
  Serial.println(F("Hello, CC3000!\n")); 

  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
  
   
  // Initialise the module
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
  
  Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
   
  Serial.println(F("Connected!"));
  
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }  

  // Display the IP address DNS, Gateway, etc.
  while (! displayConnectionDetails()) {
    delay(1000);
  }
  // Start listening for connections
  httpServer.begin();
  
  Serial.println(F("Listening for connections..."));

}

void loop() {
  
    // Try to get a client which is connected.
  Adafruit_CC3000_ClientRef client = httpServer.available();
  
   if (client) 
  {
    delay(5);
    Serial.println(F("Client connected."));
    // Process this request until it completes or times out.
    // Note that this is explicitly limited to handling one request at a time!

    // An HTTP request ends with a blank line
        boolean currentLineIsBlank = true;
        
        
        while (client.connected()) 
        {
          
            if (client.available())
            {
                char c = client.read();
                //Serial.write(c);
                // If you've gotten to the end of the line (received a newline
                // character) and the line is blank, the HTTP request has ended,
                // so you can send a reply.
                if (readString.length() < 100) {
                    readString += c;
                    Serial.print(c);
                }
                
                if (c == '\n' && currentLineIsBlank) {
                  
                  client.println(F("HTTP/1.1 200 OK"));
                    client.println(F("Content-Type: text/html"));
                    client.println();
                    client.println(F("<!DOCTYPE HTML>")); 
                    
                    //send the HTML stuff
                    client.println(F("<html><head><title>Randi Control Panel</title><style type=\"text/css\">"));
                    client.println(F("body { font-family: sans-serif }"));
                  /*
                    client.println("h1 { font-size: 14pt; }");
                    client.println("p  { font-size: 10pt; }");
                    client.println("a  { color: #2020FF; }");
                    client.println("</style>");
                    client.println("</head><body text=\"#A0A0A0\" bgcolor=\"#080808\">");
                 */ 
                    client.println(F("<h1>Controls</h1>
"));
                  
                    client.println(F("<form method=\"link\" action=\"/forward\"><input type=\"submit\" value=\"Go!\"></form>"));
                    client.println(F("<form method=\"link\" action=\"/backward\"><input type=\"submit\" value=\"Reverse!\"></form>"));
                    client.println(F("<form method=\"link\" action=\"/stop\"><input type=\"submit\" value=\"Stop\"></form>"));
                  
                  client.println(F("<form method=\"link\" action=\"/Fleft\"><input type=\"submit\" value=\"Front Left\"></form>"));
                    client.println(F("<form method=\"link\" action=\"/Fright\"><input type=\"submit\" value=\"Front Right\"></form>"));
                    client.println(F("<form method=\"link\" action=\"/Bleft\"><input type=\"submit\" value=\"Back Left\"></form>"));
                    client.println(F("<form method=\"link\" action=\"/Bright\"><input type=\"submit\" value=\"Back Right\"></form>"));
                    client.println(F("
"));
                    client.println(F("</body></html>")); 
                    client.println();
                    break; 
                }
                
                if (c == '\n') {
                  // You're starting a new line.
                  currentLineIsBlank = true;
                }
                else if (c != '\r') {
                  // You've gotten a character on the current line.
                  currentLineIsBlank = false;
                }
                 
            }
        }
        // Give the web browser time to receive the data.
          
         process(client);
        
          readString = "";
  }
 
        
  }  
        
 void process (Adafruit_CC3000_ClientRef client)
{       
   if(readString.length() > 0){
    if (readString.indexOf("/forward") > 0)
      {
  // put your main code here, to run repeatedly:
/*if (Serial.available()) {
    // read the most recent character
    */
 //  input = Serial.read();
    // switch based on the character
  //  switch(input){
    //  case 'F': 
        // forward
  analogWrite(IN1,0);
  analogWrite(IN2,255);
  analogWrite(IN3,255);
  analogWrite(IN4,0);
   //break;
  }
  else if (readString.indexOf("/backward") > 0)
      {
   //   case 'B':  // backwards
           // v=Serial.read();
   analogWrite(IN1,200);
  analogWrite(IN2,0);
  analogWrite(IN3,0);
  analogWrite(IN4,200);
  // break;
      }
   //   case 'S':  // stop
   
    else if (readString.indexOf("/stop") > 0)
      {
        analogWrite(IN1,0);
        analogWrite(IN2,0);
        analogWrite(IN3,0);
        analogWrite(IN4,0);
     //   break;
      }
     // case 'L':  // left
      else if (readString.indexOf("/Fleft") > 0)
      {   
  analogWrite(IN1,0);
  analogWrite(IN2,150);
  analogWrite(IN3,0);
  analogWrite(IN4,200);
      }
      //  break;
    //  case 'R':  // right
   else if (readString.indexOf("/Fright") > 0)
      { 
  analogWrite(IN1,150);
  analogWrite(IN2,LOW);
  analogWrite(IN3,200);
  analogWrite(IN4,LOW);
      }//  break;
   //   default:    // if character not recognized then stop
      else if (readString.indexOf("/Bright") > 0)
      {
        analogWrite(IN1, 0);
        analogWrite(IN3, 0);
    //    break;
    }
}}


// Tries to read the IP address and other connection details
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  
  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}

plz any help

i want to use break but its doesnt accept it with if

and tried to change it to switch but give error with indexof

:(

i want to use break but its doesnt accept it with if

Why not return?

i tried but the different between with and without return that the first one continue loading but its not change the direction and without return give me error page