Biblioteca encoderrotary no matlab
Mostrar comentarios más antiguos
Good morning everyone, I have a small project in which I intend to read two encoders using only Matlab that communicates with the Arduino Mega2560, so that I could perform the communication and programming via Matlab-Arduino I had to download some support packages for Matlab were they :
1º
http://www.mathworks.com/matlabcentral/fileexchange/32374-legacy-ma...
2º
http://www.mathworks.com/matlabcentral/fileexchange/40312-simulink-...
3º
http://www.mathworks.com/matlabcentral/fileexchange/47522-matlab-su...
I also downloaded the rotaryencoder library and to use it and communicate with matlab it was as follows:
and to use the rotaryencoder library I need to use the interruptions pins, in the case I already tested for the Arduino Uno and it worked normally, as I want to read two encoder I bought an Arduino Mega2560
according to the site:http://www.arduino.cc/reference/pt/language/functions/external-inte..
Board Possible digital pins for interruptions
Uno, Nano, Mini and others with 328p 2, 3
Uno WiFi Rev.2 all digital pins
Mega, Mega2560, MegaADK 2, 3, 18, 19, 20, 21
clear all; close all; clc
a = arduino('COM11','Mega2560','Libraries','RotaryEncoder')
channelA1 = 'D2' ;
channelB1 = 'D3' ;
channelA2 = 'D18' ;
channelB2 = 'D19' ;
encoder1 = rotaryEncoder(a,canalA1,canalB1,180);% 1st encoder is the ky040
encoder2 = rotaryEncoder(a,channelA2,channelB2,180);% 2nd encoder is the readout sensor attached to the motor shaft
for k=3:100
ky040 = readCount(encoder1);
motor_axis = readCount(encoder2);
endcencoder a %closes the communication with the arduino
well when I use the Arduino uno to read an encoder it works perfectly,
when I use the Arduino Mega2560 to read an Encoder it works and when I put the second Encoder now reading two Encoders it gives an error during the reading it is reading normally and then it stops before finishing the loop for k=3:100.
the rotaryencoder library was made to read only one encoder I even suspected that???, but after researching a bit I saw that it is possible yes in this example he use one Arduino Due http://https://www.mathworks.com/help/supportpkg/arduinoio/ug/steer...
another possible cause is that the processing is too big and demanded a lot from the notebook, I think maybe not, I made a program to work only on the Ide from Arduino and it worked normally too.
to advance, because you are using the matlab to communicate with the arduino you can do everything there in the Arduino IDE? well, yes that is possible but as I intend to apply PID, GPC, I+PD, PI, etc... controllers in the Arduino IDE it would be very heavy I believe and much more work since I already have almost everything ready in Marlab and that I have been saving throughout my course, I just need to adapt to what I intend to work
1 comentario
Respuestas (0)
Categorías
Más información sobre Arduino Hardware en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!