fscanf question with Arduino

4 visualizaciones (últimos 30 días)
Darryl
Darryl el 24 de Feb. de 2013
Respondida: Kristian Cvetkov el 12 de Nov. de 2017
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 24 de Feb. de 2013
fscanf(arduino, '%d', 1);
  3 comentarios
Walter Roberson
Walter Roberson el 25 de Feb. de 2013
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 el 25 de Feb. de 2013
Thank you very much indeed. Much appreciated, will try that tomorrow.

Iniciar sesión para comentar.

Más respuestas (1)

Kristian Cvetkov
Kristian Cvetkov el 12 de Nov. de 2017
How I can write data on my Arduino, after I read them in Matlab?

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by