Azzera filtri
Azzera filtri

Continously reading input from arduino pin

3 visualizzazioni (ultimi 30 giorni)
Muhammad Haziq
Muhammad Haziq il 9 Gen 2019
Risposto: Bálint Décsi il 28 Apr 2019
Hi,
I am using matlab 2018b. I have a problem, actually I want to read input from pin 02 of arduino and when ever the D2 pin =0 it should print a=0 otherwise it should print a=1. I write this code but it only run for one time and then it gives error.
Undefined function 'readDigitalPin' for input arguments of type 'double'.
Error:
Error in servo_example (line 17)
status = readDigitalPin(a,'D2');
status = readDigitalPin(a,'D2');
Code:
a = arduino('COM5', 'Uno', 'Libraries', 'Servo');
configurePin(a,'D2','DigitalInput');
while (1)
status = readDigitalPin(a,'D2');
if (status ==0)
a=0
pause(3);
else
a=1
end
end

Risposte (1)

Bálint Décsi
Bálint Décsi il 28 Apr 2019
Hi,
I guess your case is solved or not relevant anymore, but anyway I leave an answer here.
The problem with your code is that you gave the same name to your arduino instance that you gave to the variable to print (a). So during the first iteration of the while cycle, your arduino instance a is overwritten, hence won't exist anymore and you won't be able to call its methods. I suggest to change the name of the arduino, e.g.:
ard = arduino('COM5', 'Uno', 'Libraries', 'Servo');
and use this name in later funcions.

Categorie

Scopri di più su MATLAB Support Package for Arduino Hardware in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by