No appropriate method, property, or field 'pinMode' for class 'arduino'.

3 ビュー (過去 30 日間)
Fredy  Aldo Tsangue Jiatsa
Fredy Aldo Tsangue Jiatsa 2016 年 9 月 26 日
コメント済み: Walter Roberson 2017 年 7 月 20 日
Hello,
I make a project with arduino and matlab. I have connected everything, now I try to write arduino code in matlab. if I print on run, this following announcement always comes out:
No appropriate method, property, or field 'pinMode' for class 'arduino'.
can somebody help please me?
thanks
thus matlab code looks:
a = arduino('COM12', 'uno');
clkPin=2;
dtPin=3;
swPin=4;
a.pinMode(2,'input')
a.pinMode(3,'input');
a.pinMode(4,'input');
a.digitalWrite(4,1);
oldA = 1;
oldB = 1;
result = 0;
encoderVal = 0;
newA = a.digitalRead(clkPin);
newB = a.digitalRead(dtPin);
if (newA ~= oldA) | (newB ~= oldB)
if (oldA == 1 & newA == 0)
result = (oldB * 2 - 1);
end
end
oldA = newA;
oldB = newB;
change = result;
encoderVal = encoderVal + change;
if digitalRead(swPin) == 0
encoderVal = 0;
end
Serial.println(encoderVal);
i use matlab R2016a
  2 件のコメント
homam  mohamad alramadan
homam mohamad alramadan 2017 年 7 月 20 日
編集済み: Walter Roberson 2017 年 7 月 20 日
i have the same problem i am trying to communicate arduino ith matlab gui and the error appears in the last line
delete(instrfind({'Port'},{'COM5'}))
clear a;
global a;
a=arduino('COM5');
a.pinMode(8,'output');
Walter Roberson
Walter Roberson 2017 年 7 月 20 日
homam mohamad alramadan: which MATLAB release are you using?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 9 月 26 日
pinmode is the older "legacy" interface. It has been replaced. See https://www.mathworks.com/help/supportpkg/arduinoio/ref/configurepin.html and readDigitalPin and readVoltage and writeDigitalPin
  9 件のコメント
Walter Roberson
Walter Roberson 2016 年 10 月 25 日
Try
delete(instrfind())
to get rid of any lingering connections.
Fredy  Aldo Tsangue Jiatsa
Fredy Aldo Tsangue Jiatsa 2016 年 10 月 27 日
編集済み: Walter Roberson 2016 年 10 月 27 日
Hello Walter Roberson,
when I run the programme by putting delete (instrfind ()) at this level:
clear all; close all; clc
a = arduino('COM12', 'uno');
delete(instrfind())
configurePin(a,'D2','DigitalInput');
configurePin(a,'D3','DigitalInput');
configurePin(a,'D4','Unset');
writeDigitalPin(a,'D4',1);
encoderVal = 0;
oldA = 1;
oldB = 1;
while 1
result = 0;
newA = readDigitalPin(a,'D2');
newB = readDigitalPin(a,'D3');
if (newA ~= oldA) || (newB ~= oldB)
if (oldA == 1 && newA == 0)
result = (oldB * 2 - 1);
end
end
oldA = newA;
oldB = newB;
change = result;
encoderVal = encoderVal + change
end
I get the text suivant:
Error using to Encode (line 4)
Instrument object OBJ simple percentage year invalid object.
but when I put delete (instrfind ()) at the end of the programme:
clear all; close all; clc
a = arduino('COM12', 'uno');
configurePin(a,'D2','DigitalInput');
configurePin(a,'D3','DigitalInput');
configurePin(a,'D4','Unset');
writeDigitalPin(a,'D4',1);
encoderVal = 0;
oldA = 1;
oldB = 1;
while 1
result = 0;
newA = readDigitalPin(a,'D2');
newB = readDigitalPin(a,'D3');
if (newA ~= oldA) || (newB ~= oldB)
if (oldA == 1 && newA == 0)
result = (oldB * 2 - 1);
end
end
oldA = newA;
oldB = newB;
change = result;
encoderVal = encoderVal + change
end
delete(instrfind())
I still do not get numbers negative. I always get numbers positive, all the same which direction of encoder I turn .
where exactly in the programme I must delete(instrfind()) write?
good day to you and thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB 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