Stacked shields

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
pjdestexhe
 
Posts: 9
Joined: Mon Oct 28, 2019 8:46 am

Stacked shields

Post by pjdestexhe »

Hello!

I'm trying to use two Adafruit Motorshields V2 and I have weird results. I can make both shields work, but not perfectly together. I tried to make a code as clear as possible to explain my problems, check it in the bottom of this post. I built functions to show the results of different options

I have two problems but I'll keep my post in a single forum in case both problems are related:

1) The order of the shield.begin(); seems to matter as illustrated in the workingSetup and notWorkingSetup functions. That's weird! In my opinion it should not matter ! When I begin the stepper shield before the DC motor shield my steppers don't work but I can use my DC motors. When I begin the DC motor shield before the stepper shield I can use the two steppers and the two DC motors, though not perfectly as I'll explain further down.

I soldered a jumper on my DC motor shield, I think the physical connections are okay as I can use all my motors when they initialize my shields in the right order.

2) My project is to build a robot than can move around which two DC motors and lift and rotate a kind of crane with two Stepper motors. I can raise the crane until it presses a button used to mark its high position, and it then holds its position as required, but then if I move the robot using the DC motors the stepper drops the crane. I don't think it's a matter of battery, because the stepper holds the crane when I run the DC motors at high-speed. It looks like it drops the crane when I run the DC motors slowly or when I release them. It also looks like one of the DC motors has more effect than the other. It looks like interference to me. Do you have suggestions?

Code: Select all

#include <Adafruit_MotorShield.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_MotorShield ShieldSteppers(0x60);
Adafruit_MotorShield ShieldMoteurs(0x70);
Adafruit_StepperMotor *stepElev = ShieldSteppers.getStepper(200, 1), *stepRot = ShieldSteppers.getStepper(200, 2);
Adafruit_DCMotor *moteurGauche = ShieldMoteurs.getMotor(1), *moteurDroite = ShieldMoteurs.getMotor(2);
int portBPElev = 25;

void setup()
{ 
  Serial.begin(9600);
  int portBPElev = 25; // pin of the button that detects that the crane is up
  pinMode(portBPElev,INPUT);
  workingSetup();  // The order of the shields.begin() matters. Why ? That's weird !
  stepElev->setSpeed(85);
  stepRot->setSpeed(1);
  while (digitalRead(portBPElev) == true) // This lifts a crane until it presses a button
  {
    stepElev->step(1, FORWARD, SINGLE);
  }
}

void loop()
{
  drop1();
}


void workingSetup()
{
  ShieldMoteurs.begin();  // The order of the shields.begin() matters. Why ? That's weird !
  ShieldSteppers.begin();
}

void notWorkingSetup()
{
  ShieldSteppers.begin();
  ShieldMoteurs.begin();  // The order of the shields.begin() matters. Why ? That's weird !
}

void drop1()
{
  moteurGauche->setSpeed(100); // 0 or 100 no matter
  moteurGauche->run(RELEASE);
}

void drop2()
{
  moteurGauche->setSpeed(0);
  moteurGauche->run(FORWARD);
}

void slow_drop()
{
  moteurGauche->setSpeed(0);
  moteurGauche->run(FORWARD);
  moteurDroite->setSpeed(0);
  moteurDroite->run(FORWARD);
}

void hold1()
{
  moteurGauche->setSpeed(100);
  moteurGauche->run(FORWARD);
  moteurDroite->setSpeed(100);
  moteurDroite->run(FORWARD);
}

void hold2()
{
  moteurDroite->setSpeed(0);
  moteurDroite->run(RELEASE);
}

User avatar
adafruit_support_bill
 
Posts: 88041
Joined: Sat Feb 07, 2009 10:11 am

Re: Stacked shields

Post by adafruit_support_bill »

The problem is in your addressing of the second board:

Code: Select all

Adafruit_MotorShield ShieldMoteurs(0x70);
0x70 is the 'all-call' address of the PCA9685. All PCA9685 chips respond to this address - regardless of the jumper configuration. See the note in the guide:
https://learn.adafruit.com/adafruit-mot ... ds-2045911

User avatar
pjdestexhe
 
Posts: 9
Joined: Mon Oct 28, 2019 8:46 am

Re: Stacked shields

Post by pjdestexhe »

Indeed! Thank you so much ! Problem solved!

I soldered an other jumper, changed the address and it works perfectly!

Just one thought though : if you solder the leftmost jumper (which is what I had done), is there a way to address the shield other than (0x70)?

User avatar
adafruit_support_bill
 
Posts: 88041
Joined: Sat Feb 07, 2009 10:11 am

Re: Stacked shields

Post by adafruit_support_bill »

Yes. You can combine the A5 jumper with any of the other address jumpers to create 64 unique addresses. A few of these are reserved or can be configured for special purposes. See section 7.1 of the datasheet:
https://cdn-shop.adafruit.com/datasheets/PCA9685.pdf

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”