Arduino Mega, Adafruit Mega Shield, Adafruit Motot Shield

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

Moderators: adafruit_support_bill, adafruit

Arduino Mega, Adafruit Mega Shield, Adafruit Motot Shield

Postby kokopellix » Mon Feb 11, 2013 5: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
//    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: 4
Joined: Sat Oct 15, 2011 11:12 am

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

Postby adafruit_support_bill » Mon Feb 11, 2013 6: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
User avatar
adafruit_support_bill
 
Posts: 16024
Joined: Sat Feb 07, 2009 9:11 am


Return to Arduino Shields from Adafruit

Who is online

Users browsing this forum: No registered users and 5 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [103]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[61]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]