problem in creating serialobject with the command serialport

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

After you create the object the port becomes busy and is no longer available until you release it?
Hi!!! Really thanks for your attention!! I haven't indication about the status of the serial port....I just receive the message that the serial port hasn't been find. Unfortunately I aven't more information!!!
caterina
Also, I've tried to clean the serial port buffer with the command flush(s), but I still haven't serial port available...
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.
Hi!! Really thanks for your kind attention!! I need to connect an I2C RGB display to Arduino and I'm having trouble in the serial communication. I've tried again to create the serial port object with the command
s = serialport("COM3", 9600)
and I receive all the data about the object and it is ok.
Then I create the arduino Object and I'm in this situation:
>> a = arduino('COM3', 'Uno')
Unable to create a communication link with the serial port. Please check the input argument PORT and verify
that a device is connected.
If I create before the arduino object with the above command and then the serial port object I have that:
Error using serialport
Unable to connect to the serialport device at port 'COM3'. 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.
See related documentation for troubleshooting steps.
Really really thanks if you coul help me in understnding better and solving that trouble!!
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...
yes, me too I've presumed the same:one would create a serialport object and then use it to connect/ to communicate with Arduino. I've presumed that this object is the Matlab version of the command serial.begin(9600). The problem is that I need to control my display i2c rgb color with arduino, but I can't. Before I upload the Arduino sketch for the display to establish the connection, then, once that the connection is established, I can control the display, but I want to control the display directly from Matlab, without uploading the Arduino sketch. The display is the DFRobot lcd 1602: maybe when I create the arduino object in Matlab I have to include its library, the one from DFRobot? I really can't understand why I can't connect the display!!! Really thanks for your attention, sincerely!!
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.
yes, controlling the pin with configurePin works!!!
really really thanks for yoiur great help, sincerely!!
Glad to hear, good luck!

Sign in to comment.

Answers (0)

Asked:

on 18 Sep 2023

Commented:

dpb
on 19 Sep 2023

Community Treasure Hunt

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

Start Hunting!