Memorial day is 05/25/2015 – Orders will ship out on May 26th. There will not be any deliveries or shipping on Monday. Any order placed after 11am ET on Friday May 22nd will not start to ship out until Tuesday May 26th.

Arduino Mega, Adafruit Mega Shield, Adafruit Motot Shield
Moderators: adafruit_support_bill, adafruit

Arduino Mega, Adafruit Mega Shield, Adafruit Motot Shield

by kokopellix on Mon Feb 11, 2013 6:43 pm

The Arduino Mega associates digital pin 3 with Interrupt 1.

The AdaFruit motor shield associates Digital pin 3 with DC Motor #2 / Stepper #1 (activation/speed control).

I have built a robot using the Arduino Mega, AdaFruit Mega Shield, and AdaFruit Mega Shield and two DC motors. I used the Mega because I wanted to associate all bumper/cliff on/off switches with corresponding interrupts and needed as many interrupts as I could get.

When running, if pin 3 drops to zero, the right motor stops and the left motor starts and stops (steps?).

How can I manage some sort of compatibility or is this project doomed? Is there a Mega motor shield?

Stripped down code, involving only the motor running straight ahead and pin 3 (which I cannot seem to read) follows:

Code: Select all | TOGGLE FULL SIZE
//    Sketch:  motorCheck
//  Robot running motor check.


#include <AFMotor.h>
AF_DCMotor  rightMotor(1, MOTOR12_64KHZ);    // Right wheel motor
AF_DCMotor  leftMotor(2, MOTOR12_64KHZ);     // Left wheel motor

const  int  defaultDelay = 20;

int      leftCliffIntPin = 3;

void setup()
{
  Serial.begin(9600);   // start the serial port
  Serial.print("FORWARD = ");    Serial.println(FORWARD);
  Serial.print("BACKWARD = ");   Serial.println(BACKWARD);

//  Install pull-up resistors on pin
  pinMode(leftCliffIntPin, INPUT);     
  digitalWrite(leftCliffIntPin, HIGH);
 
  //  Start the motors
  rightMotor.setSpeed(200);
  leftMotor.setSpeed(200);
  rightMotor.run(FORWARD);
  leftMotor.run(BACKWARD);
}

void loop()
{
    runStraight(defaultDelay);
   
    int  pinVal = digitalRead(leftCliffIntPin);
    if (pinVal == HIGH) Serial.println("High, high, high");
    else Serial.println("Low, low, low");
   
    Serial.println("Running forward.");   
}


void  runStraight(int  straightDelay)
{
  rightMotor.run(FORWARD);
  leftMotor.run(BACKWARD);
  Serial.println("Forward, forward, forward.");
  delay(straightDelay);
}
kokopellix
 
Posts: 6
Joined: Sat Oct 15, 2011 12:12 pm

Re: Arduino Mega, Adafruit Mega Shield, Adafruit Motot Shield

by adafruit_support_bill on Mon Feb 11, 2013 7:43 pm

Re-allocating pins for the shield is complicated. It would require both hardware and library changes. A better approach is to use pin-change interrupts. These can work with many more pins than external interrupts: http://playground.arduino.cc/Main/PinChangeInt

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