Arduino Uno and rotaryEncoder, client connection is lost at high rpm.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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?
0 comentarios
Respuestas (1)
Harry Vancao
el 17 de Ag. de 2018
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
0 comentarios
Ver también
Categorías
Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!