replicating Arduino pulseIn() on Matlab

조회 수: 19 (최근 30일)
Mauricio Gallegos
Mauricio Gallegos 2017년 6월 14일
댓글: Walter Roberson 2021년 8월 29일
Long story short I have to replicate the Arduino pulseIn() command in MatLAB reading in an acceleration X and Y component. I was doing research and found that this link:
had a similar request but the "adiosrv.pde" file is outdated and the native command (tic, toc) for Matlab is not consistent enough to give me the accurate readings I need for this project. Apparently the .pde file has changed name and/or been split up into multiple documents and I cannot find it anywhere for the life of me. any input?

답변 (1개)

Nagarjuna Manchineni
Nagarjuna Manchineni 2017년 6월 21일
I see that the solution in the link that you are referring was written for Giampiy's legacy Arduino library, which I think was the case with the pde file. It is not applicable now.
To measure distance using the new Arduino object, there is an Ultrasonic Sensor add-on library on matlabcentral, but you need to first install a 3rd party library as explained in the instructions on that page.
If this Add-on does not work with your Ultrasonic Sensor, you can use it as a template to create your own custom add-on library.
Here's the doc for creating custom add-on libraries for Arduino.
I hope this helps!
  댓글 수: 6
Welid Benchouche
Welid Benchouche 2021년 8월 28일
Both codes won't work, because the code is stuck in this loop and never passes it
while readDigitalPin(a,echo) == 0
%do nothing -- that is, loop until it reads differently
end
it never detects when the echo pin goes high for some reason.
Walter Roberson
Walter Roberson 2021년 8월 29일
It would be interesting to instead use
maxtry = 25;
got_one = false;
for trynum = 1 : maxtry
value = readDigitalPin(a,echo);
if value ~= 0; got_one = true; break; end
disp('pin was 0')
end
if ~got_one
error('No 0 found in %d tries', maxtry);
end

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

카테고리

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