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);
}