フィルターのクリア

How can i send my number plate data(e.g. GJ1XX1111) from MATALAB to arduino?

1 回表示 (過去 30 日間)
MEET PATEL
MEET PATEL 2017 年 4 月 13 日
編集済み: Walter Roberson 2017 年 4 月 16 日
I have tried one example on integar and it worked. Now, i want to send string data to Arduino but can't do it. Can anyone help?
my trial program:
clear all;
clc;
arduino= serial('COM7','BaudRate',9600);
sendData =input('Enter the data ether A or B:');
fopen(arduino);
fprintf(arduino,'%s',sendData);
fscanf(arduino)
fclose(arduino)

採用された回答

Nick
Nick 2017 年 4 月 14 日
Hi try this
Arduino code:
#include <String.h>
String str;
void setup() {
Serial.begin(9600);
}
void loop() {
if(Serial.available() >0){
str=Serial.readString();
Serial.print("Received: ");
Serial.println(str);
}
}
Matlab code (change to your COM port; Also the pause may need to be increased if a timeout occurs):
arduino = serial('COM3', 'Baudrate', 9600);
fopen(arduino);
pause(2)
str=('hello world');
fprintf(arduino,'%s\n',str);
recv = fscanf(arduino)
fclose(arduino);
you should receive the output "Received: hello world" in Matlab
  1 件のコメント
MEET PATEL
MEET PATEL 2017 年 4 月 14 日
thank you for the answer, Sir. It really helped a lot.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by