Calibrating

### Start

There are two things to calibrate on the robot. One is the mechanical position of the pen in its holder. The other is the position in degrees of the servo.

### Modules

Gather the following parts to complete this project.

All Parts
All Parts
Potentiometer
Cable
PartQuantity
Potentiometer 1
Cable 1

### Calibrate the Servo

We are going to find the minimum and maximum that the servo should move. Plug a cable into A0 and the other side into the potentiometer. Set the potentiometer to its middle position. This is done by rotating it so the groove in the dial points to the socket.

All the parts
All the parts
Take cable
Into potentiometer
Into A0

Upload the following code. You will need all 6 batteries in and powering the I2C boards

Potentiometer must in middle position

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38


//Libraries needed
#include "ServoDriver.h"
#include <Wire.h>

//84 to 116

//Creating the servo driver object
ServoDriver servoDriver;

//Variables for data
int dialSocket = A0;
int val;

void setup()
{
//Open I2C communication
Wire.begin();
//Begin Serial communication
Serial.begin(9600);
//Begin communication with driver
servoDriver.init(0x7f);
}

void loop()
{
//Map value to a degree
val = map(val, 0, 1023, 0, 180);
//Send that mapped value to Serial Monitor
Serial.println(val);
//Set servo position in position 1 to the value
servoDriver.setAngle(1, val);
//Small delay for stability
delay(15);
}


#### Observe

Open up the Serial Motor. Your initial value should be pretty close to 90 degrees.

#### Find the Minimum

Slowly rotate the dial so the servo horn moves down. You are looking for the spot where the servo horn is just barely in the pen holder cutouts. I get a value of about 85. Write your number down.

Starting at middle
Starting at middle
Turn
Middle
Down
Middle
Down

#### Find the Maximum

Slowly rotate the dial the other way so the servo horn moves up. You are looking for the spot where the pen assembly is slightly up and tilted. I get a value of about 120. Write your number down. These are your servo calibration numbers.

From low
From low
Turn
Down
Up
Down
Up

### Calibrate the Pen

Set your servo to the minimum position. Roll the pen down in the pen mount (adjusting the rubber band if necessary) so that it just touches the surface of whatever your robot is on. I suggest you place a piece of paper under your robot. Especially if you are using a marker.

Un-calibrated
Un-calibrated
Touching the paper at minimum
When servo is up

Change the minimum and maximum values then upload the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

//Libraries needed
#include "ServoDriver.h"
#include <Wire.h>

//Creating the servo driver object
ServoDriver servoDriver;

//PUT YOUR VALUES HERE
int minVal = 85;
int maxVal = 120;

void setup()
{
//Open I2C communication
Wire.begin();
//Begin communication with driver
servoDriver.init(0x7f);
}

void loop()
{

//Set servo position to Max
servoDriver.setAngle(1, maxVal);
//Wait
delay(2000);
//Set servo position to Min
servoDriver.setAngle(1, minVal);
//Wait
delay(2000);
}


#### Observe

If you've calibrated everything correctly then the pen should be lifting up, waiting two seconds, then going down and making contact with the paper, and waiting two more seconds before looping.

#### Next Section

With everything calibrated you can remove the potentiometer and cable to move on to drawing some shapes in the next section.