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/28 22:09] – [Start] pczekalski | en:iot-open:practical:hardware:sut:esp32:emb10_1 [2024/04/09 12:58] (current) – [Result validation] pczekalski | ||
|---|---|---|---|
| Line 22: | Line 22: | ||
| ==== Task to be implemented ==== | ==== Task to be implemented ==== | ||
| Rotate the servo to the following angles: 0, 90, 180, 135, 45 and back to 0 degrees. | Rotate the servo to the following angles: 0, 90, 180, 135, 45 and back to 0 degrees. | ||
| + | <note warning> | ||
| ==== Start ==== | ==== Start ==== | ||
| - | Check if the servo is in the camera view. Servo is controlled with GPIO 37. | + | Check if the servo is in the camera view. The servo is controlled with GPIO 37. |
| ==== Steps ==== | ==== Steps ==== | ||
| - | // Write some extra information if, i.e. some steps are optional; otherwise, cancel this paragraph | + | **Write your application all in the '' |
| + | <note warning> | ||
| === Step 1 === | === Step 1 === | ||
| - | //Describe activities done in 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 | ||
| + | </code> | ||
| + | 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 | ||
| + | </code> | ||
| - | ... | + | === Step 2 === |
| + | Define a servo controller object: | ||
| + | <code c> | ||
| + | static Servo srv; | ||
| + | </ | ||
| - | === Step n === | + | === Step 3 === |
| - | //Describe activities done in Step n.// | + | Initialise parameters (duty cycle, channel, GPIO): |
| + | <code c> | ||
| + | srv.attach(SRV_PIN, | ||
| + | </code> | ||
| + | 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); | ||
| + | </code> | ||
| - | ==== Result validation ==== | ||
| - | //Provide some result validation methods for self-assessment.// | ||
| ===== FAQ ===== | ===== FAQ ===== | ||
| - | This section is to be extended as new questions appear. \\ | ||
| - | When using the printed version of this manual, please refer to the latest online version of this document to obtain the valid and up-to-date list of the FAQ. | ||
| - | //Provide some FAQs in the following form:\\ | ||
| - | **Question? | ||
| - | // | ||
| + | **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 ===== | ===== Project information ===== | ||
| {{: | {{: | ||
| Line 62: | Line 88: | ||
| {{: | {{: | ||
| </ | </ | ||
| - | + | </ | |
| - | + | ||