Contenuto principale

Standard Servo Write

R2026b

Set shaft position of standard servo motor to angle specified in degrees

  • Arduino Standard Servo Write icon

Libraries:
Simulink Support Package for Arduino Hardware / Common

Description

Add-On Required: This feature requires the Simulink Support Package for Arduino Hardware add-on.

The Standard Servo Write block sets the shaft position of the servo motor from 0 to 180 degrees depending on the input value sent to the block on the Arduino® hardware pin.

You can run a Simulink® model containing Standard Servo Write block in Connected IO mode on Arduino boards.

Note

If you use the Standard Servo Write block along with the Serial Receive and Serial Transmit blocks in a Simulink model, use longer sample times to avoid overruns.

Maximum Number of Servo Blocks Allowed Per Simulink Model

The number of Servo blocks, Standard Servo Read, Standard Servo Write, and Continuous Servo Write, you can use in your Simulink model depends on the number of timers on your Arduino hardware board. Every timer on the Arduino board can support up to 12 Servo blocks.

For example, consider the Arduino Mega 2560/ADK board. The maximum number of servo blocks that can be used per Simulink model is 48. If your Simulink model utilizes a total number of 48 Servo blocks and the board has 5 timers, timer 5 supports the first set of 12 (1 to 12) Servo blocks. Similarly, timer 1 supports the next set of 12 (13-24) Servo blocks, timer 3 supports the next set of 12 (25-36) Servo blocks, and finally, timer 4 supports the last set of 12 (37-48) servo blocks.

The Servo blocks are grouped as follows:

  • Set 1: Servo blocks 1 to 12

  • Set 2: Servo blocks 13 to 24

  • Set 3: Servo blocks 25 to 36

  • Set 4: Servo blocks 37 to 48

  • Set 5: Servo blocks 49 to 60

This table shows how to assign timers to Servo blocks depending on the Arduino board you are using. It also provides the maximum number of Servo blocks that you can use per Simulink model.

Arduino/ Arduino Compatible BoardsTimerMaximum Number of Servo Blocks per Simulink Model
Uno, Nano 3.01Set 1
Mega 2560/ADK1Set 2
3Set 3
4Set 4
5Set 1
Leonardo, Robot Control Board, Robot Motor Board, Micro1Set 1
MKR 1000, MKR WiFi 1010, MKR ZeroTC4Set 1
Nano 33 IoTTC4Set 1
DueTC3_CH0Set 1
TC4_CH1Set 2
TC5_CH2Set 3
TC2_CH2Set 4
TC0_CH0Set 5
  • Uno R4 Wi-Fi®

  • Uno R4 Minima

  • Nano R4

FSP TimerSet 1
  • Teensy 4.0

  • Teensy 4.1

PIT0Set 4
PIT1
PIT2
PIT3
  • ESP32-WROOM

  • ESP32-WROVER

  • ESP32-S3 Series

  • Nano ESP32

0Set 4
1
2
3
  • Raspberry Pi® Pico

  • Raspberry Pi Pico W

0Set 1

Ports

Input

expand all

The input signal is the angle of rotation of the shaft, in degrees. The shaft angle that you specify must be any value between 0 and 180 degrees. Any out-of-range values at the block input port has the same effect as the maximum or minimum input values. For example, 200 is treated as 180 and -10 is treated as 0.

The block input inherits the data type of the upstream block and internally converts the input to uint8.

Data Types: single | double | uint8 | int8 | uint16 | int16 | uint32 | int32

Parameters

expand all

Specify the Arduino hardware board pin number to which the standard rotation servo write motor input signal is connected.

Note

  • Do not assign the same pin number to multiple blocks within a Simulink model.

  • The Standard Servo Write block sets the servo angle on the Arduino pin. The Standard Servo Read block reads this servo angle and does not input the physical servo position from a signal connected to an Arduino pin.

For more information on how to assign pins or view the pins for the Standard Servo Write block, see Pin Mapping for Arduino Timer-Dependent Blocks.

Click this button to view the pin mapping table associated with the Arduino hardware board you select.

Version History

Introduced in R2012a