wifi shield code help

im usung adafruit cc3000 wifi shield and all the examples work fine with the shield but for the life of me i can not figure out why it wont initialize atleast in this scketch

//include necessary libraries
#include <Adafruit_CC3000.h>
#include "MotorDriver.h"
#include <SPI.h>j
#include "utility/debug.h"
#include "utility/socket.h"
#include <string.h>
// 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_DIVIDER); // you can change this clock speed

#define WLAN_SSID       "Wentworth"   // cannot be longer than 32 characters!
#define WLAN_PASS       "dawsonliam"
// 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.

#define MAX_ACTION            10      // Maximum length of the HTTP action that can be parsed.

#define MAX_PATH              64      // Maximum length of the HTTP request path that can be parsed.
// There isn't much memory available so keep this short!

#define BUFFER_SIZE           MAX_ACTION + MAX_PATH + 20  // Size of buffer for incoming request data.
// Since only the first line is parsed this
// needs to be as large as the maximum action
// and path plus a little for whitespace and
// HTTP version.

#define TIMEOUT_MS            500    // Amount of time in milliseconds to wait for
// an incoming request to finish.  Don't set this
// too high or your server could be slow to respond.

Adafruit_CC3000_Server httpServer(LISTEN_PORT);
uint8_t buffer[BUFFER_SIZE + 1];
int bufindex = 0;
char action[MAX_ACTION + 1];
char path[MAX_PATH + 1];

String webClickRequest;

void setup(void) {

  // initialize the digital pin as an output.
  motordriver.init();
  motordriver.setSpeed(200, MOTORB);
  motordriver.setSpeed(200, MOTORA);
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n")); 
  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
  
  /* Initialise the module */
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Unable to initialise the CC3000! 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!"));
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

  // Start listening for connections
  httpServer.begin();

  Serial.println(F("Listening for connections..."));
}

