This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:remotelab:sut:generalpurpose2:b7 [2020/05/17 15:30] – pczekalski | en:iot-open:remotelab:sut:generalpurpose2:b7 [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| === Prerequisites === | === Prerequisites === | ||
| - | You need to understand how typical servomotor looks like and how it works.\\ | + | You need to understand how a typical servomotor looks like and how it works.\\ |
| - | The servo is controlled using predefined, precise PWM timing. Most servos share exactly the same model (0-180 degree servos), regardless of their size and power voltage. Classical, analogue servo frequency is 50Hz = 20ms period and duty cycle of the high signal is 1ms for 0deg and 2ms for 180deg. So changing the PWM duty cycle from 1ms to 2ms (5% to 10%) rotates servo. There is no need, however, to implement manually (still you can do) but you will use a predefined library instead of manually setting-up PWM. This brings features like range mapping to control servo logical way (i.e. providing angle, not duty cycle).\\ | + | The servo is controlled using predefined, precise PWM timing. Most servos share exactly the same model (0-180 degree servos), regardless of their size and power voltage. Classical, analogue servo frequency is 50Hz = 20ms period and duty cycle of the high signal is 1ms for 0deg and 2ms for 180deg. So changing the PWM duty cycle from 1ms to 2ms (5% to 10%) rotates servo. There is no need, however, to implement manually (still you can do it) but you will use a predefined library instead of manually setting up PWM. This brings features like range mapping to control servo logical way (i.e. providing angle, not duty cycle).\\ |
| The library is '' | The library is '' | ||
| Line 15: | Line 15: | ||
| === Scenario === | === Scenario === | ||
| - | In this scenario, you will rotate the servo to the 0 degrees, then 45, 90, 135 and 180 degrees counter wise, then 180, 90, 0, clockwise. Note - Arrow pointing left means servo is set to 0, pointing right is 180 degrees, and when 90 degrees, arrow points down. | + | In this scenario, you will rotate the servo to 0 degrees, then 45, 90, 135 and 180 degrees counter wise, then 180, 90, 0, clockwise. Note - Arrow pointing left means servo is set to 0, pointing right is 180 degrees, and when 90 degrees, arrow points down. |
| - | We use LCD to get feedback about requested servo angle and to compare it with the result, but please note, it is just for information only and is not necessary to implement servo rotation. | + | We use LCD to get feedback about the requested servo angle and to compare it with the result, but please note, it is just for information only and is not necessary to implement servo rotation. |
| <note warning> | <note warning> | ||
| Line 39: | Line 39: | ||
| ... | ... | ||
| Servo servo; | Servo servo; | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | If you intend to implement your solution with rotation targets array, here is a hint on array declaration: | ||
| + | <code c> | ||
| + | ... | ||
| + | byte angles[] = {0, | ||
| ... | ... | ||
| </ | </ | ||
| Line 46: | Line 53: | ||
| <code c> | <code c> | ||
| ... | ... | ||
| - | LiquidCrystal_I2C lcd(0x3F, | + | LiquidCrystal_I2C lcd(0x3F, |
| + | //8 and 9 for a 20 chars and 4 line display | ||
| // | // | ||
| ... | ... | ||
| Line 58: | Line 66: | ||
| lcd.backlight(); | lcd.backlight(); | ||
| lcd.home(); | lcd.home(); | ||
| + | lcd.print(" | ||
| + | ... | ||
| + | servo.attach(servoPin); | ||
| + | servo.write(0); | ||
| ... | ... | ||
| </ | </ | ||
| + | Setting servo to the desired angle is as simple as calling '' | ||
| + | \\ | ||
| + | |||
| + | If you implement your solution using rotation targets array, here is a hint on how to implement the '' | ||
| + | <code c> | ||
| + | ... | ||
| + | for(int i=0; i< | ||
| + | { | ||
| + | ... | ||
| + | </ | ||
| + | The '' | ||
| + | |||
| + | |||
| + | <note tip>Give it at least 2s gap between setting subsequent rotation target for the servo. Otherwise, you may be unable to reliably observe results via video stream.</ | ||
| == Step 5 == | == Step 5 == | ||
| - | Keep '' | + | Keep '' |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 69: | Line 95: | ||
| } | } | ||
| </ | </ | ||
| - | '' | ||
| - | |||
| - | To convert float into the string with formatting use '' | ||
| - | <code c> | ||
| - | ... | ||
| - | sprintf(buffer," | ||
| - | ... | ||
| - | delay(5000); | ||
| - | ... | ||
| - | </ | ||
| - | <note tip>'' | ||
| - | '' | ||
| === Result validation === | === Result validation === | ||
| - | Observe | + | Observe the arrow rotating |