No appropriate method, property, or field 'pinMode' for class 'arduino'.
Show older comments
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 Comments
homam mohamad alramadan
on 20 Jul 2017
Edited: Walter Roberson
on 20 Jul 2017
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
on 20 Jul 2017
homam mohamad alramadan: which MATLAB release are you using?
Answers (1)
Walter Roberson
on 26 Sep 2016
1 vote
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 Comments
Fredy Aldo Tsangue Jiatsa
on 27 Sep 2016
Edited: Walter Roberson
on 27 Sep 2016
Walter Roberson
on 27 Sep 2016
The Serial class is for C++ on the Arduino side. On the MATLAB side, if you want to display to the screen, you can disp() the value. If you want to send to the Arduino as text you would need to fprintf(a, '%d\n', encoderVal) or similar.
Fredy Aldo Tsangue Jiatsa
on 5 Oct 2016
Edited: Walter Roberson
on 5 Oct 2016
Walter Roberson
on 5 Oct 2016
Edited: Walter Roberson
on 5 Oct 2016
persistent oldA oldB
oldA = int32(HIGH);
oldB = int32(HIGH);
Fredy Aldo Tsangue Jiatsa
on 6 Oct 2016
Edited: Walter Roberson
on 6 Oct 2016
Walter Roberson
on 6 Oct 2016
Move
oldA = 1;
oldB = 1;
to before the while loop.
Fredy Aldo Tsangue Jiatsa
on 25 Oct 2016
Walter Roberson
on 25 Oct 2016
Try
delete(instrfind())
to get rid of any lingering connections.
Fredy Aldo Tsangue Jiatsa
on 27 Oct 2016
Edited: Walter Roberson
on 27 Oct 2016
Categories
Find more on Sensors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!