0

Motor Shield / Music Maker pin comflict
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Motor Shield / Music Maker pin comflict

by MavenScout on Tue Dec 12, 2017 2:40 pm

I am trying to use the Adafruit Motor Shield v2 and the Adafruit Music Maker Shield stacked on an Arduino Mega. In my research I have come across numerous references to a pin 3 conflict between these two boards.

Is using an addition micro controller (such as the METRO 328) to drive the Music Maker the only way to avoid this conflict?

Thanks for you time and trouble.

MavenScout
 
Posts: 11
Joined: Mon Nov 02, 2015 6:39 pm

Re: Motor Shield / Music Maker pin comflict

by adafruit_support_bill on Tue Dec 12, 2017 3:05 pm

The V2 motor shield does not use pin 3. All communication with the board is via the i2c bus (SDA & SCL).

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

Re: Motor Shield / Music Maker pin comflict

by MavenScout on Tue Dec 12, 2017 3:14 pm

In the FAQ it says:

Digital pin 3: DC Motor #2 / Stepper #1 (activation/speed control)

... and when I stack the Motor Shield on the Music Maker the music no longer plays. What am I missing?

(I'm also using a stepper on M3 M4 and two servos)

MavenScout
 
Posts: 11
Joined: Mon Nov 02, 2015 6:39 pm

Re: Motor Shield / Music Maker pin comflict

by adafruit_support_bill on Tue Dec 12, 2017 3:46 pm

That is the V1 motor shield FAQ. The V2 shield does not use pin 3.

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

Re: Motor Shield / Music Maker pin comflict

by MavenScout on Tue Dec 12, 2017 3:53 pm

Ok. It's not pin 3.

I apologize for my ignorance. That's the only "problem" I have been able to find in these forums or general Google searches.

Why does the Music Maker shield quit working when the Motor Shield is plugged it?

Can you at least point me in the right direction?

MavenScout
 
Posts: 11
Joined: Mon Nov 02, 2015 6:39 pm

Re: Motor Shield / Music Maker pin comflict

by adafruit_support_bill on Tue Dec 12, 2017 4:03 pm

Please post photos showing all your soldering and connections. And also please post the code you are using.

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

Re: Motor Shield / Music Maker pin comflict

by MavenScout on Tue Dec 12, 2017 4:30 pm

Code: Select all | TOGGLE FULL SIZE
  /*  Switcheroo v2
  *   by Dan Griffin 12/17
  *   
  *   Drives a Adafruit #324 stepper motor to carry a HiTec HS-755HB servo
  *   driven arm back and forth that turns off switches in the same order
  *   that they were turned on.  As well as operating a HiTec HS-755HB servo
  *   to open the top of the box to gain access to said switches.
  */

  #include <Wire.h>                                        // Pin communications via I2C.
  #include <Adafruit_MotorShield.h>                        // Adafruit Stepper/DC Motor library.
  #include "utility/Adafruit_MS_PWMServoDriver.h"          // Adafruit Servo Driver library.
  #include <Servo.h>                                       // Arduino built-in Interrupt driven Servo library.
  #include <QueueArray.h>                                  // FIFO stack for tracking of switches to turn off.
  #include <PID_v1.h>                                      // Control DC motor acceleration for accuracy (proportional–integral–derivative).
  #include <Adafruit_VS1053.h>                             // Adafruit Music Maker Shield for playing MP3s from an SD card.
  #include <SPI.h>                                         // Required for VS1053 above.
  #include <SD.h>                                          // Required for SPI above.

  #define SHIELD_RESET    -1                               // VS1053 reset pin (unused!).
  #define SHIELD_CS       7                                // VS1053 chip select pin (output).
  #define SHIELD_DCS      6                                // VS1053 Data/command select pin (output).
  #define DREQ            3                                // VS1053 Data request, ideally an Interrupt pin.
  #define CARDCS          4                                // Card chip select pin.

      int intOpen         = 1;                             // Flag for openCloseLid().
      int intClose        = 0;                             // Flag for openCloseLid().
      int intSwitch[6]    = {39, 41, 43, 45, 47, 49};      // Switch pins.
      int intPositn[6]    = {50, 50, 50, 50, 50, 50};      // Step counts for switch position.
      int intCurSwch      = 1;                             // Current switch number.
      int intOldSwch      = 0;                             // Old switch number.
      int intSpeed        = 50;                            // Stepper motor speed (0-55).

  const int conServo2     =  9;                            // Pin 9 is for servo 2, to open the lid.
  const int conServo1     = 10;                            // Pin 10 is for servo 1, that actuates the switch arm.

  const int conPinLfP     = 24;                            // Left limit switch plus.
  const int conPinLfN     = 25;                            // Left limit switch minus.
  const int conPinRtP     = 26;                            // Right limit switch plus.
  const int conPinRtN     = 27;                            // Right limit switch minus.

  Adafruit_MotorShield AFMS = Adafruit_MotorShield();      // Create the Adafruit_MotorShield object.
  Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2); // Create Stepper motor object for M3/M4.

  Servo servo1;                                            // Create the Arduino servo object (Switch arm).
  Servo servo2;                                            // Create the Arduino servo object (Lid).

  QueueArray <int> queue;                                  // Create boolean FIFO switch array.

  Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

