Arduino Due with Adafruit Motor Shield v2.0

Has anyone been able to get the example program DCMotor test to work with the Adafruit Motor Shield v2.0 connected to an Arduino Due? The board and program work great on an Arduino Uno but on the Arduino Due the Motor just powers up and never stops. The I2C scanner program reports device found at address 0x060 and at 0x070.

Which I2C scanner on which Arduino? The scanner in the playground scans the Wire bus only.

The motor shield uses the Wire bus on all but the Due. The Due uses Wire1.

I'm using the I2C Scanner version posted by Surfer Tim in a previous message that works on the Due board.

http://forum.arduino.cc/index.php?topic=332498.0

That is my Due I2C scanner code. Then you should be good to go if it detects the motor shield.

I have two Adafruit I2C devices connected to my Due. The 16 channel servo breakout board is the one using Wire1, and it works great. The Adafruit page for the motor shield (and the library) state it is Due compatible.

Thanks for the reply and the code SurferTim. I thought the same, since the Scanner detects the board it sort of proves the I2C comms are good. Unfortunately when I run the DCMotor Test the driver chips don't respond properly. On the Serial Port Monitor the tick tock tech is displayed but the DC Motor is just running away without stopping or changing direction or speed. Display of tick tock tech indicates that commands are being sent to the PCA9685 chip on the Motor board.

You mention in the other message thread you are using the PWM breakout board which uses the same PCA9685 chip. Are you connecting VCC of the breakout board to 3.3V to use Due logic levels?

The same Motor board works fine on an Arduino Uno. The only change is moving a solder jumper to change logic of the board between 3.3V and 5.0V

Are you connecting VCC of the breakout board to 3.3V to use Due logic levels?

No. The breakout board has a logic level converter. I connect it to the 5v pin.

That is interesting because on the MotorShield the Logic Selection jumper actually changes the PCA9685 pin 28 VDD to be powered by 3.3V instead of 5V. I wonder if powering the chip with 5V and using Bidirectional level shifters on the I2C bus would make a difference. Although I keep going in circles with that logic because this shield is supposed to be compatible with the Arduino Due board.

Adafruit Motorshield V2 Schematic

PCA9685 Data Sheet

I just checked my 16 channel servo board using 3.3 volts on Vcc, and it works fine. Maybe I should be using that instead of 5 volts.

I think I misspoke. The schematic for the servo board shows it does not have a logic level converter.

edit: If I have a problem, I think I am going to power the board with 5 volts and use 20K resistors from both the SDA and SCL lines to ground. That should reduce the 5 volts through the 10K pullups down to 3.3 volts.

I believe your break out board has VCC which is operational/logic voltage and it has a separate power supply input for the Motors. So when used on a Due it should be 3.3 on the VCC pin. Can only find a board layout picture but no schematic. If you know where I can find one please post a link.

Adafruit 16 Channel PWM board

edit: I changed my mind. I just ordered a logic level converter from Adafruit. I want the 5 volt level on the servo signal pins.

Thanks for the link. I see that the level shifters you have chosen are for I2C connection. That looks like a good way to go for Servo control with an Arduino Due. Let us know if the level shifters work out when you get a chance to hook them up.

Mikeee:
Thanks for the link. I see that the level shifters you have chosen are for I2C connection. That looks like a good way to go for Servo control with an Arduino Due. Let us know if the level shifters work out when you get a chance to hook them up.

I will. I'll connect my o-scope and insure all is ok with it before reporting on it.

edit: If you plan on using the level shifter with the motor shield, you must do a little pin bending.

I just received my Adafruit I2C shifter and it is working great! I have 5 volt power to the servo board and the o-scope shows 3.3 volt data on the Due side, and 5 volt data on the servo board side. I now have a 5 volt signal level on the servos. That is what I wanted! :slight_smile:

That sounds like a great idea. I'm going to order a level shifter and try it on the Motor Shield. Will be able to move the shield back and forth between the Uno and the Due board without changing the Logic setting on the Shield. Just have to figure an efficient way of redirecting the I2C pins on the due with out constantly bending pins on the Motor Shield.

Hello Mike,
Have you tested the level shifter with the arduino Due and the motor shield? Because I think I have the same problem as yours (Arduino Due + Motor Shield Adafruit v2 - Motors, Mechanics, Power and CNC - Arduino Forum), and I would like to know if it's a good solution.

Thank you

Sorry for not getting back to you sooner. The level shifters didn't fix the problem so have been spending time reading the PCA9685 Datasheet and looking at the Adafruit Motorshield Library. I found some code on another forum that is a basic driver for the PCA9685. With these 3 sources I am writing a simple program that doesn't use the Adafruit Library to step through the PCA9685 initialization and then attempt to manipulate the outputs that control the TB6612FNG motor driver chips. Constantly checking for an I2C error that might cause the run away condition of the motor driver chips. So far no problems when sending a Reset, Sleep Mode, then setting Prescale. Hope to tackle the control of the TB6612FNG this week.

Source code for PCA9685 Driver

PCA9685 Datasheet

While testing the I2C comm between the Due and the Adafruit Motorshield the I2C stopped function after a failure during data transmit. endTransmission() returned with error 3. Repeated attempts to access after this initial failure resulted in endTransmission() return with error 2.

-2:received NACK on transmit of address
-3:received NACK on transmit of data

The Wire Library detailed reference states the following:

-3: Data was sent and a NACK received. This means the slave has no more to send. The master can send a STOP condition, or a repeated START.

Wire Library Detailed Reference

This statement has me questioning what to do. The Master was the one sending data not the slave when this error happened.

Does the wire library recognize this error and send a STOP condition, or a repeated START? Or is it necessary to capture this error ourselves and generate either of these to clear the problem. Usually a RESET of the Due board clears the problem but there has been a few times where it doesn't and Power has to be removed from both to RESET the PCA9685 on the shield.

Code sample with error trap.

 // Motor Release IN1 = LOW

  on = 0;
  off = 4096;

  Wire1.beginTransmission(PCA9685_ADDRESS);
  Wire1.write(LED0_ON_L + 4 * IN1pin); // Address for Motor IN1 
  Wire1.write(on);
  Wire1.write(on>>8);
  Wire1.write(off);
  Wire1.write(off>>8);
  errorI2c = Wire1.endTransmission();

  if (errorI2c == 0)
    {
      Serial.println("Motor Release IN1 = LOW");
      Serial.println(" ");
    }
  else
    {
      Serial.print("Fault PCA9685 Motor Release - Error = ");
      Serial.println(errorI2c);
    }

  delay(5000);

Asked the previous question too soon. Did some more reading and now understand that endTransmission() adds the stop bit and triggers the transmit of the data with function twi_writeTo. This function returns the error codes. If this is wrong someone please correct me.

So it's up to the programmer to handle the fail condition.

Hmm no further ahead in solving the root of the problem but definitely learning how the I2C interface works. If there is noise getting into the SCL which causes a false clock pulse to the Slave Device the communication fails. If the error isn't handled the motor will run forever because access to the control pins is non functional.