Connecting Arduino to App Designer with Drop Down and Button

17 views (last 30 days)
I want to connect my Arduino to App Designer by using the "drop down" list. This is what my app looks like:
First, I am looking for if there is any serial com. system. And I am writing them to Drop Down.
p = instrhwinfo('serial');
app.SerialPortsDropDown.Items = p.AvailableSerialPorts;
After this I have planned to read the serial port that is shown in the Drop Down and write it to serialport()
app.a = serialport(app.SerialPortsDropDown.value,9600);
Unfortunately these lines did not work. The error message I got:
Error using serialport (line 116) Unable to connect to the serialport device at port 'COM9'. Verify that a device is connected to the port, the port is not in use, and all serialport input arguments and parameter values are supported by the device.
So, the first two lines of code work. I am able to see COM9 (the com my arduino connected) in the drop-down list. This shows there is a serial port at COM9. But when it comes to reading it with app.a = serialport(app.SerialPortsDropDown.value,9600); it gives error.
How can I connect a serial port via the MATLAB App-designer?
  1 Comment
Abdulkadir Arslan
Abdulkadir Arslan on 30 May 2022
Edited: Abdulkadir Arslan on 30 May 2022
I guess I solved the problem.
I added the following lines before to declare app.a:
clear a;
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
These a few lines clears the serial coms. that are connected to a before.
But the problem continues. Now I cannot use connected serial port.
App Designer does not run this simple code line:
writeDigitalPin(app.a,'D3',1);
It is giving this error:
Error Undefined function 'writeDigitalPin' for input arguments of type 'internal.Serialport'.
Any idea about the problem ?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 31 May 2022
writeDigitalPin only applies arduino objects. You need to arduino() the serial port, not serialport() it.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!