how could I read digital pin pulses from arduino in matlab?
I mean by writing readDigitalPin(a,'D4')
it shows just 0 or 1
but I want to read pulses from this pin which connected with the phase of increamental encoder

답변 (1개)

Asad Mirza
Asad Mirza 2019년 2월 24일

0 개 추천

Digital pins only return values of 0 or 1. If you want to read voltage information from an incremental encoder it would have to be connected to an analog in pin and then you would have to use readVoltage.

댓글 수: 7

john white
john white 2019년 2월 24일
actually I want to know the position of the encoder and I know that matlab has a code for this by using readCount of rotaryEncoder but I want to connect the pins of the encoder to different digital pins like 4 and 5 instead of 2 and 3 so I neet to know which pulses of the channels of encoder is in high level at the first to know the CW or CCW direction to adding count or decreasing count
Asad Mirza
Asad Mirza 2019년 2월 24일
I believe MATLAB has an example code that reports the position of an encoder. Granted they use pin's D2 and D3 but you can easily change it to be D4 and D5 for ChannelA and B and then have say D2 be for the pushbutton.
john white
john white 2019년 2월 25일
yes I know that Matlab has a code but when I change the pins number it shows an error that the pins in the rotaryEncoder command must be D2 and D3
Asad Mirza
Asad Mirza 2019년 2월 25일
Ah that might be because only D2 and D3 on a classic Arduino Uno have what are called interrupt pins which are needed for rotary encoder information. Arduino Interrupts explains a bit about this. As far as I know you cannot change the interrupt pins in MATLAB but using the Arduino ide you can program the Atmel chip to make any of the other digital pins interrupts like so.
john white
john white 2019년 2월 25일
yes I know that and I could change the other digital pins to Interrupt pins in the Arduino ide
but there is no way in Matlab.
Asad Mirza
Asad Mirza 2019년 2월 25일
Yeah, as far as I know MATLAB can't natively change the interrupt pins.
Welid Benchouche
Welid Benchouche 2022년 9월 15일
but can matlab call an interrupt in matlab code ?not the external interrupt or detect increase in simulink, in matlab code.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Arduino Hardware에 대해 자세히 알아보기

질문:

2019년 2월 24일

댓글:

2022년 9월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by