// =======================================================
void setup() {

  pinMode(conPinLfP, INPUT_PULLUP);                        // +
  pinMode(conPinRtP, INPUT_PULLUP);                        // +
  pinMode(conPinLfN, OUTPUT);
  pinMode(conPinRtN, OUTPUT);
  digitalWrite(conPinLfN, LOW);                            // -
  digitalWrite(conPinRtN, LOW);                            // -

  servo1.attach(conServo1, 1000, 2000);                    // Attach arm servo (HS-755HB) to the library and set MIN MAX range.
  servo2.attach(conServo2, 1000, 2000);                    // Attach lid servo (HS-755HB) to the library and set MIN MAX range.
  servo1.writeMicroseconds(1000);                          // Initialize servo1 to 90 degrees (starting position).
  servo2.writeMicroseconds(1000);                          // Initialize servo2 to closed (starting position).

  AFMS.begin();                                            // Connect to the Adafruit_MotorShield Controller with default frequency 1.6KHz.
  myMotor->setSpeed(intSpeed);                             // Set the motor RPM (78 max).

  Serial.begin(9600);                                      // Just for debugging.
  Serial.println("Start");

  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);                                             // Don't do anything more.
  }
  // Serial.end();                                            // No need for serial com.
  musicPlayer.setVolume(10,10);                            // Lower is louder.
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);     // If DREQ is on an interrupt pin (int5) we can do background audio playing.

  for(int i = 0; i < 6; i++){
    pinMode(intSwitch[i], INPUT_PULLUP);                   // Latch each of the switch pins to internal resistor (HIGH = OFF / LOW = ON).
  }
  for(int i = 0; i < 6; i++){                              // Load FIFO array with initial switch status.
    // if(digitalRead(intSwitch[i]) == LOW){                  // (just in case switch(s) are ON at power up).
      queue.enqueue(i +1);                                 // Load queue with switch number(a).
    // }
  }
  // resetMotorLeft();                                        // Make sure Switcheroo starts out with the motor to the far left.

} // --- End Setup.

// ======================================================= MAIN LOOP
void loop() {

  if(!queue.isEmpty()) {
    openCloseLid(intOpen);
    while(!queue.isEmpty()) {                              // We have switches on!!
      intCurSwch = queue.dequeue();                        // Get and remove switch #? from queue.
      if(intCurSwch > intOldSwch) {                        // Check motor position - do we need to go BACKWARD, FOREWARD or stay here.
        myMotor->step(intPositn[intCurSwch],BACKWARD,DOUBLE); // Run the motor FORWARD to the switch.
        hitTheSwitch();                                    // We're there!
      } else if(intCurSwch < intOldSwch) {
        myMotor->step(intPositn[intCurSwch],FORWARD,DOUBLE); // Run the motor BACKWARD to the next switch.
        hitTheSwitch();                                    // We're there!
      } else {
        // Do nothing.
      }
    }
    openCloseLid(intClose);                                // We're done, close the lid.
    musicPlayer.playFullFile("Easy.wav");                  // Play us out!
    resetMotorLeft();
   
  }

} // --- End Loop.

// ======================================================= FUNCTION: hitTheSwitch()
// Activates the arm to turn switch off.

void hitTheSwitch() {

  servo1.writeMicroseconds(1870);                        // Turn switch off with arm.
  delay(200);                                            // Give arm time to actually turn switch off.
  servo1.writeMicroseconds(1700);                        // Arm back to ready position.
  intOldSwch = intCurSwch;

}

// ======================================================= FUNCTION: openCloseLid()
// Opens and closes the lid as appropriate.

void openCloseLid(int intMove) {

  if (intMove) {
    servo2.writeMicroseconds(1500);                        // Open lid.
    delay(500);                                            // Give the lid time to get out of the way.
    servo1.writeMicroseconds(1700);                        // Move arm to "ready" possition.
  } else {
    servo1.writeMicroseconds(1000);                        // Move arm down out of the way.
    delay(500);                                            // Give the arm time to get out of the way.
    servo2.writeMicroseconds(2000);                        // Close lid.
    delay(250);
  }
}

// ======================================================= FUNCTION: resetMotorLeft()
// Runs the motor toward the LEFT limit switch.  Sets motor to start position.

void resetMotorLeft() {

  while(digitalRead(conPinLfP)) {                          // Reads LOW if it's off.
    // Stepping via the library cannot be interupted so we have to step 1 at a time.
    myMotor->step(1,FORWARD,DOUBLE);                       // Step motor left to limit switch.
  }
}
Attachments
IMG_20171212_130849.jpg
Project view
IMG_20171212_130849.jpg (130.46 KiB) Viewed 294 times
IMG_20171212_130909.jpg
IMG_20171212_130909.jpg (115.69 KiB) Viewed 294 times
IMG_20171212_130736.jpg
IMG_20171212_130736.jpg (100.3 KiB) Viewed 294 times

MavenScout
 
Posts: 11
Joined: Mon Nov 02, 2015 6:39 pm

Re: Motor Shield / Music Maker pin comflict

by MavenScout on Tue Dec 12, 2017 4:30 pm

... additional views.
Attachments
IMG_20171212_130956.jpg
IMG_20171212_130956.jpg (115.06 KiB) Viewed 294 times
IMG_20171212_130839.jpg
IMG_20171212_130839.jpg (115.01 KiB) Viewed 294 times

MavenScout
 
Posts: 11
Joined: Mon Nov 02, 2015 6:39 pm

Re: Motor Shield / Music Maker pin comflict

by adafruit_support_bill on Tue Dec 12, 2017 5:16 pm

It looks like you have assembled your motor shield with the header pins in the signal breakout holes. That probably would work OK if all the solder joints on both boards were good. But it looks like a few suspect ones. Some look like possible cold-joints and some appear not to have flowed well. There is a lot of burnt flux residue too. But I don't see anything that appears to bea solder-bridge. This guide has some tips on identifying and fixing common soldering problems. http://learn.adafruit.com/adafruit-guid ... n-problems

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

Please be positive and constructive with your questions and comments.