Servo

Modified on Wed, 04 Jan 2023 at 10:08 PM

This example shows how to use the I/O Control Panels to control a servo on pin 8 with sub-degree resolution.


Indeed, our library lets you control your servos with sub-degree resolution, while the standard library only permits degree resolution. This feature allows for finer positioning (the position resolution of a servo is around 0.1°). It also allows to perform smooth motions at low speed when using our motion control library



Wiring diagram

Connect a servo on pin 8 and add an electrolytic capacitor in parallel with the servo power supply (beware of the polarity!!!). Connect it as close as possible to the servo.

 



Sketch

Upload this program : 1_Basics \ 4_Servo


HITIComm internally creates and manages Servo variables from the standard Servo library. So, you don’t need to create any Servo variable.


We attach a Servo variable to pin 8 by using HC_attachServo(pin, position). We also use this function to move the servo to an initial position of 53.7°. The value must be given in millidegrees (53700 m°).

#include <HITIComm.h>

const int pin_Servo = 8;

void setup()
{
    // initialize library
    HC_begin();

    // attach servo to the pin. Initial position is 53.7°. 
    // (if not specified in parameters, default initial position is 90°)
    HC_attachServo(pin_Servo, 53700);
}

void loop()
{
    // communicate with HITIPanel
    HC_communicate();
}

 

 

Control Panels

1) Display the I/O Control Panels (“IO” button). 

2) The servo is at its initial position (53.7°). As you can see, the displayed value is not exactly the one we asked for. This is due to the positioning resolution of a servo which is around 0.1° but not exactly 0.1°.



3) Change the value to move the servo to a new position. Try for instance 125.4°.






Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article