How can I use dsp.timescope in appdesigner to measure data from serial?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Donato stigliano
el 3 de Dic. de 2020
Respondida: Khodour Al Kadry
el 8 de Dic. de 2020
hi everyone, to simplify the problem I wrote a script of a few lines that makes the connection and reads data from a serial through a for loop and inside I inserted the plot through dsp.timescope.
My problem is why can't I see the waveform until the end of the for loop?
if I used a timer would I solve the problem?
The Matlab code I used is the following:
Fs=100;
scope = dsp.TimeScope(1,Fs,'TimeSpanSource','Auto', ...
"TimeSpanOverrunAction",'Scroll', ...
"ReduceUpdates",false, ...
"AxesScaling","Updates", ...
"ShowGrid",true);
arduinoObj = serialport("COM10",115200);
flush(arduinoObj);
arduinoObj.UserData = struct("Data",[],"Count",1)
show(scope)
release(scope);
for ll=1:20
data = readline(arduinoObj);
% Convert the string data to numeric type and save it in the UserData
% property of the serialport object.
arduinoObj.UserData.Data(end+1) = str2double(data);
% Update the Count value of the serialport object.
arduinoObj.UserData.Count = arduinoObj.UserData.Count + 1;
%Plot in timescope
signal = arduinoObj.UserData.Data';
scope(signal);
release(scope);
end
I used the following arduino code:
%%ARDUINO CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Create a variable to send
float number=0;
// Define Analog input Pin
const int analogInPin = A1;
void setup() {
// initialize serial, use the same boudrate in Matlab command
Serial.begin(115200);
}
void loop(){
number = ((analogRead(analogInPin)*5)/1023)*sin(((float) millis()/1000)); // Give your float a value
// Print terminator
Serial.println(number);
delay(200);
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0 comentarios
Respuesta aceptada
Khodour Al Kadry
el 8 de Dic. de 2020
Hi Donato
By Looking at your code, I see that you are calling release in two unnessary spots. After show there is no need to call release. Inside the for loop as well I see that you are calling release which is not a good practice.
If the data coming from the arduino is not fixed size and for that reason you had to call release, I do recommned using dsp.AsyncBuffer ro buffer the data to the desired frame size, and then plot the data using the dsp.TimeScope object.
-Regards
Khodour
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!