Question about I2C Motor Shiled with Wifi CC3000

Hello, recently I also work on Robot Project based on the WIFI shield. The products I used were:

  1. Adafruit CC3000 WIFI chip — https://www.adafruit.com/products/1510
  2. Adafruit Motor Shield V2 (I2C) —Overview | Adafruit Motor Shield V2 | Adafruit Learning System
  3. Aduino UNO board

The WIFI chip and the motor shield can work perfect when I used them separately but when they work together some problems occur. I found out that wherever I put the code “AFMS.begin()” in my Arduino program it will influence the WIFI shield because when I run “app.js”, an information like “Error adding the device” will appear. But when I remove the line “AFMS.begin()” and then run “app.js”, information will show that my wifi shield can be found and added successfully. I really do not know why this happens and how to solve this.

The following is my code.

#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <aREST.h>

#include <Wire.h>
#include <MotorShield.h>

// Create the motor shield object with the default I2C address
MotorShield AFMS = MotorShield();

// Select which ‘port’ M1, M2, M3 or M4.
Adafruit_DCMotor *Motor1 = AFMS.getMotor(1);
Adafruit_DCMotor *Motor2 = AFMS.getMotor(2);

#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 8
#define ADAFRUIT_CC3000_CS 10

#define WLAN_SSID “yourwifiname”
#define WLAN_PASS “yourwifipassword”
#define WLAN_SECURITY WLAN_SEC_WPA2

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);
// Create aREST instance
aREST rest = aREST();

#define LISTEN_PORT 80

// Server instance
Adafruit_CC3000_Server restServer(LISTEN_PORT);

void setup()
{
pinMode(10, OUTPUT);
Serial.begin(115200);
Serial.println(F(“Hello, CC3000!\n”));

//Expose functions
rest.function(“forward”,forward);
rest.function(“backward”,backward);
rest.function(“left”,left);
rest.function(“right”,right);
rest.function(“stop”,stop);

rest.set_id(“1”);
rest.set_name(“robot”);

// Set up CC3000 and get connected to the wireless network.
if (!cc3000.begin())
{
while(1);
}

if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
while(1);
}
while (!cc3000.checkDHCP())
{
delay(100);
}
displayConnectionDetails();
restServer.begin();
Serial.println(F(“Listening for connections…”));
//AFMS.begin();
}

void loop()
{
Adafruit_CC3000_ClientRef client = restServer.available();
rest.handle(client);
}

// Forward
int forward(String command) {

Motor1->setSpeed(100);
Motor1->run(FORWARD);
Motor2->setSpeed(100);
Motor2->run(FORWARD);
return 1;
}

//Backforward
int backward(String command) {

Motor1->setSpeed(100);
Motor1->run(BACKWARD);
Motor2->setSpeed(100);
Motor2->run(BACKWARD);
return 1;
}

// Left
int left(String command) {

Motor1->setSpeed(75);
Motor1->run(BACKWARD);
Motor2->setSpeed(75);
Motor2->run(FORWARD);
return 1;
}

// Right
int right(String command) {

Motor1->setSpeed(75);
Motor1->run(FORWARD);
Motor2->setSpeed(75);
Motor2->run(BACKWARD);
return 1;
}

// Stop
int stop(String command) {

Motor1->run(RELEASE);
Motor2->run(RELEASE);
return 1;
}

// Print connection details of the CC3000 chip
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;
}
}

I used the libraries provided by Adafruit:

  1. Motor Shiled: Install Software | Adafruit Motor Shield V2 | Adafruit Learning System
  2. WIFI CC3000: Using the CC3000 | Adafruit CC3000 WiFi | Adafruit Learning System
  3. aREST: GitHub - marcoschwartz/aREST: A RESTful environment for Arduino

As I just test 2 DC motors so I delete some contents in the Adafruit_MotorShield Library and rename it as MotorShield and this does not influence the performance of the motors. I can make sure of that as I’ve tested that. Another reason of modifying the motor shield library is that when I use the original Adafruit_MotorShield Library , the Arduino IDE will remind me that my sketch has occupied too much memory and this may influence the stability of my program, so I just delete the contents I do not need so far.

I will be really grateful if anyone can help. I’ve searched the solution for my problem for several days and cannot find a way to solve it. Thank you so much!