This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:practical:hardware:sut:esp32:emb10_1 [2024/02/29 00:09] – [Start] pczekalski | en:iot-open:practical:hardware:sut:esp32:emb10_1 [2024/04/09 15:58] (current) – [Result validation] pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== EMB10: Controlling standard servo ====== | ||
| + | You will learn how to control a standard miniature servo in this scenario. Standard miniature, so-called " | ||
| + | <note warning> | ||
| + | A servo has a red arrow presenting the gauge' | ||
| + | The servo is an actuator. It requires a time to operate. So, you should give it time to operate between consecutive changes of the control PWM signal (requests to change its position). Moreover, because of the observation via camera, too quick rotation may not be observable at all depending on the video stream fps. A gap of 2s between consecutive rotations is usually a reasonable choice. | ||
| + | ===== Prerequisites ===== | ||
| + | To ease servo control, instead of use of '' | ||
| + | <code bash> | ||
| + | ib_deps = dlloydev/ | ||
| + | </ | ||
| + | This library requires minimum setup but, on the other hand, supports, i.e. fine-tuning of the minimum and maximum duty cycle as some servos tend to go beyond 1ms and above 2ms to achieve a full 180-degree rotation range. It is usually provided in the technical documentation accompanying the servo. | ||
| + | |||
| + | ===== Suggested Readings and Knowledge Resources ===== | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | ===== Hands-on Lab Scenario ===== | ||
| + | |||
| + | ==== Task to be implemented ==== | ||
| + | Rotate the servo to the following angles: 0, 90, 180, 135, 45 and back to 0 degrees. | ||
| + | <note warning> | ||
| + | |||
| + | ==== Start ==== | ||
| + | Check if the servo is in the camera view. The servo is controlled with GPIO 37. | ||
| + | |||
| + | ==== Steps ==== | ||
| + | **Write your application all in the '' | ||
| + | <note warning> | ||
| + | === Step 1 === | ||
| + | Include servo control library, specific for ESP32 and declare GPIO, minimum and maximum duty cycle values: | ||
| + | <code c> | ||
| + | #include < | ||
| + | #define SRV_PIN 37 | ||
| + | </ | ||
| + | MG 90 servos that we use in our lab are specific. As mentioned above, to achieve a full 180-degree rotation range, their minimum and maximum duty cycle timings go far beyond standards. Here, we declare minimum and maximum values for the duty cycle (in microseconds) and a PWM control channel (2): | ||
| + | <code c> | ||
| + | #define PWMSRV_Ch | ||
| + | #define srv_min_us | ||
| + | #define srv_max_us 2400 | ||
| + | </ | ||
| + | |||
| + | === Step 2 === | ||
| + | Define a servo controller object: | ||
| + | <code c> | ||
| + | static Servo srv; | ||
| + | </ | ||
| + | |||
| + | === Step 3 === | ||
| + | Initialise parameters (duty cycle, channel, GPIO): | ||
| + | <code c> | ||
| + | srv.attach(SRV_PIN, | ||
| + | </ | ||
| + | 50Hz frequency is standard, so we do not need to configure it. | ||
| + | |||
| + | === Step 4 === | ||
| + | Rotating a servo is as easy as writing the desired angle to the controller class, e.g.: | ||
| + | <code c> | ||
| + | srv.write(SRV_PIN, | ||
| + | delay(2000); | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== FAQ ===== | ||
| + | |||
| + | **How do I know minimum and maximum values for the timings for servo operation? | ||
| + | |||
| + | ==== Result validation ==== | ||
| + | Observe the red arrow to rotate accordingly. Remember to give the servo some time to operate. | ||
| + | |||
| + | <WRAP noprint> | ||
| + | ===== Project information ===== | ||
| + | {{: | ||
| + | This Intellectual Output was implemented under the Erasmus+ KA2.\\ | ||
| + | Project IOT-OPEN.EU Reloaded – Education-based strengthening of the European universities, | ||
| + | Project number: 2022-1-PL01-KA220-HED-000085090. | ||
| + | |||
| + | **__Erasmus+ Disclaimer__**\\ | ||
| + | This project has been funded with support from the European Commission. \\ | ||
| + | This publication reflects the views of only the author, and the Commission cannot be held responsible for any use that may be made of the information contained therein. | ||
| + | |||
| + | **__Copyright Notice__**\\ | ||
| + | This content was created by the IOT-OPEN.EU Reloaded consortium, 2022, | ||
| + | The content is Copyrighted and distributed under CC BY-NC [[https:// | ||
| + | <figure label> | ||
| + | {{: | ||
| + | </ | ||
| + | </ | ||