I am trying to create a rover using a seeed shield v2.0…
I have an ultransonic sensor connected to a sivel type shield that I created with a servo motor in the center, that allows me to turn and ‘look’ for correct paths…
I can get the seeed motors working with an ultrasonic sensor when not using the servo motor, but when I connected the servo motor, the seeed motors stop working.
I can see the seeed motors stopping when I attach the servo to my output pin.
myservo.attach(headPin);
Where the headpin = 2.
I am assuming that there is something going on in this initialization call that is causing a problem with the #include "MotorDriver.h" file provided from seeed.
How do you power the servo motor ? The Arduino 5V pin can not be used, it doesn't have enough power (current).
Yes, I am using the 5v pin, I was thinking that may be the problem, but wasn't sure because it works when I only run the servo and not the gear motors...
To a what?
Sorry, I meant to say swivel mount.
I really don't have a set of 'source code' yet... I am just trying to test right now. I have been moving the call to myservo.attach(headPin); trying to see if I can get it to work, so this is not the cleanest code.
Here source code:
#include "MotorDriver.h"
#include "Servo.h"
const int pingPin = 7;
const int headPin = 2;
int pos = 0;
Servo myservo;
void setup() {
// initialize serial communication:
Serial.begin(9600);
motordriver.init();
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
//Serial.print(cm);
//Serial.print("cm");
//Serial.println();
if (cm < 10)
{
Serial.print("Danger!! Danger!!");
Serial.println();
motordriver.stop();
//myservo.attach(headPin);
if (pos < 45)
{
pos = 45;
}
else if (pos < 90)
{
pos = -90;
}
else if (pos < 180)
{
pos = 0;
}
myservo.write(pos);
delay(2000);
}
else
{
//myservo.detach();
Serial.print("All is clear...");
Serial.println();
motordriver.goForward();
if (pos != 0)
{
pos = 0;
myservo.write(pos);
delay(150);
}
}
delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
I have the solution to the conflict between the MotorDriver.h and Servo.h files that causes wpm pins 9 and 10 to switch off. Thereby making the DC motors useless.
Seeedstudio replied and recommended the following;
Open the motordriver.h file in a text editor. change the speed pins from 9 & 10 to 5 & 6. Then save the file and restart the IDE.
Next, physically connect male jumper wires from pin 9 to 5 on the headers and pin 10 to 6.
Now my DC motors will work with one Servo motor.
Try at your own risk, but it worked for me. Good luck.