How to send data from MATLAB to Arduino an?
古いコメントを表示
Hi, I was wondering how do I send data from MATLAB , say a number ,5 to my Arduino board. The board contains some code in it. For simplicity lets assume it multiplies the incoming number with 4. The output , 20 ,should be displayed in the command window. Is this possible ? I know about a.roundTrip('data') function. But the one in my query is something different. (I work on R2010a)
2 件のコメント
Josh
2012 年 12 月 18 日
I have this same exact question. Any answers?
Akarsh Sinha
2013 年 3 月 29 日
採用された回答
その他の回答 (4 件)
Nthai Papala
2015 年 11 月 19 日
0 投票
I need assistance. I need to send a binary data, say random bits (1 byte for example) from one computer to the other using LED and a phototransistor. The data must be generated in matlab and be sent over a serial port through arduino. I am using matlab 2015a and Arduino Uno and i need codes for both Arduino and Mat Lab.
Thanks in advance
3 件のコメント
Walter Roberson
2015 年 11 月 20 日
Please open a new Question for this.
Busra AYDIN
2021 年 1 月 25 日
hi, did you solve your problem?
Reyhane Jalil
2021 年 9 月 2 日
hi i have same project ...can you send me detail of your work...reyhane.jalil.karim@gmail.com
Rouis Jihene
2017 年 7 月 20 日
編集済み: Walter Roberson
2017 年 7 月 20 日
Hello,
I want to send a value from matlab to arduino,i tried this code but it doesn't work:
in Arduino:
void setup() {
Serial.begin(9600);}
void loop() {
if (Serial.available()) {
Serial.println(Serial.read());}
}
In matlab:
a=serial('com7');
val=20;
fopen(a);
fwrite(a,'%i',val);
fclose(a);
Do you have any solution ? Please help and thanks.
Walter Roberson
2017 年 7 月 20 日
Change
fwrite(a,'%i',val);
to
fprintf(a,'%i',val);
6 件のコメント
Rouis Jihene
2017 年 7 月 20 日
same problem!!! :( In this code, should i precise RX and TX pins?
Walter Roberson
2017 年 7 月 20 日
No, it is not possible to specify the RX or TX pins for serial ports. RX and TX pins are part of the hardware interface level: you either wired them through the right way or you did not wire them through the right way.
The fact that you used COM7 suggests to me that you might be using a USB to serial convertor. If so then likely the correct wires have already been used.
Are you able to talk to the ardiuno if you use the arduino() command? https://www.mathworks.com/help/supportpkg/arduinoio/setup-and-configuration.html
Rouis Jihene
2017 年 7 月 20 日
Yes, i'am able to talk with Arduino using arduino() command, there is no problem in this point.
Rouis Jihene
2017 年 7 月 20 日
Do you know what's the most weird thing, that i'am able to send value from arduino to matlab without having any problem ! Do you believe in this ? Is it logical ?!
Walter Roberson
2017 年 7 月 20 日
Try
fprintf(a,'%d\n',val);
Rouis Jihene
2017 年 7 月 20 日
Same problem! Do you have any other solution?(using Bluetooth or something else)
Syahmi Noordin
2018 年 4 月 29 日
編集済み: Syahmi Noordin
2018 年 4 月 29 日
0 投票
Hi, I want to ask about how to transfer more than one value from matlab GUI to arduino? I put 3 edit text functions in the Gui so I want the user to input value in each edit text function and those three values must be send to arduino for further calculation. Thanks.
1 件のコメント
Walter Roberson
2018 年 4 月 29 日
get() the String property of the handles. fprintf(a, '%s %s %s\n', str1, str2, str3) where a is the arduino connection. This assumes that you want spaces between the strings and newline after the group of three.
You should probably do some sanity checking to be sure the strings are not empty and represent valid numbers.
カテゴリ
ヘルプ センター および File Exchange で MATLAB Support Package for Arduino Hardware についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!