void loop(void) {
  // Try to get a client which is connected.
  Adafruit_CC3000_ClientRef client = httpServer.available();
  if (client) {
      while (client.connected()) {
        if (client.available()) {
          char c = client.read();

          //read the incoming HTTP request
          if (webClickRequest.length() < 100) {

            //store the request to a string
            webClickRequest += c;

          }

          //check to see if the request has come to an end
          if (c == '\n') {

            //Begin drawing out the website using
            //using basic HTML formatting with some CSS
            client.println(F("HTTP/1.1 200 OK"));
            client.println(F("Content-Type: text/html"));
            client.println();
            client.println(F("<HTML>"));
            client.println(F("<HEAD>"));
            client.println(F("<TITLE>Internet Controlled RC Car</TITLE>"));
            client.println(F("<STYLE>"));
            client.println(F("body{margin:50px 0px; padding:0px; text-align:center;}"));
            client.println(F("h1{text-align: center; font-family:\"Trebuchet MS\",Arial, Helvetica, sans-serif; font-size:24px;}"));
            client.println(F("a{text-decoration:none; width:75px; height:50px; border-color:black; font-family:\"Trebuchet MS\",Arial, Helvetica, sans-serif; padding:6px; background-color:#aaaaaa; text-align:center; border-radius:10px 10px 10px; font-size:24px;}"));
            client.println(F("a:link {color:white;}"));
            client.println(F("a:visited {color:white;}"));
            client.println(F("a:hover {color:red;}"));
            client.println(F("a:active {color:white;}"));
            client.println(F("</STYLE>"));
            client.println(F("</HEAD>"));
            client.println(F("<BODY>"));
            client.println(F("<H1>Internet Controlled RC Car</H1>"));
            client.println(F("
"));
            client.println(F("
"));
            client.println(F("<a href=\"/?left\"\">LEFT</a>"));
            client.println(F(" "));
            client.println(F("<a href=\"/?forward\"\">FORWARD</a>"));
            client.println(F(" "));
            client.println(F("<a href=\"/?right\"\">RIGHT</a>"));
            client.println(F("
"));
            client.println(F("
"));
            client.println(F("
"));
            client.println(F("<a href=\"/?back\"\">BACK</a>"));
            client.println(F(" "));
            client.println(F("
"));
            client.println(F("
"));
            client.println(F("<a href=\"/?brake\"\">BRAKE</a>"));
            client.println(F("</BODY>"));
            client.println(F("</HTML>"));

            //Stop loading the website
            delay(1);
            client.stop();



            //check to see if any of the drive commands have been sent
            //from the webpage to the Arduino

            if (webClickRequest.indexOf("?left") > 0) {
              Serial.println(F("hello"));
              motordriver.goLeft();
              delay(1000);

            }

            else if (webClickRequest.indexOf("?forward") > 0) {
              motordriver.goForward();
              delay(1000);

            }

            else if (webClickRequest.indexOf("?right") > 0) {
              motordriver.goRight();
              delay(1000);

            }

            else if (webClickRequest.indexOf("?back") > 0) {
              motordriver.goBackward();
              delay(1000);

            }

            else if (webClickRequest.indexOf("?brake") > 0) {
              motordriver.stop();
              delay(1000);

            }

            //clear the string for the new incoming data
            webClickRequest = "";

          }
        }
      }
    }
  }
  // initialize the digital pin as an output.
  motordriver.init();
  motordriver.setSpeed(200, MOTORB);
  motordriver.setSpeed(200, MOTORA);

Which pins is this instance using?

#ifndef MOTORDRIVER_H
#define MOTORDRIVER_H
#include <Arduino.h>
/Pins definitions*******/
#define MOTORSHIELD_IN1 8
#define MOTORSHIELD_IN2 11
#define MOTORSHIELD_IN3 12
#define MOTORSHIELD_IN4 2
#define SPEEDPIN_A 9
#define SPEEDPIN_B 10
/Motor ID********/
#define MOTORA 0
#define MOTORB 1

If you are using an Uno, you can't use D10 to D13 for anything but the SPI bus.

originaly i was but i have just got my mega in the mail and trying to set it up with that.... would this help?

would this help?

Yes, because the SPI bus on the Mega uses pins 50 to 53.

so i should change those pins on one of the shields then?

oh that might be difficault with shields wouldnt it?? maybe i could leave out the motor shield and set it up myself im only running two small dc motors

so i should change those pins on one of the shields then?

You can't change the pins that the SPI bus is on.

You may be able to change the pins that the motor shield uses, if there are jumpers. The pin numbers in the code need to match the pins that the motors are actually connected to.

merkzilla:
originaly i was but i have just got my mega in the mail and trying to set it up with that.... would this help?

I don't know. The Adafruit CC3000 docs are not complete. I see no schematic. However, I did find this page.

It states you must jumper some pads on the bottom of the shield to use it with a mega. It implies that the CC3000 shield does use D10 to D13 for the shield, and maybe some other pins.

edit: I'll be honest. This is poor design. Almost all new Arduino designs (including the Uno) use the ICSP pins for the SPI bus data lines to avoid this problem. It is very unlike Limor Fried to miss this. :frowning:

I did jumper the pads already I think it must be a conflict with the motor shield because it works fine with the examples I'll have to look further at the motor shield maybe I'll try it without to see if it connects

D10 to D13 are still unusable after doing the jumper with the pads on the CC3000 shield. That should connect the ICSP SPI data lines to D11 to D13 on the shield.

maybe I'll try it without to see if it connects

Maybe?

I think I'll stay away from shields in the future.....I'm new to Arduino do you think there's anyway to use both shields?

Ok I will lol

I'm new to Arduino do you think there's anyway to use both shields?

Sure. Bend the pins on the motor shield that connect to pins 10 to 13. Solder wires on those pins, and connect them to other pins on the Arduino. Change the code to match where you really connected things.

There may be alternatives, depending on which motor shield you have.

merkzilla:
I think I'll stay away from shields in the future.....I'm new to Arduino do you think there's anyway to use both shields?

Maybe. You will need to put the motor shield on top of the CC3000 shield and do some pin bending and wire jumpering as PaulS suggested, then change the defines in the motor shield library.

so it was the motor shield without it im able to connect but it loads the web control page and when i use one of the buttons it cant connect to the page anymore and i have to restart it

//include necessary libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>j
#include "utility/debug.h"
#include "utility/socket.h"
#include <string.h>
// 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_DIVIDER); // you can change this clock speed

#define WLAN_SSID       "Wentworth"   // cannot be longer than 32 characters!
#define WLAN_PASS       "dawsonliam"
// 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.

#define MAX_ACTION            10      // Maximum length of the HTTP action that can be parsed.

#define MAX_PATH              64      // Maximum length of the HTTP request path that can be parsed.
// There isn't much memory available so keep this short!

#define BUFFER_SIZE           MAX_ACTION + MAX_PATH + 20  // Size of buffer for incoming request data.
// Since only the first line is parsed this
// needs to be as large as the maximum action
// and path plus a little for whitespace and
// HTTP version.

#define TIMEOUT_MS            500    // Amount of time in milliseconds to wait for
// an incoming request to finish.  Don't set this
// too high or your server could be slow to respond.

Adafruit_CC3000_Server httpServer(LISTEN_PORT);
uint8_t buffer[BUFFER_SIZE + 1];
int bufindex = 0;
char action[MAX_ACTION + 1];
char path[MAX_PATH + 1];

String webClickRequest;

void setup(void) {

  // initialize the digital pin as an output.
     pinMode(4, OUTPUT); 
     pinMode(5, OUTPUT); 
     pinMode(6, OUTPUT); 
     pinMode(7, OUTPUT); 
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n")); 
  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
  
  /* Initialise the module */
  Serial.println(F("\nInitialising the CC3000 ..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Unable to initialise the CC3000! 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!"));
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

  // Start listening for connections
  httpServer.begin();

  Serial.println(F("Listening for connections..."));
}

void loop(void) {
  // Try to get a client which is connected.
  Adafruit_CC3000_ClientRef client = httpServer.available();
  if (client) {
    Serial.println(F("Client connected."));
      while (client.connected()) {
        if (client.available()) {
          char c = client.read();

          //read the incoming HTTP request
          if (webClickRequest.length() < 100) {

            //store the request to a string
            webClickRequest += c;

          }

          //check to see if the request has come to an end
          if (c == '\n') {

             //Begin drawing out the website using
              //using basic HTML formatting with some CSS
              client.println("HTTP/1.1 200 OK"); 
              client.println("Content-Type: text/html");
              client.println();
              client.println("<HTML>");
              client.println("<HEAD>");
              client.println("<TITLE>Internet Controlled RC Car</TITLE>");
              client.println("<STYLE>");
              client.println("body{margin:50px 0px; padding:0px; text-align:center;}");
              client.println("h1{text-align: center; font-family:\"Trebuchet MS\",Arial, Helvetica, sans-serif; font-size:24px;}");
              client.println("a{text-decoration:none; width:75px; height:50px; border-color:black; font-family:\"Trebuchet MS\",Arial, Helvetica, sans-serif; padding:6px; background-color:#aaaaaa; text-align:center; border-radius:10px 10px 10px; font-size:24px;}");
              client.println("a:link {color:white;}");
              client.println("a:visited {color:white;}");
              client.println("a:hover {color:red;}");
              client.println("a:active {color:white;}");
              client.println("</STYLE>");
              client.println("</HEAD>");
              client.println("<BODY>");
              client.println("<H1>Internet Controlled RC Car</H1>");
              client.println("
");
              client.println("
");        
              client.println("<a href=\"/?left\"\">LEFT</a>");
              client.println(" ");
              client.println("<a href=\"/?forward\"\">FORWARD</a>");  
              client.println(" ");      
              client.println("<a href=\"/?right\"\">RIGHT</a>");
              client.println("
");
              client.println("
");
              client.println("
");            
              client.println("<a href=\"/?backleft\"\">BACK LEFT</a>");
              client.println(" ");
              client.println("<a href=\"/?back\"\">BACK</a>");
              client.println(" ");  
              client.println("<a href=\"/?backright\"\">BACK RIGHT</a>");
              client.println("</BODY>");
              client.println("</HTML>");
     
              //Stop loading the website     
              delay(1);
              client.stop();



            //check to see if any of the drive commands have been sent
            //from the webpage to the Arduino

           if(webClickRequest.indexOf("?left") > 0){
              Serial.println("hello");
                  left();
                  delay(1000);
                  brake();
            }

            else if(webClickRequest.indexOf("?forward") >0){
                forward();
                delay(1000);
                brake();
            }
            
            else if(webClickRequest.indexOf("?right") >0){
                right();
                delay(1000);
                brake();
            }
            
            else if(webClickRequest.indexOf("?backleft") >0){
                left();
                reverse();
                delay(1000);
                brake();
            }
            
            else if(webClickRequest.indexOf("?back") >0){
                reverse();
                delay(1000);
                brake();
            }
            
            else if(webClickRequest.indexOf("?backright") >0){
                right();
                reverse();
                delay(1000);
                brake();
            }
            
            
            //clear the string for the new incoming data
            webClickRequest="";
     
            }
          }
        }
      }
    }

 //drive functions
  //here on down
  
  void reverse(){ 
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH); 
  }

  void forward(){
    digitalWrite(4, HIGH);  
    digitalWrite(5, LOW);   
  }

  void right(){
    digitalWrite(6, HIGH);  
    digitalWrite(7, LOW);  
  }

  void left(){
    digitalWrite(6, LOW);   
    digitalWrite(7, HIGH);  
  }

  void brake(){
    digitalWrite(4, LOW);    
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);   
    digitalWrite(7, LOW); 
  }

I suspect that you are running out of memory. You use the F() macro in some places, but not enough. ALL string literals should be wrapped.

Global variables use 1,978 bytes (24%) of dynamic memory, leaving 6,214 bytes for local variables. Maximum is 8,192 bytes.