problem in creating serialobject with the command serialport
Show older comments
Hi!!! I'm a PhD student in a PhD programme of Electronics and computer Science with a degree in Chemistry with almost no experience in controlling my Arduino Uno with Matlab, so my question could be quite simple. Now I have to initializate the serial communication with arduino, so that I create the serialObject with the command serialport. Before to create the SerialObject, I check the serial port available with the command
serialportlist("available")
and from the command the serial port COM3 to which is connected my Arduino results available.
successively I create The serial object with the command serialport
S = serialport("COM3", 9600)
but after creating the serial object, if I can check the serial port available with the comamand serialportlist("available") none serial port results available. what could be the problem?
please, if I poorly described something, tell me so I can define better!!
really thanks for all, sincerely
10 Comments
Walter Roberson
on 18 Sep 2023
After you create the object the port becomes busy and is no longer available until you release it?
Caterina
on 18 Sep 2023
Caterina
on 18 Sep 2023
As @Walter Roberson says, once you've attached to a port, it isn't going to be available any longer; the next step isn't to look for available ports (unless you have need for more than one which doesn't seem as would be the case) but to use the serial port object, S, you've attached to/created.
I've never had access to an Arduino so no real familiarity with using one, but the next step would be to look at the simple demo code for interaction with one and see if you can make it do something...
You've done all there is to be done with the serialportlist function.
<Looks like a good jumping in place> from the Arduino and MATLAB section...should be able to make sure you can make it do something from there pretty quickly and learn your way around to then get on to your specific project.
Caterina
on 19 Sep 2023
dpb
on 19 Sep 2023
arduino doc implies you connect to the Arduino directly by specifying the COM port of interest, it doesn't use the serial port object as the connection argument.
As noted, I've never had an Arduino so "know nuthink!" about it, specifically, but the examples and the syntax shown would just use
a = arduino('COM3','Uno')
without having created the serial port object, S, and, since arduino wants access to that particular port, having attached it to the serial port object, its now no longer available for use by Arduino. That makes sense given the way it appears the Arduino interface connection function is designed. I had presumed (and you also, apparently) that one would create a serial port object and then use it to connect to/communicate with the Arduino, but it creates its own specific object instead.
Alternatively, it appears you can leave the Arduino connected and simply call
a=arduino();
and it should auto-discover/connect to the Arduino board automagically.
Anyway, it now looks to me from this doc that you don't use the serialport() stuff at all here...
Caterina
on 19 Sep 2023
dpb
on 19 Sep 2023
Well, if the LCD is connected to the Arduino, then you've got to use it to control the LCD indirectly from MATLAB; you can't communicate/control the LCD directly. Either you will need to write specific C/C++ code that runs on the Arduino to directly manipulate the LCD pins or use an interface library that gives you higher-level access to the LCD display, yes.
Caterina
on 19 Sep 2023
dpb
on 19 Sep 2023
Glad to hear, good luck!
Answers (0)
Categories
Find more on Serial and USB Communication 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!