Serial communication, (read, write from/to arduino ) on MATLAB Support Package for Arduino® Hardware

조회 수: 12 (최근 30일)
Hello there,
I'm trying for over a week now to find the proper way to read and write from/to arduino via Matlab. I am using the MATLAB Support Package for Arduino® Hardware, (the new one not legacy). If I am not mistaken in the legacy package the code for reading what was printed in the arduino IDE serial monitor was something like
s = serial (COM3)
fopen (s)
out = fscanf(s)
Is there a way to do the same thing with the new package and how?

채택된 답변

Pasc Peli
Pasc Peli 2016년 8월 21일
Thank you for you quick reply. By "new" and "legacy" packages I mean this
"http://www.mathworks.com/hardware-support/arduino-matlab.html"
and this
"http://www.mathworks.com/matlabcentral/fileexchange/32374-legacy-matlab-and-simulink-support-for-arduino"
respectively.
Now, from what I understand, if i create an arduino object using
a = arduino ('COM3')
I can manipulate the pins, therefore the circuit, and it would be like matlab runs the "main" and arduino is just peripheral (an extention).
On the other hand if I create a serial object using
a = serial ('COM3')
fopen(s)
etc...
I would be able to read whatever the arduino print in its Serial Monitor but I won't be able to manipulate the i/o pins directly (I could to sent a command through the serial and then have the arduino do something when it receives that command). In this case I believe that the arduino is runing its code and matlab just observes.
I tried to implement both arduino and serial objects but I get an error saying that "COM 3 is in use by another object"
So, my questions are. 1) Am I right in my assumptions or have I misunderstood something 2) If I am right is there a way to observe the serial monitor by creating an arduino object
I would prefer to use Matlab code instead of simulink model.
Thank you in advance
  댓글 수: 1
saif khalid
saif khalid 2018년 1월 18일
1.i think your assumptions is ok. 2. i think you can use USB for creating an arduino object and use bluetooth to observe the serial monitor

댓글을 달려면 로그인하십시오.

추가 답변 (4개)

Esther
Esther 2015년 11월 18일
Hi, by new package do you mean Version 15.2.0 of the Arduino MATLAB Support Package, which ships Arduino 1.6.1?
  • I connected an Arduino Mega and tried on R2015b with that version installed.
  • Downloaded a Simulink model that tells the Arduino to send data from Analog Input Pin 0 to the serial port.
  • Then I read from the serial port:
s = serial
fopen(s)
fread(s)
ans =
160
72
75
48
254
Maybe this File Exchange submission will help.
  댓글 수: 1
Pasc Peli
Pasc Peli 2015년 11월 18일
Thank you for you quick reply. By "new" and "legacy" packages I mean this
"http://www.mathworks.com/hardware-support/arduino-matlab.html"
and this
"http://www.mathworks.com/matlabcentral/fileexchange/32374-legacy-matlab-and-simulink-support-for-arduino"
respectively.
Now, from what I understand, if i create an arduino object using
a = arduino ('COM3')
I can manipulate the pins, therefore the circuit, and it would be like matlab runs the "main" and arduino is just peripheral (an extention).
On the other hand if I create a serial object using
a = serial ('COM3')
fopen(s)
etc...
I would be able to read whatever the arduino print in its Serial Monitor but I won't be able to manipulate the i/o pins directly (I could to sent a command through the serial and then have the arduino do something when it receives that command). In this case I believe that the arduino is runing its code and matlab just observes.
I tried to implement both arduino and serial objects but I get an error saying that "COM 3 is in use by another object"
So, my questions are. 1) Am I right in my assumptions or have I misunderstood something 2) If I am right is there a way to observe the serial monitor by creating an arduino object
I would prefer to use Matlab code instead of simulink model.
Thank you in advance

댓글을 달려면 로그인하십시오.


Madhu Govindarajan
Madhu Govindarajan 2015년 11월 18일
As far as I know there is no way to do both at the same time, as methods(a) on the arduino object does not give me anything that is along the lines of serial monitor. However, what is your use case for the serial monitor when you can monitor most of the Arduino pins using the necessary commands.
  댓글 수: 1
Pasc Peli
Pasc Peli 2015년 11월 20일
That's what i thought! I want to get the readings of multiple sensors, some connected in the analog IO pins with an simple voltage output and others more sophisticated like DHT which use their own libraries, and output a stream of bits.

댓글을 달려면 로그인하십시오.


Pasc Peli
Pasc Peli 2015년 11월 20일
I think it's how arduino object works on matlab, but I dont believe that there is a function for read/write via serial.
If you guys can check it, just to be sure I'll be delighted!! thanks

Nouha Rouis
Nouha Rouis 2017년 8월 28일
Hi guys, i want to send value from matlab to arduino, but it doesn't work ? Do you have any idea? thanks

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by