fscanf question with Arduino

4 ビュー (過去 30 日間)
Darryl
Darryl 2013 年 2 月 24 日
回答済み: Kristian Cvetkov 2017 年 11 月 12 日
I need to know how I can control the amount of Serial.println(variable_1) methods that get read during the fscanf() execution.
This is the code:
arduino = serial('COM4');
fopen(arduino);
x = 1:1:60;
for i=1:length(x)
y(i) = fscanf(arduino, '%d');
end
fclose(arduino);
% Plot data from arduino
plot(x,y)
If my Arduino sketch has multiple Serial.println() it seems to combine the variables within the Serial statements in the same vector. Is it possible for them to be separated?

採用された回答

Walter Roberson
Walter Roberson 2013 年 2 月 24 日
fscanf(arduino, '%d', 1);
  3 件のコメント
Walter Roberson
Walter Roberson 2013 年 2 月 25 日
y(i) = fscanf(arduino, '%d', 1);
z(i) = fscanf(arduino, '%d', 1);
if you want to read both of them. Or, more efficiently,
t = fscanf(arduino '%d%d', 1);
y(i) = t(1);
z(i) = t(2);
Darryl
Darryl 2013 年 2 月 25 日
Thank you very much indeed. Much appreciated, will try that tomorrow.

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

その他の回答 (1 件)

Kristian Cvetkov
Kristian Cvetkov 2017 年 11 月 12 日
How I can write data on my Arduino, after I read them in Matlab?

カテゴリ

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