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 sendfloat number=0;// Define Analog input Pinconst 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);}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Best Answer