0

ARDUINO DUE + ADAFRUIT MOTORSHIELD V2
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by sonicalflair on Fri Jun 06, 2014 10:26 am

Greetings!

Is it possible to use both the Arduino Due I2C Interfaces with Adafruit Motorshield V2?

It's not clear to me how I would denote the Wire and Wire1 when it comes to addressing.

I'm trying to build a Split-Flap Display http://en.wikipedia.org/wiki/Split-flap_display and would like the ability to split the traffic on I2C bus.

I'm currently using the following and have noticed a decrease in speed every-time I add another module and run them all simultaneously.

-Arduino Mega R3 (PRODUCT ID: 191)
-Adafruit Motor Shield V2 (PRODUCT ID: 1438)
-Stepper Motor (PRODUCT ID: 324)
-AccelStepper Library

Increasing the I2C speed to 400KHz helped the speed by a factor of 4, but I didn't see linear gains when I changed it to 800KHz (outside ATMEL spec).

Here is a short video of the first 5 that we've calibrated. We have 16 built and it takes almost 12 seconds to perform a full rotation. I'm afraid going to our goal of 64 will be excruciatingly slow!

http://youtu.be/orQ9U3OJWTk

Thank you!

sonicalflair
 
Posts: 10
Joined: Thu May 01, 2014 10:51 pm

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by adafruit_support_bill on Fri Jun 06, 2014 10:58 am

Nice looking display!

You would have to do a bit of hacking, but it should be possible. The shield itself is wired to use the common R3 SDA/SCL pins. These are also connected to pins A4/A5 for pre-R3 Atmega 328 based Arduinos. You would need to cut traces from those 4 pins and run jumpers from the breakout holes to the second i2c bus.

The library too would need a minor hack also to address the other bus.

adafruit_support_bill
 
Posts: 71415
Joined: Sat Feb 07, 2009 10:11 am

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by sonicalflair on Fri Jun 06, 2014 11:51 am

Thanks Bill! It's been a tough but fun learning curve so far!

How minor is "minor"? I'm a EE by degree, the worst type of coder :D

Should I post help for that library modification in a separate forum, perhaps in the 'Arduino'?

sonicalflair
 
Posts: 10
Joined: Thu May 01, 2014 10:51 pm

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by adafruit_support_bill on Fri Jun 06, 2014 12:22 pm

Let me check with our Due expert. The Arduino Wire library documentation is a little sketchy on the use of the second bus.

adafruit_support_bill
 
Posts: 71415
Joined: Sat Feb 07, 2009 10:11 am

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by adafruit_support_rick on Fri Jun 06, 2014 7:09 pm

Well, there's a surprise! The Due Wire library is interrupt-driven in both directions. The AVR Wire library is interrupt-driven only on receive. So, yeah, that ought to help with throughput.

I suppose what I would do is to make a copy of the motorshield library, and change all the references to Wire to Wire1. That seems the easiest thing to me.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by sonicalflair on Fri Jun 06, 2014 10:20 pm

I'll give that a try tomorrow, hopefully I won't run into many I2C issues!

I got a total of 8 calibrated today, how about this for a thanks :D

http://youtu.be/8_-ryN2Th6U

sonicalflair
 
Posts: 10
Joined: Thu May 01, 2014 10:51 pm

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by adafruit_support_bill on Sat Jun 07, 2014 5:56 am

You are welcome!

adafruit_support_bill
 
Posts: 71415
Joined: Sat Feb 07, 2009 10:11 am

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by adafruit on Sat Jun 07, 2014 11:40 am

fantastic, this made our day, thank you!

adafruit
 
Posts: 12149
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by sonicalflair on Sat Jun 07, 2014 11:40 pm

It seems like the default is the SCL1/SDA1, so using 1k resistors as external pullups allowed me to use my existing code.

I then went into Adafruit_MotorShield.cpp and changed WIRE1 to WIRE and was able to use SCL/SDA to drive my steppers.

Can you give a little more detail on how to edit the Adafruit Motorshield library to be able to address some shields on WIRE and some on WIRE?

