Pages: [1]   Go Down
Author Topic: Adafruit Motor Shield  (Read 1020 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I recently purchased the Adafruit Motorshield. It can flawlessly run either motors or servos, but if I try to run the motors (any of the 4 channels) the servos go beserk. Here is my test code:
#include <AFMotor.h>
AF_DCMotor motor(4);

void setup() {
  myservo.attach(9);
  yourservo.attach(10);
  motor.setSpeed(200);
 
  motor.run(RELEASE);
}

void loop() {
  motor.run(FORWARD);
  delay(1000);
  motor.run(BACKWARD);
  delay(1000);}

I checked, no bridged pins or the like, all the pins are functioning normally. I am using a Arduino Mega 2560.
Thanks!
Logged

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11671
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmmm, looks like it ought to work having looked a bit at the library.  Probably crosstalk or missing ground connection?  Is the power supply powerful enough to run servos and motors?
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The power source is 6x AA batteries.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried hooking the servo directly up to pin 13 (which isn't used by the shield), gnd and 5V, and the motor to M4, running off of the seperate power brick, and the servo still had irregular motion. If I wanted to control the Adafruit shield without the AFMotor.h library, I could just use analogWrite for PWM and digitalWrite for direction, right?
Logged

0
Offline Offline
Shannon Member
****
Karma: 199
Posts: 11671
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You'd have to drive the pins that talk to the shift register with digitalWrite and the 4 PWM pins it uses with analogWrite, yes.  And remember to set them as OUTPUTs.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried setting the pins labeled M# to analog(200), and the direction pins to HIGH. got nothing. How exactly would I do this?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I got the AFMotor library to work. The problem was noise from the motors, and not the library. Thanks for your help!
Logged

Pages: [1]   Go Up
Jump to: