Arduino Uno and rotaryEncoder, client connection is lost at high rpm.

조회 수: 1 (최근 30일)
Stefano Gambuzza
Stefano Gambuzza 2018년 8월 14일
답변: Harry Vancao 2018년 8월 17일
Hello all,
I am trying to gather data from a rotary encoder with an Arduino Uno connected to MATLAB. The encoder channels are connected to the D2 and D3 pins of the Arduino, and I use the following code to plot a short time hitory of the rpm:
a1 = arduino('COM4', 'uno', 'libraries', 'rotaryencoder');
encoder = rotaryEncoder(a1, 'D2', 'D3', 500);
rpm = nan(1, 50);
h = figure(1);
while true
rpm = [rpm(2:end), readSpeed(encoder)];
plot(rpm);
grid('on');
grid('minor');
xlim([1, length(rpm)]);
ylabel('rpm');
drawnow;
if ~ishandle(h)
break
end
end
clear('a1', 'encoder', 'rpm', 'h');
When I increase the encoder speed to more than 2000 rpm, I get an error in the command window, saying
Error using ard (line 7)
The host and client connection is lost. Make sure the board is plugged in and recreate arduino and related objects.
With 500 counts per revolution, each pin is receiving around 20k counts per second, which should be well in the limitations of the Arduino board. Is there a maximum limit to the rpm that can be read with the rotaryEncoder?

답변 (1개)

Harry Vancao
Harry Vancao 2018년 8월 17일
Hello Stefano,
It seems that there is a limit to the rpm that can be read with "rotaryEncoder". As noted in this document page, the maximum A/B signal rate that the Arduino can handle is about 17–18 kHz. Once this threshold is crossed, the interrupts that are produced by the rotary encoder can interfere with serial communications to MATLAB.
However, note that once the signal rate or rotation speed decreases again, the serial communication should get unblocked.
Harry

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by