In this activity, you will test to make sure that the electrical connections between your board and the servos are correct. The picture below shows your BOE Shield-Bot’s front, back, left, and right. We need to make sure that the right-side servo turns when it receives pulses from pin 12 and that the left-side servo turns when it receives pulses from pin 13.
The next example sketch will test the servo connected to the right wheel, shown below. The sketch will make this wheel turn clockwise for three seconds, then stop for one second, then turn counterclockwise for three seconds.
/* * Robotics with the BOE Shield - RightServoTest * Right servo turns clockwise three seconds, stops 1 second, then * counterclockwise three seconds. */ #include <Servo.h> // Include servo library Servo servoRight; // Declare right servo void setup() // Built in initialization block { servoRight.attach(12); // Attach right signal to pin 12 servoRight.writeMicroseconds(1300); // Right wheel clockwise delay(3000); // ...for 3 seconds servoRight.writeMicroseconds(1500); // Stay still delay(1000); // ...for 3 seconds servoRight.writeMicroseconds(1700); // Right wheel counterclockwise delay(3000); // ...for 3 seconds servoRight.writeMicroseconds(1500); // Right wheel counterclockwise } void loop() // Main loop auto-repeats { // Empty, nothing needs repeating }
Now, it’s time to run the same test on the left wheel as shown below. This involves modifying the RightServoTest sketch.
Here is a list of some common symptoms and how to fix them.
The first step is to double check your sketch and make sure all the code is correct.
The servo doesn’t turn at all.
The left servo turns when the right one is supposed to.
This means that the servos are swapped. The servo that’s connected to pin 12 should be connected to pin 13, and the servo that’s connected to pin 13 should be connected to pin 12.
The wheel does not fully stop; it still turns slowly.
If the wheel keeps turning slowly after the clockwise, stop, counterclockwise sequence, it means that the servo may not be exactly centered. There are two ways to fix this:
The wheel never stops, it just keeps turning rapidly.
If you are sure the code in your sketch is correct, it probably means your servo is not properly centered.
Links
[1] https://learn.parallax.com/202
[2] https://learn.parallax.com/203
[3] https://learn.parallax.com/199
[4] https://learn.parallax.com/185