Main Content

readSpeed

Read current rotational speed

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

Description

example

rpm = readSpeed(encoder) returns the current rotational speed measured by the single quadrature encoder in revolutions per minute.

example

rpm = readSpeed([encoder1,encoder2]) also returns the current rotational speeds measured by the two quadrature encoders in revolutions per minute.

Examples

collapse all

Create an Arduino® object with the 'rotaryEncoder' library.

a = arduino('COM4','Uno','Libraries','rotaryEncoder');

Connect to the encoder that is connected to your Arduino board.

encoder = rotaryEncoder(a,'D2','D3',180);

Read the current rotational speed.

rpm = readSpeed(encoder)
rpm = 0

Create an Arduino object with the 'rotaryEncoder' library.

a = arduino('COM8','Mega2560','Libraries','rotaryEncoder');

Connect to the encoders that are connected to your Arduino board.

encoder1 = rotaryEncoder(a,'D2','D3',180);
encoder2 = rotaryEncoder(a,'D18','D19',180);

Read the current rotational speed.

rpm = readSpeed([encoder1,encoder2])
rpm = 1×2

     0     0

Input Arguments

collapse all

Quadrature encoder connection, specified as a single rotaryEncoder object or a vector of rotaryEncoder objects.

Note

Specify pulse per revolution while creating the rotaryEncoder object to use this function.

Output Arguments

collapse all

Current rotational speed measured by the quadrature encoder in revolutions per minute, returned as a double or vector of doubles.

Note

The speed measurement interval of 20 ms is used to calculate the rotational speed.

Version History

Introduced in R2017a