Tweaking the servo configuration

Our example was using the minimum and maximum angles of the servo; we mentioned that the defaults are 0 to 180 degrees, but, can we change them? Obviously we can.

We can modify them with the setAngleRange method. In my experience, if we use the default pulse duration configuration most mini servos go just from 0 to 90 degrees. To reflect that we can use the following code:

servo.setAngleRange(0.0, 90.0)

There are many cases when we want to configure the angle range: smaller range -such as 0 to 90-, larger range -such as 0 to 360-, custom range -such as -90 to 90- for code clarity reasons, and so on.

The other configuration we can tweak is the range for the duration of the pulse. For that we have the setPulseDurationRange method. This range will create a map from the angles to the pulse duration. For the minimum angle the driver will send the shortest pulse, for the maximum angle it will send the longest pulse, and for the angles in between it will send a proportional pulse length.

The default pulse duration range is 1 to 2 milliseconds, but most servos have a wider range.

The default values, as we mentioned earlier, are 1 to 2 milliseconds. That pulse duration is a safe bet, but you may want to play around with your servos. In the majority of the mini servos I have tested, the default values only cover up to 90 degrees, but a wider range allowed them to cover up to 180 degrees.

A less conservative pulse duration range that works in many servos is the following:

servo.setPulseDurationRange(0.65, 2.5)

But be careful when going over the default pulse duration range; each servo is slightly different.

Play with the pulse duration range to find the best configuration for your servo.

With that, you should be able to properly configure pretty much any servo. Let's look at the last typical use of PWM: analog output.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.36.192