I tried to make a copy of the original library, and putting '1' after Adafruit_MotorShield, Adafruit_DCMotor, and Adafruit_StepperMotor in the Adafruit MotorShield.cpp and Adafruit MotorShield.h files. After compiling I received a bunch of "multiple definitions" errors.

Since I don't yet understand how libraries and the arduino IDE work, I only half expected that to work :D

Anyways, I probably could finish brute forcing my way to adding '1's to everything, but there has to be a better way.

Ideally at the end, I'm envisioning the following:

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_MotorShield1.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
// Adafruit_Motorshield1 definitions will be on the SCL1/SDA1

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); //default i2c address on SDA/SCL
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);

Adafruit_MotorShield1 AFMS1 = Adafruit_MotorShield1();  //default i2c address on SDA1/SCL1
Adafruit_StepperMotor1 *myMotor1 = AFMS1.getStepper(200, 1);

Thanks again!

sonicalflair
 
Posts: 10
Joined: Thu May 01, 2014 10:51 pm

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by adafruit_support_rick on Sun Jun 08, 2014 9:09 am

Hmmm.. I looked a little deeper at the code. I can see where you could get a lot of multiple definition errors. Give me a day or two to play around with it. Maybe I can come up with a good solution.

adafruit_support_rick
 
Posts: 35095
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by sonicalflair on Tue Jun 10, 2014 12:17 am

Thanks for the help so far guys!

Bad news is that I seem to be running into what I'll describe as I2C "freezing" issues.

When testing with 4 steppers, using 1kOhm resistors as pull ups seem to work quite well on SCL1/SDA1.

Using larger values, 10kOhm, 4.7kOhm, 2.2kOhm yielded a similar "freezing" type issue.

As I started scaling up, I would command all the steppers to move at once, and they would all move a few steps and stop.
I then tried to reset the Due by pressing the reset button, and at times observed the "Estimated pre-scale" messages come up very slowly, one at a time (I have 8 motorshield boards currently).
This seems only remedied by disconnecting the Due from the USB port.

I then tried using SCL0/SDA0 (without external pull-ups), but observed the same behavior. It would work on a small scale, but when I add more steppers, I observe periodic "freezes" and information on my serial port shows up "slowly".

I also tried the I2C fix described in this post to no avail: https://github.com/arduino/Arduino/pull/1994

I'll continue my analysis after getting an oscilloscope, but due to time constraints, i'll need to think of other options to overcome my memory and speed issues.

Here is 16 running on the Mega I took over the weekend; I don't look forwards to removing the 3.3v jumpers that I added to all the boards during my Due testing XD

http://youtu.be/nQdiGxEqky4

sonicalflair
 
Posts: 10
Joined: Thu May 01, 2014 10:51 pm

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by adafruit_support_bill on Tue Jun 10, 2014 6:56 am

How are you powering all these motors?

adafruit_support_bill
 
Posts: 71415
Joined: Sat Feb 07, 2009 10:11 am

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by sonicalflair on Tue Jun 10, 2014 9:23 am

Hi Bill!

I'm using a 12V, 30A Meanwell power supply NES-350-12 for each set of 16 stepper motors. To be safe, I plan to add 2A fuses in-line to each motorshield.

sonicalflair
 
Posts: 10
Joined: Thu May 01, 2014 10:51 pm

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by adafruit_support_bill on Tue Jun 10, 2014 9:56 am

Sounds like sufficient power.

I'm not sure that the external pullups are necessary. The shield board has pullups of its own. Although the pullup value is not critical, 4.7K is typical. 1K is a pretty strong pullup. I believe that the shield pullups are 10K, so you can stack a few before you have to think about removing some of them.

adafruit_support_bill
 
Posts: 71415
Joined: Sat Feb 07, 2009 10:11 am

Re: ARDUINO DUE + ADAFRUIT MOTORSHIELD V2

by sonicalflair on Tue Jun 10, 2014 10:09 am

Thanks Bill, I didn't realize the shield itself had pull ups! I'll try the same set up tonight, but with no pull ups on SCL1/SDA1. Can't wait to get that scope! The build team is moving forwards with building 64 of these babies. I hope I can catch up :D

sonicalflair
 
Posts: 10
Joined: Thu May 01, 2014 10:51 pm

Please be positive and constructive with your questions and comments.