Arduino ReadDigitalPin all ones

1 次查看(过去 30 天)
almolch
almolch 2018-5-4
Hi, I'm trying to connect an arduino to matlab to collect data from the digital pins. I am sending data to pin D3, but when I say readDigitalPin(a,'D3') in matlab it just gives me 1. My code is below, any advice would be appreciated.
if true
a = arduino('com8', 'uno');
t1 = 0;
dt=[];
dv=[];
tic
for i =1:500
i;
tic;
v = readDigitalPin(a,'D2');
dT = toc;
t1 = t1 + dT;
dt(i) = [t1];
dv(i) = [v]
pause(0.5)
end
end
  1 个评论
Walter Roberson
Walter Roberson 2018-5-4
Have you put an oscilloscope onto the pin to verify that the value goes lower than the threshold at some point, and does so for longer than the hold time of the sampling hardware?
Is D2 configured as a continual read or is it configured as triggered by edge detection? If triggered then what are the reset conditions?

请先登录,再进行评论。

回答(0 个)

类别

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