VNH5019/SPI communication conflict

Hi,

I have an Arduino Uno with a DualVNH5019 motor shield that I’m trying to get to work with an Adafruit CC3000 Wi-Fi Shield with the default pin configurations. When I try to control the Motor 2 speed without initializing the CC3000 in my Arduino program, I can control motor speed as expected. Once I initialize the CC3000, the motor will only go at full speed forward, no speed, or full speed reverse.

My initial guess is that there’s a conflict with the pins used for SPI communication (11, 12, 13). I’ve broken the trace for pin 12/M2EN/DIAG as shown in pololu.com/docs/0J49/6.a but I’m not sure what else is required.

I’m attaching a code sample which, when run, either ramps up the speed (as I would expect) or goes to full speed immediately when the line cc3000.begin() is commented out.

Am I missing something about how the combination of these shields should work together? Thanks!

-Albert

[code]#include <DualVNH5019MotorShield.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <avr/wdt.h>

//-----------------CC3000 and network info plus interrupt and control pins--------//
#define ADAFRUIT_CC3000_IRQ 3// 3 // MUST be an interrupt pin!
#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);

DualVNH5019MotorShield motors;

void setup() {
Serial.begin(115200);
// cc3000.begin();
motors.init();
Serial.println(“Setup”);

}

void loop() {
motors.setM1Speed(0);

Serial.println(“Starting”);
for (int i = 0; i < 400; i++) {
motors.setM2Speed(i);
delay(5);
}
}
[/code]

Hello, Albert.

Thank you for posting your code. It looks like the Adafruit CC3000 shield uses pin 10 for chip select (CS) by default. This conflicts with the VNH5019 shield since pin 10 is used as the M2PWM pin. You could remap this on the VNH5019, but since our library assumes timer1 is used for PWM, it would require a lot of work. Alternatively, it would probably be easier to remap the CS pin on the CC3000 shield. This can be done by cutting the trace between the WCS pin and pin 10, then running a wire from WCS to an available pin you want to use. Finally, you will need to make sure you take this into account in your code, so #define ADAFRUIT_CC3000_CS 10 would need to change to #define ADAFRUIT_CC3000_CS n, where n is the pin number you made the connection to.

By the way, it sounds like you cut the trace for pin 12; however, it wasn’t clear if you ran a wire from a different Arduino pin as described in the “Remapping the Arduino Connections” section of the VNH5019 shield user’s guide that you linked to. If you want motor 2 to function normally, you will need to make this connection to another pin. You will also need to be sure you declare this change in the library, which can be done using the DualVNH5019MotorShield constructor:

DualVNH5019MotorShield(unsigned char INA1, unsigned char INB1, unsigned char EN1DIAG1, unsigned char CS1, unsigned char INA2, unsigned char INB2, unsigned char EN2DIAG2, unsigned char CS2)
For example, since you only need to change pin 12 (EN2DIAG2), your constructor might look like this if you remapped the connection to the A5 pin on your Arduino:

DualVNH5019MotorShield md(2, 4, 6, A0, 7, 8, A5, A1);
-Brandon

Thanks for the quick response, Brandon! I hope to try out those changes in the next week and will let you know if I have any more questions.

-Albert

The motors are working as expected, but the CC3000 won’t finish initializing at startup.

I’ve changed the connection from Pin 12 on the VNH5019 to A5 and updated the constructor inside the library.

I’ve also changed the connection from Pin 10 on the CC3000 to A2 and updated the code so that it looks like this. I haven’t been able to find anything that makes me think that changing these pins shouldn’t work.

#define ADAFRUIT_CC3000_CS    A2   // 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);

When the CC3000 is starting up, it looks like it never gets past the point in Adafruit_CC3000::begin() where

  wlan_start(patchReq);

is called. Is there something wrong with my new pin setup?

-Albert

I do not see anything obvious from what you changed that would cause problems. Does removing the VNH5019 shield and trying the CC3000 shield alone fix the problem?

-Brandon

I’ve managed to get things working. However, to get it to work, I have to initialize the motors before and after the CC3000 like this. I haven’t been able to figure out why.

-Albert

void setup() {
  Serial.begin(115200);
  Serial.println("Initialize motors #1");
  motors.init();
  Serial.println("Initialize network");
  cc3000.begin();
  Serial.println("Initialize motors #2");
  motors.init();
}

We tried the same configuration here, and it worked fine for us as long as we initialized the VNH5019 shield after the CC3000 shield. What happens if you remove the first motors.init() and just initialize the VNH5019 shield after the CC3000 shield? If it doesn’t work and you want to post your full code, I would be happy to take a look.

-Brandon

I don’t remember it working without the first motors.init() call, but that was a somewhat agonizing night so my recall might not be accurate. :slight_smile:

I will try to find some time to see if things work as expected without that first call.