Arduino Mega, Adafruit Mega Shield, Adafruit Motot Shield

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
kokopellix
 
Posts: 9
Joined: Sat Oct 15, 2011 12:12 pm

Arduino Mega, Adafruit Mega Shield, Adafruit Motot Shield

Post by kokopellix »

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

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

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

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

Post by adafruit_support_bill »

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

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

Return to “Arduino Shields from Adafruit”