Warning: Error creating or updating Line

Hi everyone
I´m practicing in matlab R2019 with this excercise:
When I run the code, the LED turns on depending on the LDR values, but if I push the button the graph does not appear, and the Command Window displays the next warnings:
> In defaulterrorcallback (line 12)
In asyncio/Stream/wait (line 183)
In asyncio/OutputStream/drain (line 205)
In matlabshared.transportlib.internal.asyncIOTransportChannel/AsyncIOTransportChannel/write
In matlabshared.seriallib.internal/Serial/write
In matlabshared.transportclients.internal.IOServerClient/IOServerBlockClient/write
In matlabshared.ioclient/IOProtocol/commandResponse
In matlabshared.ioclient/IOProtocol/rawRead
In matlabshared.ioclient.peripherals/AnalogInput/readResultAnalogInSingleInternal
In matlabshared.devicedrivers/AnalogInSingle/readAnalogInResult
In arduino/readVoltageHook (line 929)
In matlabshared.adc/master/readVoltage (line 56)
In p7 (line 68)
Warning: Error creating or updating Line
Error in value of one or more of the following properties: XData YData
Array is wrong shape or size
> In defaulterrorcallback (line 12)
In asyncio/Stream/wait (line 183)
In asyncio/OutputStream/drain (line 205)
In matlabshared.transportlib.internal.asyncIOTransportChannel/AsyncIOTransportChannel/write
In matlabshared.seriallib.internal/Serial/write
In matlabshared.transportclients.internal.IOServerClient/IOServerBlockClient/write
In matlabshared.ioclient/IOProtocol/commandResponse
In matlabshared.ioclient/IOProtocol/rawRead
In matlabshared.ioclient.peripherals/DigitalIO/readDigitalPinInternal
In matlabshared.devicedrivers/DigitalIO/readDigitalIO
In matlabshared.dio/master/readDigitalPinHook (line 151)
In matlabshared.dio/master/readDigitalPin (line 75)
In p7 (line 61)
Warning: Error creating or updating Line
Error in value of one or more of the following properties: XData YData
Array is wrong shape or size
> In defaulterrorcallback (line 12)
In asyncio/Stream/wait (line 183)
In asyncio/OutputStream/drain (line 205)
In matlabshared.transportlib.internal.asyncIOTransportChannel/AsyncIOTransportChannel/write
In matlabshared.seriallib.internal/Serial/write
In matlabshared.transportclients.internal.IOServerClient/IOServerBlockClient/write
In matlabshared.ioclient/IOProtocol/commandResponse
In matlabshared.ioclient/IOProtocol/rawWrite
In matlabshared.ioclient.peripherals/DigitalIO/writeDigitalPinInternal
In matlabshared.devicedrivers/DigitalIO/writeDigitalIO
In matlabshared.dio/master/writeDigitalPinHook (line 160)
In matlabshared.dio/master/writeDigitalPin (line 104)
In p7 (line 77)
Warning: Error creating or updating Line
Error in value of one or more of the following properties: XData YData
Array is wrong shape or size
How can I correct this "error" to make the graph of voltage appears?
Thanks for you help.
%%p7.m
%Excercise 2
%Según la intensidad de luz en el ambiente dependerá la intensidad de
%brillo del LED.
%A mayor intensidad de luz, menor brillo del LED.
%A menor intensidad de luz, mayor brillo del LED.
%Fotoresistencia conectada al PIN 0('D0') del Arduino Uno. LDR connected to PIN 0
%Botón conectado al PIN 3 ('D3') del Arduino Uno. Button connected to PIN 3
%LED conectado al PIN 11 ('D11') del Arduino Uno. LED connected to PIN 11
%%
%%Inicializamos Objetos logicos del Arduino y asignamos Pines
clear all;
close all;
clc;
Port = 'COM9';
minutesToRunDemo = 0.5;
%Eliminamos las conexiones existentes al puerto asignado al ArduinoUno.
delete(instrfind({'Port'},{Port}))
a = arduino('COM9','Uno');
%% Asignamos entradas digitales al ArduinoUno
buttonPin = 'D3'; %Pin3 'D3'
ledPin = 'D11'; %Pin11 'D11'
%% Fotoresistencia
lightSensorPin = 'D0'; %Pin0 'D0'
%%
%%Grafica
h = plot(nan,nan,'r');
hAxes = h.Parent;
hAxes.Title.String = 'Luminosidad del ambiente';
hAxes.YGrid = 'on';
hAxes.YLim = [0,1];
drawnow;
%% Adquisisción de los datos desde ArduinoUno
disp(['La ejecución se realizará durante ', num2str(minutesToRunDemo*60), ' seconds.']);
disp('Presiona el botón para cambiar el estado (On/Off) e inciar la captura de información...');
lightValue = NaN;
obs = 1;
writePWMDutyCycle(a,'D11',0);
% Inicializamos el estado del botón en Off
buttonState = 0; % buttonState == 0, no se capta información.
% buttonState == 1, se captura información.
% Leemos el estado actual del botón
%%previousButtonState = readDigitalPin(a,buttonPin);
previousButtonState = readDigitalPin(a,'D3');
tic
while toc/60 < minutesToRunDemo
%%currentButtonState = readingDigitalPin(a,buttonPin);
currentButtonState = readDigitalPin(a,'D3'); %% LINE 61 WARNING
if currentButtonState == 1 && previousButtonState == 0
buttonState = mod(buttonState+1,2);
end
if buttonState == 1
%%lightValue = readVoltage(a,lightSensorPin);
lightValue = readVoltage(a,'A0'); %% LINE 68 WARNING
%%writePWMDutyCycle(a,ledPin,(5-lightVlue)/5);
writePWMDutyCycle(a,'D11',(5-lightValue)/5);
end
if buttonState == 0
lightValue = nan;
if currentButtonState == 1
%%writeDigitalPin(a,ledPin,1);
writeDigitalPin(a,'D11',1); %% LINE 77 WARNING
else
%%writeDigitalPin(a,ledPin,0);
writeDigitalPin(a,'D11',0);
end
end
% Actualizamos la grafica
h.XData = [h.XData,obs];
end

Answers (0)

Categories

Asked:

on 10 Dec 2019

Edited:

on 10 Dec 2019

Community Treasure Hunt

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

Start Hunting!